-
Notifications
You must be signed in to change notification settings - Fork 0
285 lines (254 loc) · 10.5 KB
/
Copy pathbuild-single-parser.yml
File metadata and controls
285 lines (254 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
name: Build Single Tree-sitter Parser
on:
workflow_dispatch:
inputs:
language:
description: "Language to build parser for"
required: true
type: choice
options:
- all
- javascript
- typescript
- tsx
- html
- css
- angular
- java
- kotlin
- groovy
- scala
- python
- go
- rust
- c-sharp
- cpp
- c
- php
- ruby
- elixir
- json
- yaml
- less
- xml
- toml
platforms:
description: "Platforms to build for"
required: true
type: choice
default: "all"
options:
- all
- linux-only
- macos-only
- windows-only
env:
TREE_SITTER_ABI_VERSION: "15"
jobs:
setup:
name: Setup Build Matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.setup-matrix.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup matrix
id: setup-matrix
run: |
# Define platform configurations following Python example pattern
platforms='[
{"os": "ubuntu-latest", "arch": "x64", "platform": "linux", "cross_compile": false},
{"os": "ubuntu-latest", "arch": "arm64", "platform": "linux", "cross_compile": true, "qemu_arch": "arm64"},
{"os": "macos-latest", "arch": "arm64", "platform": "darwin", "cross_compile": false},
{"os": "macos-latest", "arch": "x64", "platform": "darwin", "cross_compile": true},
{"os": "windows-latest", "arch": "x64", "platform": "win32", "cross_compile": false}
]'
if [ "${{ inputs.language }}" == "all" ]; then
# Extract all language names from languages.json
languages=$(jq -r '.languages | keys' languages.json)
else
# Single language
languages='["${{ inputs.language }}"]'
fi
# Create matrix combinations
matrix=$(echo "$languages" | jq -c --argjson platforms "$platforms" '[.[] as $lang | $platforms[] | . + {"language": $lang}]')
echo "matrix=$matrix" >> $GITHUB_OUTPUT
build:
name: Build ${{ matrix.language }} on ${{ matrix.os }} (${{ matrix.arch }})
runs-on: ${{ matrix.os }}
needs: setup
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.setup.outputs.matrix) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU (for cross-compilation)
if: matrix.qemu_arch != '' && matrix.qemu_arch != null
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ matrix.qemu_arch }}
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "18"
- name: Set up tree-sitter CLI
uses: tree-sitter/setup-action/cli@v2
- name: Extract language info
id: lang-info
shell: bash
run: |
repo_url=$(jq -r ".languages[\"${{ matrix.language }}\"].repo" languages.json)
ref=$(jq -r ".languages[\"${{ matrix.language }}\"].ref" languages.json)
grammar_dir=$(jq -r ".languages[\"${{ matrix.language }}\"].grammar_dir // \"\"" languages.json)
echo "repo_url=$repo_url" >> $GITHUB_OUTPUT
echo "ref=$ref" >> $GITHUB_OUTPUT
echo "grammar_dir=$grammar_dir" >> $GITHUB_OUTPUT
- name: Make scripts executable
shell: bash
run: chmod +x scripts/*.sh
- name: Install GNU coreutils (macOS only)
if: matrix.platform == 'darwin'
run: brew install coreutils
- name: Build parser (Linux ARM64)
if: matrix.os == 'ubuntu-latest' && matrix.arch == 'arm64'
run: |
docker run --rm -v $PWD:/workspace -w /workspace \
--platform linux/arm64 \
node:18-alpine \
sh -c "
apk add --no-cache git bash tree-sitter-cli build-base &&
./scripts/build-parser.sh '${{ matrix.language }}' '${{ steps.lang-info.outputs.repo_url }}' '${{ steps.lang-info.outputs.ref }}' 'artifacts' '${{ matrix.arch }}' '${{ matrix.platform }}' '${{ matrix.cross_compile }}' '${{ steps.lang-info.outputs.grammar_dir }}'
"
env:
TREE_SITTER_ABI_VERSION: ${{ env.TREE_SITTER_ABI_VERSION }}
- name: Build parser (Native)
if: matrix.os != 'ubuntu-latest' || matrix.arch != 'arm64'
shell: bash
run: |
./scripts/build-parser.sh "${{ matrix.language }}" "${{ steps.lang-info.outputs.repo_url }}" "${{ steps.lang-info.outputs.ref }}" "artifacts" "${{ matrix.arch }}" "${{ matrix.platform }}" "${{ matrix.cross_compile }}" "${{ steps.lang-info.outputs.grammar_dir }}"
env:
TREE_SITTER_ABI_VERSION: ${{ env.TREE_SITTER_ABI_VERSION }}
# Set cross-compilation flags for macOS x86_64
CFLAGS: ${{ matrix.cross_compile == true && matrix.platform == 'darwin' && '-arch x86_64' || '' }}
CXXFLAGS: ${{ matrix.cross_compile == true && matrix.platform == 'darwin' && '-arch x86_64' || '' }}
LDFLAGS: ${{ matrix.cross_compile == true && matrix.platform == 'darwin' && '-arch x86_64' || '' }}
ARCHFLAGS: ${{ matrix.cross_compile == true && matrix.platform == 'darwin' && '-arch x86_64' || '' }}
- name: Import Code Signing Certificate (macOS only)
if: matrix.platform == 'darwin'
uses: apple-actions/import-codesign-certs@v3
with:
p12-file-base64: ${{ secrets.APPLE_CERTIFICATE_BASE64 }}
p12-password: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
- name: Sign dylib files (macOS only)
if: matrix.platform == 'darwin'
env:
APPLE_IDENTITY: ${{ secrets.APPLE_IDENTITY }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
shell: bash
run: |
find artifacts/ -name "*.dylib" | while read -r dylib_file; do
echo "Signing: $dylib_file"
# Set timeout for codesign (5 minutes)
timeout 300 codesign \
--force \
--timestamp \
--sign "$APPLE_IDENTITY" \
--team-id "$APPLE_TEAM_ID" \
--options runtime \
--verbose \
"$dylib_file"
done
- name: Verify Signing (macOS only)
if: matrix.platform == 'darwin'
shell: bash
run: |
find artifacts/ -name "*.dylib" | while read -r dylib_file; do
echo "Verifying signature for: $dylib_file"
codesign --verify --deep --verbose=4 "$dylib_file"
done
- name: Create ZIP for Notarization (macOS only)
if: matrix.platform == 'darwin'
shell: bash
run: |
# Create zip with all dylib files found recursively in artifacts/
find artifacts/ -name "*.dylib" -exec zip parsers-${{ matrix.language }}-${{ matrix.platform }}-${{ matrix.arch }}.zip {} +
- name: Submit for Notarization (macOS only)
if: matrix.platform == 'darwin'
env:
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
shell: bash
run: |
# Set timeout for notarization (15 minutes)
timeout 900 xcrun notarytool submit parsers-${{ matrix.language }}-${{ matrix.platform }}-${{ matrix.arch }}.zip \
--apple-id "$APPLE_ID" \
--password "$APPLE_APP_SPECIFIC_PASSWORD" \
--team-id "$APPLE_TEAM_ID" \
--wait \
--verbose
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: parser-${{ matrix.language }}-${{ matrix.platform }}-${{ matrix.arch }}
path: artifacts/
retention-days: 7
upload:
name: Upload to S3
needs: build
runs-on: ubuntu-latest
if: always() && needs.build.result == 'success'
permissions:
id-token: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts-download/
pattern: parser-*-*
merge-multiple: true
- name: Configure AWS Credentials for S3 Upload
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: us-east-1
- name: Upload parsers to S3
run: |
# Upload all parser files to S3
find artifacts-download/ -type f \( -name "*.so" -o -name "*.dylib" -o -name "*.dll" -o -name "*.wasm" \) | while read -r file; do
# Extract the relative path from artifacts directory
relative_path=${file#artifacts-download/}
# Construct S3 key
s3_key="tree-sitter/parsers/tree-sitter-$relative_path"
echo "Uploading: $file -> s3://${{ secrets.S3_BUCKET_NAME }}/$s3_key"
# Upload to S3
aws s3 cp "$file" "s3://${{ secrets.S3_BUCKET_NAME }}/$s3_key" \
--metadata "source-file=$relative_path" \
--cache-control "public, max-age=31536000" \
--content-type "application/octet-stream"
done
- name: Summary
run: |
if [ "${{ inputs.language }}" == "all" ]; then
echo "## 🎉 Build Summary for All Languages" >> $GITHUB_STEP_SUMMARY
else
echo "## 🎉 Build Summary for ${{ inputs.language }}" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Built Files" >> $GITHUB_STEP_SUMMARY
find artifacts-download/ -name "*.so" -o -name "*.dylib" -o -name "*.dll" -o -name "*.wasm" | sort | while read file; do
echo "- \`$(basename "$file")\` ($(du -h "$file" | cut -f1))" >> $GITHUB_STEP_SUMMARY
done
echo "" >> $GITHUB_STEP_SUMMARY
echo "### S3 Location" >> $GITHUB_STEP_SUMMARY
if [ "${{ inputs.language }}" == "all" ]; then
echo "Files uploaded to: \`s3://${{ secrets.S3_BUCKET_NAME }}/tree-sitter/parsers/\`" >> $GITHUB_STEP_SUMMARY
else
echo "Files uploaded to: \`s3://${{ secrets.S3_BUCKET_NAME }}/tree-sitter/parsers/tree-sitter-${{ inputs.language }}/\`" >> $GITHUB_STEP_SUMMARY
fi