|
| 1 | +name: Build Tree-Sitter Parsers |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - telkins/build-dylibs |
| 8 | + paths: |
| 9 | + - 'parsers.toml' |
| 10 | + - '.github/workflows/build_parsers.yml' |
| 11 | + workflow_dispatch: |
| 12 | + |
| 13 | +jobs: |
| 14 | + build-parsers: |
| 15 | + runs-on: ${{ matrix.os }} |
| 16 | + strategy: |
| 17 | + matrix: |
| 18 | + include: |
| 19 | + - os: ubuntu-latest |
| 20 | + platform: linux |
| 21 | + - os: macos-latest |
| 22 | + platform: macos |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Checkout repository |
| 26 | + uses: actions/checkout@v3 |
| 27 | + |
| 28 | + - name: Install Rust toolchain |
| 29 | + uses: actions-rs/toolchain@v1 |
| 30 | + with: |
| 31 | + toolchain: stable |
| 32 | + override: true |
| 33 | + |
| 34 | + - name: Install tsdl |
| 35 | + run: | |
| 36 | + cargo install tsdl |
| 37 | +
|
| 38 | + - name: Build tree-sitter parsers |
| 39 | + run: | |
| 40 | + tsdl build --out-dir build_parsers |
| 41 | +
|
| 42 | + - name: Determine platform and architecture |
| 43 | + id: platform_info |
| 44 | + run: | |
| 45 | + # Determine architecture |
| 46 | + arch=$(uname -m) |
| 47 | + # Map architecture names to standard values |
| 48 | + if [[ "$arch" == "x86_64" || "$arch" == "amd64" ]]; then |
| 49 | + arch="x86_64" |
| 50 | + elif [[ "$arch" == "arm64" || "$arch" == "aarch64" ]]; then |
| 51 | + arch="arm64" |
| 52 | + fi |
| 53 | +
|
| 54 | + # For macOS, adjust platform name |
| 55 | + if [[ "${{ matrix.platform }}" == "macos" ]]; then |
| 56 | + platform_name="darwin" |
| 57 | + else |
| 58 | + platform_name="${{ matrix.platform }}" |
| 59 | + fi |
| 60 | +
|
| 61 | + # Set outputs |
| 62 | + echo "arch=$arch" >> $GITHUB_OUTPUT |
| 63 | + echo "platform_name=$platform_name" >> $GITHUB_OUTPUT |
| 64 | +
|
| 65 | + - name: Rename built parsers to include platform and architecture |
| 66 | + run: | |
| 67 | + # Use outputs from previous step |
| 68 | + arch="${{ steps.platform_info.outputs.arch }}" |
| 69 | + platform_name="${{ steps.platform_info.outputs.platform_name }}" |
| 70 | + platform_arch="${platform_name}-${arch}" |
| 71 | +
|
| 72 | + echo "Using platform_arch=${platform_arch}" |
| 73 | +
|
| 74 | + # Rename parser files in the temporary directory |
| 75 | + for file in build_parsers/libtree-sitter-*; do |
| 76 | + if [ -f "$file" ]; then |
| 77 | + filename=$(basename "$file") |
| 78 | + extension="${filename##*.}" |
| 79 | + base="${filename%.*}" |
| 80 | +
|
| 81 | + echo "Processing file $filename" |
| 82 | +
|
| 83 | + # Append platform_arch before the extension |
| 84 | + new_base="${base}-${platform_arch}" |
| 85 | + echo "Renaming $file to build_parsers/${new_base}.${extension}" |
| 86 | + mv "$file" "build_parsers/${new_base}.${extension}" |
| 87 | + fi |
| 88 | + done |
| 89 | +
|
| 90 | + - name: Move renamed parsers to parsers directory |
| 91 | + run: | |
| 92 | + # Ensure parsers directory exists |
| 93 | + mkdir -p parsers |
| 94 | +
|
| 95 | + # Move files and overwrite existing ones |
| 96 | + for file in build_parsers/*; do |
| 97 | + filename=$(basename "$file") |
| 98 | + dest_file="parsers/$filename" |
| 99 | +
|
| 100 | + echo "Moving $file to $dest_file" |
| 101 | + mv -f "$file" "$dest_file" |
| 102 | + done |
| 103 | +
|
| 104 | + - name: Configure git |
| 105 | + run: | |
| 106 | + git config user.name "${{ github.actor }}" |
| 107 | + git config user.email "${{ github.actor }}@users.noreply.github.com" |
| 108 | +
|
| 109 | + - name: Check for changes |
| 110 | + id: changes |
| 111 | + run: | |
| 112 | + git add -A |
| 113 | + if git diff --cached --quiet; then |
| 114 | + echo "changes=false" >> $GITHUB_OUTPUT |
| 115 | + else |
| 116 | + echo "changes=true" >> $GITHUB_OUTPUT |
| 117 | + fi |
| 118 | +
|
| 119 | + - name: Pull latest changes |
| 120 | + if: steps.changes.outputs.changes == 'true' |
| 121 | + run: | |
| 122 | + git pull --rebase --autostash |
| 123 | +
|
| 124 | + - name: Commit changes |
| 125 | + if: steps.changes.outputs.changes == 'true' |
| 126 | + run: | |
| 127 | + git commit -m "Build tree-sitter parsers for ${{ steps.platform_info.outputs.platform_name }}-${{ steps.platform_info.outputs.arch }}" |
| 128 | +
|
| 129 | + - name: Push changes |
| 130 | + if: steps.changes.outputs.changes == 'true' |
| 131 | + run: | |
| 132 | + max_retries=5 |
| 133 | + retry_count=0 |
| 134 | + until git push || [ $retry_count -eq $max_retries ]; do |
| 135 | + echo "Push failed, retrying..." |
| 136 | + git pull --rebase --autostash |
| 137 | + retry_count=$((retry_count + 1)) |
| 138 | + sleep 5 |
| 139 | + done |
| 140 | + if [ $retry_count -eq $max_retries ]; then |
| 141 | + echo "Push failed after $max_retries attempts." |
| 142 | + exit 1 |
| 143 | + fi |
0 commit comments