-
-
Notifications
You must be signed in to change notification settings - Fork 10
431 lines (380 loc) · 16.1 KB
/
ci.yml
File metadata and controls
431 lines (380 loc) · 16.1 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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
name: CI
on:
push:
branches:
- 'main'
tags:
- '*'
pull_request:
env:
OCAML_COMPILER: 5.4.0
permissions:
contents: write
pull-requests: write
jobs:
build:
name: Build and test
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
arch: x64
- os: macos-15-intel
arch: x64
- os: macos-latest
arch: arm64
- os: windows-latest
arch: x64
steps:
- name: "Windows: Set git config"
if: runner.os == 'Windows'
run: |
git config --system core.autocrlf false
git config --system core.eol lf
git config --system core.longpaths true
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 22.x
cache: 'npm'
- name: Load opam cache
id: opam-cache
uses: actions/cache/restore@v5
with:
path: |
${{ runner.tool_cache }}/opam
~/.opam
_opam
.opam-path
C:\cygwin
C:\.opam
key: opam-${{ matrix.os }}-${{ matrix.arch }}-${{ env.OCAML_COMPILER }}-${{ hashFiles('dune-project', 'Makefile') }}
- name: Use OCaml ${{ env.OCAML_COMPILER }}
uses: ocaml/setup-ocaml@v3
if: steps.opam-cache.outputs.cache-hit != 'true'
with:
ocaml-compiler: ${{ env.OCAML_COMPILER }}
dune-cache: true
opam-disable-sandboxing: true
- name: Get OPAM executable path
if: steps.opam-cache.outputs.cache-hit != 'true'
uses: actions/github-script@v7
with:
script: |
const opam_path = await io.which('opam', true);
console.log('opam executable found: %s', opam_path);
const Fs = require('fs/promises');
await Fs.writeFile('.opam-path', opam_path, 'utf-8');
console.log('stored path to .opam-path');
- name: Use cached OPAM environment
if: steps.opam-cache.outputs.cache-hit == 'true'
run: |
# https://github.com/ocaml/setup-ocaml/blob/v3.4.6/packages/setup-ocaml/src/installer.ts
echo "OPAMCOLOR=always" >> "$GITHUB_ENV"
echo "OPAMCONFIRMLEVEL=unsafe-yes" >> "$GITHUB_ENV"
echo "OPAMDOWNLOADJOBS=4" >> "$GITHUB_ENV"
echo "OPAMERRLOGLEN=0" >> "$GITHUB_ENV"
echo "OPAMEXTERNALSOLVER=builtin-0install" >> "$GITHUB_ENV"
echo "OPAMPRECISETRACKING=1" >> "$GITHUB_ENV"
echo "OPAMRETRIES=10" >> "$GITHUB_ENV"
echo "OPAMSOLVERTIMEOUT=600" >> "$GITHUB_ENV"
echo "OPAMYES=1" >> "$GITHUB_ENV"
echo "CLICOLOR_FORCE=1" >> "$GITHUB_ENV"
if [[ "$RUNNER_OS" != "Windows" ]]; then
echo "OPAMROOT=$HOME/.opam" >> "$GITHUB_ENV"
else
echo "OPAMROOT=C:\\.opam" >> "$GITHUB_ENV"
fi
OPAM_PATH="$(cat .opam-path)"
chmod +x "$OPAM_PATH"
dirname "$OPAM_PATH" >> "$GITHUB_PATH"
if [[ "$RUNNER_OS" == "Windows" ]]; then
fsutil behavior query SymlinkEvaluation
fsutil behavior set symlinkEvaluation R2L:1 R2R:1
fsutil behavior query SymlinkEvaluation
echo "HOME=$USERPROFILE" >> "$GITHUB_ENV"
echo "MSYS=winsymlinks:native" >> "$GITHUB_ENV"
echo "CYGWIN=winsymlinks:native" >> "$GITHUB_ENV"
echo "BASH_ENV=C:\\cygwin\\bash_env" >> "$GITHUB_ENV"
# Add Cygwin bin to PATH - required for OCaml binaries to find DLLs
echo "C:\\cygwin\\bin" >> "$GITHUB_PATH"
echo "C:\\cygwin\\wrapperbin" >> "$GITHUB_PATH"
fi
shell: bash
- name: Pin some deps
if: steps.opam-cache.outputs.cache-hit != 'true' && matrix.os != 'windows-latest'
run: make pin
- name: Pin some deps (Windows with retry)
if: steps.opam-cache.outputs.cache-hit != 'true' && matrix.os == 'windows-latest'
shell: pwsh
run: |
$maxRetries = 3
$retryCount = 0
do {
$retryCount++
Write-Host "Attempt $retryCount of $maxRetries"
make pin
if ($LASTEXITCODE -eq 0) { break }
Write-Host "Attempt failed, waiting 10 seconds before retry..."
Start-Sleep -Seconds 10
} while ($retryCount -lt $maxRetries)
if ($LASTEXITCODE -ne 0) { exit 1 }
- name: Install deps
if: steps.opam-cache.outputs.cache-hit != 'true' && matrix.os != 'windows-latest'
run: make install
- name: Install deps (Windows with retry)
if: steps.opam-cache.outputs.cache-hit != 'true' && matrix.os == 'windows-latest'
shell: pwsh
run: |
$maxRetries = 3
$retryCount = 0
do {
$retryCount++
Write-Host "Attempt $retryCount of $maxRetries"
make install
if ($LASTEXITCODE -eq 0) { break }
Write-Host "Attempt failed, waiting 10 seconds before retry..."
Start-Sleep -Seconds 10
} while ($retryCount -lt $maxRetries)
if ($LASTEXITCODE -ne 0) { exit 1 }
- name: Install npm deps
run: make npm-install
- name: Build
run: make build-prod
- name: Run tests
run: make test
- name: Install benchmark tools
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y jq
wget https://github.com/sharkdp/hyperfine/releases/download/v1.18.0/hyperfine_1.18.0_amd64.deb
sudo dpkg -i hyperfine_1.18.0_amd64.deb
- name: Run benchmarks
if: matrix.os == 'ubuntu-latest'
run: BENCH_JQ=1 MIN_RUNS=5 ./benchmarks/bench.sh
- name: Upload artifacts for ${{ matrix.os }}-${{ matrix.arch }}
if: matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}-${{ matrix.arch }}-artifact
path: _build/default/cli/cli.exe
- name: Upload JavaScript artifacts for NPM
if: matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v4
with:
name: query-json-js
path: _build/default/js/js.bc.js
- name: Save opam cache
uses: actions/cache/save@v5
if: steps.opam-cache.outputs.cache-hit != 'true'
with:
path: |
${{ runner.tool_cache }}/opam
~/.opam
_opam
.opam-path
C:\cygwin
C:\.opam
key: opam-${{ matrix.os }}-${{ matrix.arch }}-${{ env.OCAML_COMPILER }}-${{ hashFiles('dune-project', 'Makefile') }}
# ========================================
# Website deploy (ubuntu-latest, main/PR)
# ========================================
- name: Build website
if: matrix.os == 'ubuntu-latest' && (github.ref == 'refs/heads/main' || github.event_name == 'pull_request')
run: make web-build
- name: Deploy to prod
if: matrix.os == 'ubuntu-latest' && github.ref == 'refs/heads/main'
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy ../dist --project-name=query-json
workingDirectory: ./website
- name: Deploy preview
if: matrix.os == 'ubuntu-latest' && github.event_name == 'pull_request'
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy ../dist --project-name=query-json --branch=${{ github.head_ref }}
workingDirectory: ./website
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
# ========================================
# Release (ubuntu-latest, tags only)
# ========================================
- name: Wait for other platform artifacts
if: matrix.os == 'ubuntu-latest' && startsWith(github.ref, 'refs/tags/')
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Waiting for artifacts from other platforms..."
ARTIFACTS="macos-15-intel-x64-artifact macos-latest-arm64-artifact windows-latest-x64-artifact"
for artifact in $ARTIFACTS; do
echo "Waiting for $artifact..."
for i in {1..60}; do
if gh api repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts | jq -e ".artifacts[] | select(.name == \"$artifact\")" > /dev/null 2>&1; then
echo "✓ $artifact is ready"
break
fi
if [ $i -eq 60 ]; then
echo "✗ Timeout waiting for $artifact"
exit 1
fi
echo " Attempt $i/60, waiting 10s..."
sleep 10
done
done
echo "All artifacts ready!"
- name: Download all platform artifacts
if: matrix.os == 'ubuntu-latest' && startsWith(github.ref, 'refs/tags/')
uses: actions/download-artifact@v4
with:
path: _release
- name: Prepare release files
if: matrix.os == 'ubuntu-latest' && startsWith(github.ref, 'refs/tags/')
run: |
# Reorganize downloaded artifacts
mkdir -p _release/platform-linux-x64
mkdir -p _release/platform-darwin-x64
mkdir -p _release/platform-darwin-arm64
mkdir -p _release/platform-windows-x64
mv _release/ubuntu-latest-x64-artifact/cli.exe _release/platform-linux-x64/
mv _release/macos-15-intel-x64-artifact/cli.exe _release/platform-darwin-x64/
mv _release/macos-latest-arm64-artifact/cli.exe _release/platform-darwin-arm64/
mv _release/windows-latest-x64-artifact/cli.exe _release/platform-windows-x64/
chmod +x _release/platform-linux-x64/cli.exe
- name: Get version
if: matrix.os == 'ubuntu-latest' && startsWith(github.ref, 'refs/tags/')
id: version
run: |
VERSION=$(_release/platform-linux-x64/cli.exe --version)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Generate NPM package
if: matrix.os == 'ubuntu-latest' && startsWith(github.ref, 'refs/tags/')
run: node scripts/make-npm-release.js ${{ steps.version.outputs.version }}
- name: Check if version exists on NPM
if: matrix.os == 'ubuntu-latest' && startsWith(github.ref, 'refs/tags/')
id: npm_check
run: |
if npm view @davesnx/query-json@${{ steps.version.outputs.version }} version 2>/dev/null; then
echo "Version ${{ steps.version.outputs.version }} already exists on NPM, skipping publish"
echo "should_publish_to_npm=false" >> "$GITHUB_OUTPUT"
else
echo "Version ${{ steps.version.outputs.version }} is available for publishing"
echo "should_publish_to_npm=true" >> "$GITHUB_OUTPUT"
fi
- name: Create archives for Github release
if: matrix.os == 'ubuntu-latest' && startsWith(github.ref, 'refs/tags/')
run: |
cd _release/platform-darwin-x64
mv cli.exe query-json
zip -r ../../query-json-darwin-x64.zip .
cd ../..
cd _release/platform-darwin-arm64
mv cli.exe query-json
zip -r ../../query-json-darwin-arm64.zip .
cd ../..
cd _release/platform-linux-x64
mv cli.exe query-json
zip -r ../../query-json-linux-x64.zip .
cd ../..
cd _release/platform-windows-x64
mv cli.exe query-json
zip -r ../../query-json-windows-x64.zip .
cd ../..
- name: Publish to NPM
if: matrix.os == 'ubuntu-latest' && startsWith(github.ref, 'refs/tags/') && steps.npm_check.outputs.should_publish_to_npm == 'true'
run: |
npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
npm config set scope "@davesnx"
npm publish --access public
working-directory: ./_release
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
- name: Create Github release
if: matrix.os == 'ubuntu-latest' && startsWith(github.ref, 'refs/tags/')
id: create_release
uses: ncipollo/release-action@v1.16.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag: ${{ steps.version.outputs.version }}
name: ${{ steps.version.outputs.version }}
draft: false
prerelease: false
makeLatest: true
- name: Upload query-json-darwin-x64.zip to Github release
if: matrix.os == 'ubuntu-latest' && startsWith(github.ref, 'refs/tags/')
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./query-json-darwin-x64.zip
asset_name: query-json-darwin-x64.zip
asset_content_type: application/zip
- name: Upload query-json-darwin-arm64.zip to Github release
if: matrix.os == 'ubuntu-latest' && startsWith(github.ref, 'refs/tags/')
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./query-json-darwin-arm64.zip
asset_name: query-json-darwin-arm64.zip
asset_content_type: application/zip
- name: Upload query-json-linux-x64.zip to Github release
if: matrix.os == 'ubuntu-latest' && startsWith(github.ref, 'refs/tags/')
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./query-json-linux-x64.zip
asset_name: query-json-linux-x64.zip
asset_content_type: application/zip
- name: Upload query-json-windows-x64.zip to Github release
if: matrix.os == 'ubuntu-latest' && startsWith(github.ref, 'refs/tags/')
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./query-json-windows-x64.zip
asset_name: query-json-windows-x64.zip
asset_content_type: application/zip
- name: Install dune-release
if: matrix.os == 'ubuntu-latest' && startsWith(github.ref, 'refs/tags/')
run: opam install dune-release -y
- name: Create source distribution archive
if: matrix.os == 'ubuntu-latest' && startsWith(github.ref, 'refs/tags/')
run: |
opam exec -- dune-release distrib -p query-json
echo "Files created:"
ls -la *.tbz || echo "No .tbz files found in root"
ls -la _build/*.tbz || echo "No .tbz files found in _build"
- name: Upload source archive to Github release
if: matrix.os == 'ubuntu-latest' && startsWith(github.ref, 'refs/tags/')
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: _build/query-json-${{ steps.version.outputs.version }}.tbz
asset_name: query-json-${{ steps.version.outputs.version }}.tbz
asset_content_type: application/x-tar
- name: Publish to opam
if: matrix.os == 'ubuntu-latest' && startsWith(github.ref, 'refs/tags/')
uses: davesnx/dune-release-action@v0.2.1
with:
packages: 'query-json'
changelog: './CHANGES.md'
github-token: ${{ secrets.GH_TOKEN }}
to-opam-repository: true
to-github-releases: false