Skip to content

Commit

Permalink
pacakge: for debian and plain old zip and tar (amd64)
Browse files Browse the repository at this point in the history
  • Loading branch information
stackmystack committed May 16, 2024
1 parent 73ad988 commit 5566b3b
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 76 deletions.
99 changes: 24 additions & 75 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
./lang d ${{ matrix.lang }}
./package/deb
- name: Make zip and tar
run: |
./package/zip
- name: Release
uses: softprops/action-gh-release@v1
with:
Expand All @@ -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:
Expand All @@ -110,3 +54,8 @@ jobs:
files: ref
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: list everything local
run: |
apt update -y
apt install tree -y
tree .
5 changes: 4 additions & 1 deletion lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
37 changes: 37 additions & 0 deletions package/deb
Original file line number Diff line number Diff line change
@@ -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 <firas.al-khalil@faveod.com>
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.deb"

29 changes: 29 additions & 0 deletions package/zip
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# /usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

case "$OSTYPE" in
darwin*)
ext="dylib"
;;
*)
ext="so"
;;
esac

pkg="tree-sitter-parsers"
dst=$pkg
dst_sed=$(printf '%s\n' "$dst" | sed -e 's/[\/&]/\\&/g')
pkg_name="$pkg-$PLATFORM"

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"/*

0 comments on commit 5566b3b

Please sign in to comment.