From 36f39ec3a8b0eb0141f61dae3cecd34fdc3201d6 Mon Sep 17 00:00:00 2001 From: Firas al-Khalil Date: Tue, 14 May 2024 14:35:51 +0200 Subject: [PATCH] pacakge: for debian and plain old zip and tar (amd64) Also do a makeup for the CI. It's horrendous. --- .github/workflows/cd.yml | 94 ++++++++-------------------------------- lang | 5 ++- package/deb | 37 ++++++++++++++++ package/zip | 31 +++++++++++++ 4 files changed, 91 insertions(+), 76 deletions(-) create mode 100755 package/deb create mode 100755 package/zip diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 4b96675..c6cebb6 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -3,88 +3,30 @@ name: cd on: [push] jobs: - build-ubuntu: + build: strategy: fail-fast: false matrix: - lang: - - bash - - c - # - cpp # FIXME: `lang` needs to handle things differently maybe because it won't generate for this - - embedded-template - - html - - java - - javascript - - json - - python - - ruby - - rust target: - # - { platform: linux-arm, triplet: arm-linux-gnueabi } - # - { platform: linux-arm64, triplet: aarch64-linux-gnu } - - { platform: linux-x64, triplet: x86_64-linux-gnu } - # NOTE: - # Now that we depend in tree-sitter-cli to regenerate the pulled parser - # all these platform doesn't make any sense. They're simply unsupported - # in the releases of tree-sitter. - # - arm-linux-gnueabihf - # - aarch64-linux-gnu - # - mipsel-linux-gnu - # - powerpc64le-linux-gnu - # - # FIXME: tree-sitter has a known (by me) bug by now: - # ld: unknown option -soname - # It should be patched to support - # - x86_64-apple-darwin - # - x86_64h-apple-darwin - # - i386-apple-darwin - # - # NOTE: Tese are supported by multiarch/crossbuild but not tree-sitter - # - x86_64-w64-mingw32 - # - i686-w64-mingw32 - runs-on: ubuntu-latest + - { os: ubuntu-latest, platform: linux-x64 } + - { os: macos-latest, platform: macos-arm64 } + runs-on: ${{ matrix.target.os }} + env: + PLATFORM: ${{ matrix.target.platform }} steps: - uses: actions/checkout@v2 - - name: Build ${{ matrix.lang }} for ${{ matrix.target.platform }} - env: - PLATFORM: ${{ matrix.target.platform }} + - name: Build for ${{ matrix.target.platform }} run: | - ./lang d ${{ matrix.lang }} - - name: Release - uses: softprops/action-gh-release@v1 - with: - tag_name: ${{ steps.vars.outputs.sha_short }} - name: Release ${{ github.ref }}-${{ steps.vars.outputs.sha_short }} - draft: true - files: | - ./lib/* - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - build-macos: - strategy: - fail-fast: false - matrix: - lang: - - bash - - c - # - cpp - - embedded-template - - html - - java - - javascript - - json - - python - - ruby - - rust - runs-on: macos-latest - steps: - - uses: actions/checkout@v2 - - name: Build ${{ matrix.lang }} for macos - env: - PLATFORM: "macos-arm64" + ./lang d bash c embedded-template html java javascript json python ruby rust + - name: Prepare git # To get tags from `git describe` + run: git fetch --prune --unshallow + - name: Make .deb + if: matrix.target.os == 'ubuntu-latest' + run: | + ./package/deb + - name: Make zip and tar run: | - ./lang d ${{ matrix.lang }} + ./package/zip - name: Release uses: softprops/action-gh-release@v1 with: @@ -97,10 +39,12 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} release-fixed-assets: - needs: [build-ubuntu, build-macos] + needs: [build] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - name: Prepare git # To get tags from `git describe` + run: git fetch --prune --unshallow - name: Release uses: softprops/action-gh-release@v1 with: diff --git a/lang b/lang index 4bd523d..435cff7 100755 --- a/lang +++ b/lang @@ -83,9 +83,12 @@ fi # Clone then Build Languages passed in args # # ################################################ # +top=$(pwd) + for lang in "$@" do + cd "$top" GET=tree-sitter-$lang if [ -z "$PLATFORM" ] then @@ -112,7 +115,7 @@ do echo "> $lang: checking out $checkout" git checkout "$checkout" fi - cd .. + cd - # Regenerate. See https://github.com/tree-sitter/tree-sitter/issues/2731 cd $GET echo "> $lang: regenerating" diff --git a/package/deb b/package/deb new file mode 100755 index 0000000..caa4059 --- /dev/null +++ b/package/deb @@ -0,0 +1,37 @@ +# /usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' +set -vx + +arch=$(dpkg-architecture -q DEB_BUILD_ARCH) +version_num=$(git describe --tags --abbrev=0 | sed -E 's/v([0-9]+\.[0-9]+)/\1/') +commit_count=$(git rev-list --count --first-parent HEAD) + +version="$version_num.$commit_count" +echo + +pkg='tree-sitter-parsers' +rm -rf "$pkg" + +debian="$pkg/DEBIAN" +mkdir -p "$debian" + +dst="$pkg/usr/local/lib" +dst_sed=$(printf '%s\n' "$dst" | sed -e 's/[\/&]/\\&/g') +mkdir -p "$dst" + +cat <<-EOF > "$debian/control" + Package: $pkg + Version: $version + Architecture: $arch + Maintainer: Firas al-Khalil + Description: A bunch of tree-sitter parsers. +EOF + +for i in lib/*-"$PLATFORM".so +do + cp $i $(echo $i | sed -E "s/^(lib\/)(.*)-$PLATFORM(\.so)$/$dst_sed\/\2\3/") +done + +dpkg-deb --build "$pkg" "lib/$pkg-$version_num.deb" + diff --git a/package/zip b/package/zip new file mode 100755 index 0000000..a6bdf1f --- /dev/null +++ b/package/zip @@ -0,0 +1,31 @@ +# /usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' +set -vx + +case "$OSTYPE" in + darwin*) + ext="dylib" + ;; + *) + ext="so" + ;; +esac + +version_num=$(git describe --tags --abbrev=0 | sed -E 's/v([0-9]+\.[0-9]+)/\1/') + +pkg="tree-sitter-parsers" +dst=$pkg +dst_sed=$(printf '%s\n' "$dst" | sed -e 's/[\/&]/\\&/g') +pkg_name="$pkg-$PLATFORM-$version_num" + +rm -rf "$dst" +mkdir "$dst" + +for i in lib/*-"$PLATFORM"."$ext" +do + cp $i $(echo $i | sed -E "s/^(lib\/)(.*)-$PLATFORM(\.$ext)$/$dst_sed\/\2\3/") +done + +zip "lib/$pkg_name.zip" "$dst"/* +tar -cvzf "lib/$pkg_name.tar.gz" "$dst"/*