forked from steipete/CodexBar
-
Notifications
You must be signed in to change notification settings - Fork 0
476 lines (431 loc) · 17.2 KB
/
Copy pathrelease-cli.yml
File metadata and controls
476 lines (431 loc) · 17.2 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
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
name: Release CLI
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: "Release tag/version to package for manual artifact builds; manual runs do not publish."
required: false
type: string
permissions:
contents: write
jobs:
build-cli:
strategy:
fail-fast: false
matrix:
include:
- name: linux-x64
runs-on: ubuntu-24.04
platform: linux
asset-platform: linux
asset-arch: x86_64
build-arch: ""
static-swift-stdlib: true
swift-sdk: ""
swift-sdk-triple: ""
swift-sdk-arch: ""
file-arch-pattern: x86-64
- name: linux-arm64
runs-on: ubuntu-24.04-arm
platform: linux
asset-platform: linux
asset-arch: aarch64
build-arch: ""
static-swift-stdlib: true
swift-sdk: ""
swift-sdk-triple: ""
swift-sdk-arch: ""
file-arch-pattern: aarch64
- name: linux-musl-x64
runs-on: ubuntu-24.04
platform: linux
asset-platform: linux-musl
asset-arch: x86_64
build-arch: ""
static-swift-stdlib: false
swift-sdk: swift-6.2.1-RELEASE_static-linux-0.0.1
swift-sdk-triple: x86_64-swift-linux-musl
swift-sdk-arch: x86_64
file-arch-pattern: x86-64
- name: linux-musl-arm64
runs-on: ubuntu-24.04-arm
platform: linux
asset-platform: linux-musl
asset-arch: aarch64
build-arch: ""
static-swift-stdlib: false
swift-sdk: swift-6.2.1-RELEASE_static-linux-0.0.1
swift-sdk-triple: aarch64-swift-linux-musl
swift-sdk-arch: aarch64
file-arch-pattern: aarch64
- name: macos-arm64
runs-on: macos-15
platform: macos
asset-platform: macos
asset-arch: arm64
build-arch: arm64
static-swift-stdlib: false
swift-sdk: ""
swift-sdk-triple: ""
swift-sdk-arch: ""
file-arch-pattern: ""
- name: macos-x86_64
runs-on: macos-15-intel
platform: macos
asset-platform: macos
asset-arch: x86_64
build-arch: x86_64
static-swift-stdlib: false
swift-sdk: ""
swift-sdk-triple: ""
swift-sdk-arch: ""
file-arch-pattern: ""
runs-on: ${{ matrix.runs-on }}
env:
RELEASE_TAG: ${{ inputs.tag || github.ref_name }}
SWIFT_STATIC_LINUX_SDK_URL: https://download.swift.org/swift-6.2.1-release/static-sdk/swift-6.2.1-RELEASE/swift-6.2.1-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz
SWIFT_STATIC_LINUX_SDK_CHECKSUM: 08e1939a504e499ec871b36826569173103e4562769e12b9b8c2a50f098374ad
SQLITE_AMALGAMATION_VERSION: "3530200"
SQLITE_AMALGAMATION_SHA3_256: 81142986038e18f96c4a54e1a72562ae17e502a916f2a7701eff43388cbf1a40
steps:
- uses: actions/checkout@v6
- name: Select Xcode 26.1.1 (if present) or fallback to default
if: matrix.platform == 'macos'
run: |
set -euo pipefail
for candidate in /Applications/Xcode_26.1.1.app /Applications/Xcode_26.1.app /Applications/Xcode.app; do
if [[ -d "$candidate" ]]; then
sudo xcode-select -s "${candidate}/Contents/Developer"
echo "DEVELOPER_DIR=${candidate}/Contents/Developer" >> "$GITHUB_ENV"
break
fi
done
/usr/bin/xcodebuild -version
- name: Runner info
run: |
set -euo pipefail
uname -a
uname -m
swift --version
- name: Validate release tag
if: github.event_name == 'release' || inputs.tag != ''
shell: bash
run: |
set -euo pipefail
if [[ -z "$RELEASE_TAG" ]]; then
echo "Missing release tag." >&2
exit 1
fi
if [[ ! "$RELEASE_TAG" =~ ^v[0-9A-Za-z._-]+$ ]]; then
echo "Invalid release tag: $RELEASE_TAG" >&2
exit 1
fi
- name: Install Swift 6.2.1 via swiftly
if: matrix.platform == 'linux'
shell: bash
run: |
set -euo pipefail
if ! command -v gpg >/dev/null 2>&1; then
sudo apt-get update
sudo apt-get install -y ca-certificates gpg
fi
SWIFTLY_ARCH="$(uname -m)"
SWIFTLY_HOME_DIR="$HOME/.local/share/swiftly"
SWIFTLY_BIN_DIR="$HOME/.local/bin"
POST_INSTALL_SCRIPT="$(mktemp)"
mkdir -p "$SWIFTLY_BIN_DIR"
curl -fsSL "https://download.swift.org/swiftly/linux/swiftly-${SWIFTLY_ARCH}.tar.gz" -o /tmp/swiftly.tar.gz
tar -xzf /tmp/swiftly.tar.gz -C /tmp
/tmp/swiftly init --assume-yes --skip-install
. "$SWIFTLY_HOME_DIR/env.sh"
echo "$SWIFTLY_BIN_DIR" >> "$GITHUB_PATH"
echo "SWIFTLY_HOME_DIR=$SWIFTLY_HOME_DIR" >> "$GITHUB_ENV"
echo "SWIFTLY_BIN_DIR=$SWIFTLY_BIN_DIR" >> "$GITHUB_ENV"
swiftly install 6.2.1 --use --assume-yes --post-install-file "$POST_INSTALL_SCRIPT"
if [[ -s "$POST_INSTALL_SCRIPT" ]]; then
sudo apt-get update
sudo bash "$POST_INSTALL_SCRIPT"
fi
hash -r
swift --version
- name: Install Swift Static Linux SDK
if: matrix.swift-sdk != ''
shell: bash
run: |
set -euo pipefail
swift sdk install "$SWIFT_STATIC_LINUX_SDK_URL" --checksum "$SWIFT_STATIC_LINUX_SDK_CHECKSUM"
swift sdk list | grep -Fx "${{ matrix.swift-sdk }}"
sdk_root="$(
find "$HOME" -type d -path "*/${{ matrix.swift-sdk }}.artifactbundle/${{ matrix.swift-sdk }}/swift-linux-musl" | head -n1
)"
if [[ -z "$sdk_root" ]]; then
echo "Swift SDK root not found." >&2
exit 1
fi
python3 - "$sdk_root/swift-sdk.json" "${{ matrix.swift-sdk-triple }}" <<'PY'
import json
import sys
sdk_json_path, target_triple = sys.argv[1], sys.argv[2]
with open(sdk_json_path, encoding="utf-8") as handle:
sdk_json = json.load(handle)
target_triples = sdk_json.get("targetTriples", {})
if target_triple not in target_triples:
raise SystemExit(f"Swift SDK target triple not found: {target_triple}")
sdk_json["targetTriples"] = {target_triple: target_triples[target_triple]}
with open(sdk_json_path, "w", encoding="utf-8") as handle:
json.dump(sdk_json, handle, indent=2)
handle.write("\n")
PY
for sdk_arch in "$sdk_root"/musl-1.2.5.sdk/*; do
if [[ "$(basename "$sdk_arch")" != "${{ matrix.swift-sdk-arch }}" ]]; then
rm -rf "$sdk_arch"
fi
done
- name: Build static SQLite for musl SDK
if: matrix.swift-sdk != ''
shell: bash
run: |
set -euo pipefail
missing_packages=()
for tool in clang openssl unzip; do
if ! command -v "$tool" >/dev/null 2>&1; then
missing_packages+=("$tool")
fi
done
if [[ "${#missing_packages[@]}" -gt 0 ]]; then
sudo apt-get update
sudo apt-get install -y "${missing_packages[@]}"
fi
sqlite_zip="$RUNNER_TEMP/sqlite-amalgamation-${SQLITE_AMALGAMATION_VERSION}.zip"
sqlite_src="$RUNNER_TEMP/sqlite-src"
sqlite_out="$RUNNER_TEMP/sqlite-${{ matrix.swift-sdk-triple }}"
curl -fsSL "https://www.sqlite.org/2026/sqlite-amalgamation-${SQLITE_AMALGAMATION_VERSION}.zip" -o "$sqlite_zip"
actual_sha3="$(openssl dgst -sha3-256 "$sqlite_zip" | awk '{print $NF}')"
if [[ "$actual_sha3" != "$SQLITE_AMALGAMATION_SHA3_256" ]]; then
echo "SQLite amalgamation checksum mismatch: $actual_sha3" >&2
exit 1
fi
rm -rf "$sqlite_src" "$sqlite_out"
mkdir -p "$sqlite_src" "$sqlite_out/build" "$sqlite_out/lib"
unzip -q "$sqlite_zip" -d "$sqlite_src"
sdk_bundle="$(
find "$HOME" -type d -name "${{ matrix.swift-sdk }}.artifactbundle" | head -n1
)"
if [[ -z "$sdk_bundle" ]]; then
echo "Swift SDK artifact bundle not found." >&2
exit 1
fi
sysroot="$sdk_bundle/${{ matrix.swift-sdk }}/swift-linux-musl/musl-1.2.5.sdk/${{ matrix.swift-sdk-arch }}"
if [[ ! -d "$sysroot" ]]; then
echo "Swift SDK sysroot not found: $sysroot" >&2
exit 1
fi
clang \
-target "${{ matrix.swift-sdk-triple }}" \
--sysroot="$sysroot" \
-O2 \
-DSQLITE_OMIT_LOAD_EXTENSION=1 \
-c "$sqlite_src/sqlite-amalgamation-${SQLITE_AMALGAMATION_VERSION}/sqlite3.c" \
-o "$sqlite_out/build/sqlite3.o"
llvm-ar crs "$sqlite_out/lib/libsqlite3.a" "$sqlite_out/build/sqlite3.o"
echo "CODEXBAR_SQLITE3_LIB_DIR=$sqlite_out/lib" >> "$GITHUB_ENV"
- name: Build CodexBarCLI (release)
id: build
shell: bash
run: |
set -euo pipefail
BUILD_ARGS=(swift build -c release --product CodexBarCLI)
if [[ -n "${{ matrix.swift-sdk }}" ]]; then
BUILD_ARGS+=(--swift-sdk "${{ matrix.swift-sdk }}" --triple "${{ matrix.swift-sdk-triple }}")
elif [[ -n "${{ matrix.build-arch }}" ]]; then
BUILD_ARGS+=(--arch "${{ matrix.build-arch }}")
fi
if [[ "${{ matrix.static-swift-stdlib }}" == "true" ]]; then
BUILD_ARGS+=(--static-swift-stdlib)
fi
"${BUILD_ARGS[@]}"
SHOW_BIN_ARGS=(swift build -c release --product CodexBarCLI --show-bin-path)
if [[ -n "${{ matrix.swift-sdk }}" ]]; then
SHOW_BIN_ARGS+=(--swift-sdk "${{ matrix.swift-sdk }}" --triple "${{ matrix.swift-sdk-triple }}")
elif [[ -n "${{ matrix.build-arch }}" ]]; then
SHOW_BIN_ARGS+=(--arch "${{ matrix.build-arch }}")
fi
if [[ "${{ matrix.static-swift-stdlib }}" == "true" ]]; then
SHOW_BIN_ARGS+=(--static-swift-stdlib)
fi
echo "bin_dir=$("${SHOW_BIN_ARGS[@]}")" >> "$GITHUB_OUTPUT"
- name: Smoke test CodexBarCLI
timeout-minutes: 5
shell: bash
run: |
set -euo pipefail
BIN_DIR="${{ steps.build.outputs.bin_dir }}"
BIN="$BIN_DIR/CodexBarCLI"
run_with_timeout() {
local output="$1"
shift
"$@" > "$output" &
local pid=$!
local run_status=
for _ in {1..20}; do
if ! kill -0 "$pid" 2>/dev/null; then
set +e
wait "$pid"
run_status=$?
set -e
break
fi
sleep 1
done
if [[ -z "$run_status" ]]; then
kill "$pid" 2>/dev/null || true
wait "$pid" 2>/dev/null || true
echo "$* timed out." >&2
exit 124
fi
if [[ "$run_status" -ne 0 ]]; then
cat "$output" >&2 || true
exit "$run_status"
fi
}
echo "BIN=$BIN"
file "$BIN"
if [[ "${{ matrix.platform }}" == "macos" ]]; then
lipo -archs "$BIN" | tr ' ' '\n' | grep -Fx "${{ matrix.asset-arch }}"
run_with_timeout "$RUNNER_TEMP/codexbar-cli-smoke-${{ matrix.name }}.txt" "$BIN" config validate --format json
elif [[ -n "${{ matrix.swift-sdk }}" ]]; then
run_with_timeout "$RUNNER_TEMP/codexbar-cli-help-${{ matrix.name }}.txt" "$BIN" --help
run_with_timeout "$RUNNER_TEMP/codexbar-cli-config-${{ matrix.name }}.json" "$BIN" config validate --format json
file "$BIN" | grep -q "${{ matrix.file-arch-pattern }}"
file "$BIN" | grep -q "statically linked"
else
run_with_timeout "$RUNNER_TEMP/codexbar-cli-help-${{ matrix.name }}.txt" "$BIN" --help
file "$BIN" | grep -q "${{ matrix.file-arch-pattern }}"
fi
printf '%s\n' "${RELEASE_TAG#v}" > "$BIN_DIR/VERSION"
VERSION_OUTPUT="$RUNNER_TEMP/codexbar-cli-version-${{ matrix.name }}.txt"
run_with_timeout "$VERSION_OUTPUT" "$BIN" --version
grep -Fx "CodexBar ${RELEASE_TAG#v}" "$VERSION_OUTPUT"
rm "$BIN_DIR/VERSION"
- name: Package
id: pkg
shell: bash
run: |
set -euo pipefail
REF_NAME="${RELEASE_TAG}"
if [[ -z "$REF_NAME" ]]; then
echo "Missing release tag." >&2
exit 1
fi
SAFE_REF_NAME="${REF_NAME//\//-}"
BIN_DIR="${{ steps.build.outputs.bin_dir }}"
OUT_DIR="$(mktemp -d)"
install -m 0755 "$BIN_DIR/CodexBarCLI" "$OUT_DIR/CodexBarCLI"
ln -s "CodexBarCLI" "$OUT_DIR/codexbar"
printf '%s\n' "${SAFE_REF_NAME#v}" > "$OUT_DIR/VERSION"
ASSET="CodexBarCLI-${SAFE_REF_NAME}-${{ matrix.asset-platform }}-${{ matrix.asset-arch }}.tar.gz"
(cd "$OUT_DIR" && tar czf "$ASSET" CodexBarCLI codexbar VERSION)
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "$OUT_DIR/$ASSET" > "$OUT_DIR/$ASSET.sha256"
else
shasum -a 256 "$OUT_DIR/$ASSET" > "$OUT_DIR/$ASSET.sha256"
fi
echo "out_dir=$OUT_DIR" >> "$GITHUB_OUTPUT"
echo "asset=$ASSET" >> "$GITHUB_OUTPUT"
- name: Upload release assets
if: github.event_name == 'release'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
set -euo pipefail
TAG="${RELEASE_TAG}"
OUT_DIR="${{ steps.pkg.outputs.out_dir }}"
ASSET="${{ steps.pkg.outputs.asset }}"
gh release upload "$TAG" "$OUT_DIR/$ASSET" "$OUT_DIR/$ASSET.sha256" --clobber
- name: Upload workflow artifact (manual runs)
if: github.event_name == 'workflow_dispatch'
uses: actions/upload-artifact@v6
with:
name: codexbar-cli-${{ matrix.name }}
path: |
${{ steps.pkg.outputs.out_dir }}/${{ steps.pkg.outputs.asset }}
${{ steps.pkg.outputs.out_dir }}/${{ steps.pkg.outputs.asset }}.sha256
update-homebrew-tap:
runs-on: ubuntu-latest
needs: build-cli
if: github.event_name == 'release'
steps:
- name: Resolve release tag
id: release
env:
RELEASE_TAG: ${{ github.ref_name }}
shell: bash
run: |
set -euo pipefail
tag="${RELEASE_TAG}"
if [[ -z "$tag" ]]; then
echo "Missing release tag." >&2
exit 1
fi
if [[ ! "$tag" =~ ^v[0-9A-Za-z._-]+$ ]]; then
echo "Invalid release tag: $tag" >&2
exit 1
fi
echo "tag=$tag" >> "$GITHUB_OUTPUT"
echo "request_id=codexbar-${tag}-${GITHUB_RUN_ID}" >> "$GITHUB_OUTPUT"
- name: Dispatch tap update
env:
GH_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
RELEASE_TAG: ${{ steps.release.outputs.tag }}
REQUEST_ID: ${{ steps.release.outputs.request_id }}
shell: bash
run: |
set -euo pipefail
test -n "$GH_TOKEN"
for attempt in {1..6}; do
if gh workflow run update-formula.yml \
--repo steipete/homebrew-tap \
-f formula=codexbar \
-f tag="$RELEASE_TAG" \
-f repository=steipete/CodexBar \
-f artifact_template='CodexBarCLI-{tag}-{target}.tar.gz' \
-f target_aliases='darwin_arm64=macos-arm64,darwin_amd64=macos-x86_64,linux_arm64=linux-aarch64,linux_amd64=linux-x86_64' \
-f cask=codexbar \
-f cask_artifact='CodexBar-macos-universal-{version}.zip' \
-f request_id="$REQUEST_ID"; then
exit 0
fi
if [[ "$attempt" -eq 6 ]]; then
echo "Failed to dispatch tap update after ${attempt} attempts." >&2
exit 1
fi
sleep $((attempt * 30))
done
- name: Wait for tap update
env:
GH_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
REQUEST_ID: ${{ steps.release.outputs.request_id }}
shell: bash
run: |
set -euo pipefail
for _ in {1..20}; do
run_id="$(
gh run list \
--repo steipete/homebrew-tap \
--workflow update-formula.yml \
--json databaseId,displayTitle \
--jq '.[] | select(.displayTitle | contains(env.REQUEST_ID)) | .databaseId' 2>/tmp/codexbar-tap-run-list.err \
| head -n1 || true
)"
if [[ -n "$run_id" ]]; then
gh run watch "$run_id" --repo steipete/homebrew-tap --exit-status
exit 0
fi
cat /tmp/codexbar-tap-run-list.err >&2 || true
sleep 5
done
echo "Timed out waiting for tap workflow to appear." >&2
exit 1