-
Notifications
You must be signed in to change notification settings - Fork 1
456 lines (372 loc) · 15.8 KB
/
release_github.yml
File metadata and controls
456 lines (372 loc) · 15.8 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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
# Release workflow for celq binaries
# Credit: Inspired by https://github.com/01mf02/jaq/blob/main/.github/workflows/release.yml
# Also see: https://github.com/BurntSushi/ripgrep/blob/61733f6378b62fa2dc2e7f3eff2f2e7182069ca9/.github/workflows/release.yml
name: GitHub Release
on:
workflow_dispatch: # Manual trigger only
push:
tags:
- "v[0-9]*" # Trigger on version tags like v1.0.0
defaults:
run:
shell: bash
env:
NAME: celq
VERSION: ${{ github.ref_name }}
# Required for gh release upload and attestations
permissions:
contents: write
id-token: write
attestations: write
artifact-metadata: write
jobs:
build:
name: ${{ matrix.target }}
runs-on: ${{ matrix.os }}
environment: github_release
strategy:
fail-fast: false
matrix:
include:
# macOS ARM64 (native)
- { target: aarch64-apple-darwin, os: macos-15, pretty_target: macos-aarch64 }
# macOS x86-64 (native)
- { target: x86_64-apple-darwin, os: macos-15-intel, pretty_target: macos-x86_64 }
# Windows x86-64 (native)
- { target: x86_64-pc-windows-msvc, os: windows-2025, pretty_target: windows-x86_64 }
# Linux x86-64 (native - musl static binary)
- { target: x86_64-unknown-linux-musl, os: ubuntu-24.04, pretty_target: linux-x86_64-musl }
# Linux ARM64 (native - musl static binary)
- { target: aarch64-unknown-linux-musl, os: ubuntu-24.04-arm, pretty_target: linux-aarch64-musl }
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install musl tools (for musl targets)
if: contains(matrix.target, 'musl')
run: |
sudo apt-get update
sudo apt-get install -y musl-tools
- name: Build
run: cargo build --locked --release --target ${{ matrix.target }}
- name: Create release archive
id: archive
run: |
EXE_suffix=""
case ${{ matrix.target }} in
*-pc-windows-*) EXE_suffix=".exe" ;;
esac
BIN_PATH="target/${{ matrix.target }}/release/${NAME}${EXE_suffix}"
BIN_NAME="${NAME}${EXE_suffix}"
# Determine archive format based on platform
case ${{ matrix.target }} in
*-pc-windows-*)
# Windows: create .zip archive with pretty name
ARCHIVE_NAME="${NAME}-${{ matrix.pretty_target }}.zip"
7z a "${ARCHIVE_NAME}" "./${BIN_PATH}"
7z rn "${ARCHIVE_NAME}" "target/${{ matrix.target }}/release/${BIN_NAME}" "${BIN_NAME}"
;;
*)
# Linux/macOS: create .tar.gz archive with pretty name
ARCHIVE_NAME="${NAME}-${{ matrix.pretty_target }}.tar.gz"
tar czf "${ARCHIVE_NAME}" -C "target/${{ matrix.target }}/release" "${BIN_NAME}"
;;
esac
echo "ARCHIVE_NAME=${ARCHIVE_NAME}" >> $GITHUB_OUTPUT
- name: Generate attestation for release archive
uses: actions/attest-build-provenance@v3
with:
subject-path: ${{ steps.archive.outputs.ARCHIVE_NAME }}
- name: Upload release archive
env:
GH_TOKEN: ${{ github.token }}
run: gh release upload ${VERSION} ${{ steps.archive.outputs.ARCHIVE_NAME }}
build-zig:
name: ${{ matrix.target }}${{ matrix.zigtargetsuffix }}
runs-on: ${{ matrix.os }}
environment: github_release
strategy:
fail-fast: false
matrix:
include:
# Linux x86-64 (zigbuild - glibc 2.28)
- { target: x86_64-unknown-linux-gnu, os: ubuntu-24.04, zigtargetsuffix: .2.28, pretty_target: linux-x86_64-gnu }
# Linux ARM64 (zigbuild - glibc 2.28)
- { target: aarch64-unknown-linux-gnu, os: ubuntu-24.04-arm, zigtargetsuffix: .2.28, pretty_target: linux-aarch64-gnu }
# FreeBSD x86-64 (zigbuild)
- { target: x86_64-unknown-freebsd, os: ubuntu-24.04, zigtargetsuffix: "", pretty_target: freebsd-x86_64 }
# FreeBSD ARM64 (zigbuild)
- { target: aarch64-unknown-freebsd, os: ubuntu-24.04-arm, zigtargetsuffix: "", pretty_target: freebsd-aarch64 }
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
if: matrix.target != 'aarch64-unknown-freebsd'
with:
targets: ${{ matrix.target }}
- name: Install Rust toolchain (FreeBSD aarch64 special case)
uses: dtolnay/rust-toolchain@1.93
if: matrix.target == 'aarch64-unknown-freebsd'
with:
components: rust-src
- name: Install Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.2
- name: Install cargo-zigbuild
uses: taiki-e/install-action@v2
with:
tool: cargo-zigbuild@0.21.6
- name: Build with Zig
if: matrix.target != 'aarch64-unknown-freebsd'
run: cargo zigbuild --locked --release --target ${{ matrix.target }}${{ matrix.zigtargetsuffix }}
- name: Build with Zig (FreeBSD aarch64 special case)
if: matrix.target == 'aarch64-unknown-freebsd'
run: |
RUSTC_BOOTSTRAP=1 RUSTFLAGS="-Z unstable-options -C panic=immediate-abort" cargo zigbuild \
--target aarch64-unknown-freebsd \
--release \
-Z build-std=std,panic_abort
- name: Create release archive
id: archive
run: |
BIN_PATH="target/${{ matrix.target }}/release/${NAME}"
BIN_NAME="${NAME}"
# Archive name uses pretty target name
ARCHIVE_NAME="${NAME}-${{ matrix.pretty_target }}.tar.gz"
tar czf "${ARCHIVE_NAME}" -C "target/${{ matrix.target }}/release" "${BIN_NAME}"
echo "ARCHIVE_NAME=${ARCHIVE_NAME}" >> $GITHUB_OUTPUT
- name: Generate attestation for release archive
uses: actions/attest-build-provenance@v3
with:
subject-path: ${{ steps.archive.outputs.ARCHIVE_NAME }}
- name: Upload release archive
env:
GH_TOKEN: ${{ github.token }}
run: gh release upload ${VERSION} ${{ steps.archive.outputs.ARCHIVE_NAME }}
update-install-script:
name: Update install script on GitHub Pages
runs-on: ubuntu-latest
needs: [build, build-zig]
environment: github_release
steps:
- name: Checkout celq repository
uses: actions/checkout@v4
with:
path: celq-repo
- name: Checkout get-celq.github.io repository
uses: actions/checkout@v4
with:
repository: get-celq/get-celq.github.io
token: ${{ secrets.PAGES_DEPLOY_TOKEN }}
path: pages-repo
- name: Generate install script with checksums
env:
GH_TOKEN: ${{ github.token }}
run: |
cd celq-repo
VERSION="${{ github.ref_name }}"
# Run the generation script
bash .github/scripts/generate-install-script.sh "$VERSION"
# Generate versioned install script (e.g., v0.1.1/install.sh or v0.2.0-beta.1/install.sh)
mkdir -p "../pages-repo/${VERSION}"
cp install.sh "../pages-repo/${VERSION}/install.sh"
# Only update root install.sh if this is NOT a pre-release
# Pre-releases have a hyphen (e.g., v0.2.0-beta.1, v1.0.0-rc.1)
if [[ ! "$VERSION" =~ -[a-zA-Z] ]]; then
echo "Stable release detected, updating root install.sh"
cp install.sh ../pages-repo/install.sh
else
echo "Pre-release detected, skipping root install.sh update"
fi
- name: Generate attestation for install script
uses: actions/attest-build-provenance@v3
with:
subject-path: celq-repo/install.sh
- name: Upload install.sh to GitHub release
env:
GH_TOKEN: ${{ github.token }}
run: |
cd celq-repo
gh release upload ${{ github.ref_name }} install.sh --clobber
- name: Commit and push changes to Pages repo
run: |
cd pages-repo
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
VERSION="${{ github.ref_name }}"
# Add versioned install script
git add "${VERSION}/install.sh"
# Only add root install.sh if it was updated (stable release)
if [[ ! "$VERSION" =~ -[a-zA-Z] ]]; then
git add install.sh
git commit -m "Update install script to $VERSION (stable release)" || echo "No changes to commit"
else
git commit -m "Add install script for $VERSION (pre-release)" || echo "No changes to commit"
fi
git push
generate-checksums:
name: Generate SHA256 checksums
runs-on: ubuntu-latest
needs: [build, build-zig, update-install-script]
environment: github_release
steps:
- name: Download all release assets
env:
GH_TOKEN: ${{ github.token }}
run: |
VERSION="${{ github.ref_name }}"
# Create temp directory for downloads
mkdir -p /tmp/release-assets
cd /tmp/release-assets
# Download all archives and install.sh for this release
gh release download "${VERSION}" \
--repo ${{ github.repository }} \
--pattern "celq-*.tar.gz" \
--pattern "celq-*.zip" \
--pattern "install.sh"
# List downloaded files
echo "Downloaded files:"
ls -lh
- name: Generate checksums file
run: |
cd /tmp/release-assets
# Generate SHA256 checksums for all downloaded files
# Sort output alphabetically by filename
sha256sum celq-* install.sh | sort -k2 > SHA256SUMS
echo "Generated checksums:"
cat SHA256SUMS
- name: Generate attestation for checksums file
uses: actions/attest-build-provenance@v3
with:
subject-path: /tmp/release-assets/SHA256SUMS
- name: Upload checksums file to release
env:
GH_TOKEN: ${{ github.token }}
run: |
cd /tmp/release-assets
gh release upload ${{ github.ref_name }} SHA256SUMS \
--repo ${{ github.repository }} \
--clobber
update-homebrew-formula:
name: Update Homebrew formula
runs-on: ubuntu-latest
needs: [build, build-zig]
environment: github_release
steps:
- name: Checkout celq repository (for template)
uses: actions/checkout@v4
with:
path: celq-repo
- name: Check if pre-release
id: check_prerelease
run: |
VERSION="${{ github.ref_name }}"
# Check if this is a pre-release (contains hyphen followed by alpha/beta/rc/etc)
if [[ "$VERSION" =~ -[a-zA-Z] ]]; then
echo "Pre-release detected: $VERSION"
echo "Skipping Homebrew formula update (Homebrew doesn't support pre-releases in main formula)"
echo "is_prerelease=true" >> $GITHUB_OUTPUT
else
echo "Stable release detected: $VERSION"
echo "is_prerelease=false" >> $GITHUB_OUTPUT
fi
- name: Checkout homebrew-tap repository
if: steps.check_prerelease.outputs.is_prerelease == 'false'
uses: actions/checkout@v4
with:
repository: get-celq/homebrew-tap
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
path: homebrew-tap
- name: Update Homebrew formula
env:
GH_TOKEN: ${{ github.token }}
if: steps.check_prerelease.outputs.is_prerelease == 'false'
run: |
chmod +x celq-repo/.github/scripts/update-homebrew-formula.sh
celq-repo/.github/scripts/update-homebrew-formula.sh \
"${{ github.ref_name }}" \
"${{ github.repository }}" \
"celq-repo/brew/celq.rb" \
"homebrew-tap/Formula/celq.rb"
- name: Commit and push Homebrew formula
if: steps.check_prerelease.outputs.is_prerelease == 'false'
run: |
cd homebrew-tap
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Formula/celq.rb
git commit -m "Update celq to ${{ github.ref_name }}" || echo "No changes to commit"
git push
echo "✅ Homebrew formula updated to ${{ github.ref_name }}"
update-scoop-manifest:
name: Update Scoop manifest
runs-on: ubuntu-latest
needs: [build, build-zig]
environment: github_release
steps:
- name: Checkout celq repository (for template)
uses: actions/checkout@v4
with:
path: celq-repo
- name: Check if pre-release
id: check_prerelease
run: |
VERSION="${{ github.ref_name }}"
# Check if this is a pre-release (contains hyphen followed by alpha/beta/rc/etc)
if [[ "$VERSION" =~ -[a-zA-Z] ]]; then
echo "Pre-release detected: $VERSION"
echo "Skipping Scoop manifest update (Scoop doesn't support pre-releases)"
echo "is_prerelease=true" >> $GITHUB_OUTPUT
else
echo "Stable release detected: $VERSION"
echo "is_prerelease=false" >> $GITHUB_OUTPUT
fi
- name: Checkout scoop-bucket repository
if: steps.check_prerelease.outputs.is_prerelease == 'false'
uses: actions/checkout@v4
with:
repository: get-celq/scoop-bucket
token: ${{ secrets.SCOOP_BUCKET_TOKEN }}
path: scoop-bucket
- name: Download Windows binary and calculate SHA256
if: steps.check_prerelease.outputs.is_prerelease == 'false'
run: |
VERSION="${{ github.ref_name }}"
# Download the Windows binary zip (using pretty name)
ZIP_URL="https://github.com/${{ github.repository }}/releases/download/${VERSION}/celq-windows-x86_64.zip"
echo "Downloading Windows binary from: $ZIP_URL"
curl -sL "$ZIP_URL" -o "/tmp/celq-windows-x86_64.zip"
# Calculate SHA256
SHA256=$(sha256sum "/tmp/celq-windows-x86_64.zip" | awk '{print $1}')
echo "Calculated SHA256: $SHA256"
# Export for next step
echo "CELQ_SHA256=$SHA256" >> $GITHUB_ENV
- name: Generate Scoop manifest using celq
if: steps.check_prerelease.outputs.is_prerelease == 'false'
run: |
cd celq-repo
VERSION="${{ github.ref_name }}"
VERSION_WITHOUT_V="${VERSION#v}" # Remove 'v' prefix
echo "Generating Scoop manifest for version: $VERSION_WITHOUT_V"
npx -y celq@0.2.0 \
-n \
-p \
-S \
--from-file "scoop/celq.json.cel" \
--arg="celq_version:string=${VERSION_WITHOUT_V}" \
--arg="celq_sha256:string=${CELQ_SHA256}" \
> "../scoop-bucket/bucket/celq.json"
echo "Scoop manifest generated successfully"
- name: Commit and push Scoop manifest
if: steps.check_prerelease.outputs.is_prerelease == 'false'
run: |
cd scoop-bucket
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add bucket/celq.json
git commit -m "Update celq to ${{ github.ref_name }}" || echo "No changes to commit"
git push
echo "✅ Scoop manifest updated to ${{ github.ref_name }}"