-
-
Notifications
You must be signed in to change notification settings - Fork 3
325 lines (295 loc) · 10.9 KB
/
Copy pathrelease-cli.yml
File metadata and controls
325 lines (295 loc) · 10.9 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
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-arch: x86_64
build-arch: ""
static-swift-stdlib: true
- name: linux-arm64
runs-on: ubuntu-24.04-arm
platform: linux
asset-arch: aarch64
build-arch: ""
static-swift-stdlib: true
- name: macos-arm64
runs-on: macos-15
platform: macos
asset-arch: arm64
build-arch: arm64
static-swift-stdlib: false
- name: macos-x86_64
runs-on: macos-15-intel
platform: macos
asset-arch: x86_64
build-arch: x86_64
static-swift-stdlib: false
runs-on: ${{ matrix.runs-on }}
env:
RELEASE_TAG: ${{ inputs.tag || github.ref_name }}
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: Build CodexBarCLI (release)
id: build
shell: bash
run: |
set -euo pipefail
BUILD_ARGS=(swift build -c release --product CodexBarCLI)
if [[ -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.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
else
run_with_timeout "$RUNNER_TEMP/codexbar-cli-help-${{ matrix.name }}.txt" "$BIN" --help
file "$BIN" | grep -q "${{ matrix.asset-arch }}"
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.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