返回 CodeWhale
release-artifacts.yml
根目录 / .github / workflows / release-artifacts.yml
1 name: Release artifacts
2
3 on:
4 workflow_call:
5 inputs:
6 source_sha:
7 description: Exact 40-character source commit to build
8 required: true
9 type: string
10 version:
11 description: Workspace version without a v prefix
12 required: true
13 type: string
14 compiled_host_delivery:
15 description: Explicitly include qualified optional companions; Node stays default
16 required: false
17 default: false
18 type: boolean
19 compiled_host_run_id:
20 description: Green official CI run at this exact SHA containing Native image proof
21 required: false
22 default: ''
23 type: string
24 compiled_host_targets:
25 description: Comma-separated matching-native targets with qualified CI receipts
26 required: false
27 default: linux-x64,macos-arm64,windows-x64
28 type: string
29 retention_days:
30 description: Retention for Actions-only intermediate and assembled artifacts
31 required: false
32 default: 7
33 type: number
34 macos_runner:
35 description: macOS build runner (default follows the CW_SELF_HOSTED_MAC repository variable; self-hosted is the codewhale-mac runner; hosted forces macos-latest)
36 required: false
37 default: default
38 type: string
39 require_signature:
40 description: Fail when the release key is absent. The tag release sets this; candidates may run unsigned.
41 required: false
42 default: false
43 type: boolean
44 secrets:
45 CODEWHALE_RELEASE_SIGNING_KEY:
46 description: Ed25519 release key (PEM). Absent means the release ships unsigned unless require_signature is set.
47 required: false
48
49 permissions:
50 contents: read
51 actions: read
52
53 env:
54 CARGO_TERM_COLOR: always
55 CARGO_INCREMENTAL: 0
56 RUSTFLAGS: -Dwarnings
57 # Build identity is the trusted workflow SHA. Callers pass source_sha only
58 # so `pin` can refuse a mismatch; it must not retarget checkout or caches.
59 CODEWHALE_BUILD_SHA: ${{ github.sha }}
60
61 jobs:
62 pin:
63 name: Pin caller SHA to this run
64 timeout-minutes: 10
65 runs-on: ubuntu-24.04
66 outputs:
67 macos_self_hosted: ${{ steps.macos.outputs.self_hosted }}
68 steps:
69 - name: Choose the macOS build runner
70 id: macos
71 env:
72 EVENT_NAME: ${{ github.event_name }}
73 EVENT_REF: ${{ github.ref }}
74 THIS_REPO: ${{ github.repository }}
75 REQUESTED: ${{ inputs.macos_runner }}
76 SWITCH: ${{ vars.CW_SELF_HOSTED_MAC }}
77 run: |
78 set -euo pipefail
79 # Only a v* tag push or a dispatch in this repository (write access required) may build shipping binaries on the self-hosted Mac.
80 self_hosted=false
81 if [ "${THIS_REPO}" = codewhale-hq/Codewhale ] && { [ "${EVENT_NAME}" = workflow_dispatch ] || { [ "${EVENT_NAME}" = push ] && [[ "${EVENT_REF}" == refs/tags/v* ]]; }; }; then
82 case "${REQUESTED:-default}" in
83 self-hosted) self_hosted=true ;;
84 hosted) ;;
85 *) if [ "${SWITCH}" = true ]; then self_hosted=true; fi ;;
86 esac
87 fi
88 echo "self_hosted=${self_hosted}" >> "${GITHUB_OUTPUT}"
89 - name: Require source_sha equals github.sha
90 env:
91 SOURCE_SHA: ${{ inputs.source_sha }}
92 run: |
93 set -euo pipefail
94 if [[ "${#SOURCE_SHA}" -ne 40 || "${SOURCE_SHA}" =~ [^0-9a-fA-F] ]]; then
95 echo "::error::source_sha must be a full 40-character commit SHA." >&2
96 exit 1
97 fi
98 expected="$(printf '%s' "${SOURCE_SHA}" | tr '[:upper:]' '[:lower:]')"
99 actual="$(printf '%s' "${GITHUB_SHA}" | tr '[:upper:]' '[:lower:]')"
100 if [[ "${actual}" != "${expected}" ]]; then
101 echo "::error::Reusable workflow SHA ${actual} does not match source_sha ${SOURCE_SHA}." >&2
102 exit 1
103 fi
104 - name: Require explicit matching-native qualification selection
105 if: inputs.compiled_host_delivery
106 env:
107 QUALIFICATION_RUN: ${{ inputs.compiled_host_run_id }}
108 HOST_TARGETS: ${{ inputs.compiled_host_targets }}
109 run: |
110 set -euo pipefail
111 [[ "${QUALIFICATION_RUN}" =~ ^[0-9]+$ ]] || { echo 'Enabled host delivery needs an exact green CI run id' >&2; exit 1; }
112 [[ -n "${HOST_TARGETS}" ]] || { echo 'No compiled host targets selected' >&2; exit 1; }
113 declare -A seen
114 IFS=',' read -ra selected <<< "${HOST_TARGETS}"
115 for target in "${selected[@]}"; do
116 case "${target}" in linux-x64|linux-arm64|macos-x64|macos-arm64|windows-x64|windows-arm64) ;; *) echo "Unsupported compiled host target ${target}" >&2; exit 1 ;; esac
117 [[ -z "${seen[${target}]:-}" ]] || { echo "Duplicate compiled host target ${target}" >&2; exit 1; }
118 seen["${target}"]=1
119 done
120
121 build:
122 name: Build ${{ matrix.platform }}
123 timeout-minutes: ${{ startsWith(matrix.os, 'macos-') && 360 || 210 }}
124 # FreeBSD is a source-build target with no prebuilt asset, no npm binary and no CI check
125 # (see packaging/freebsd/README.md and docs/INSTALL.md#freebsd).
126 strategy:
127 fail-fast: false
128 matrix:
129 include:
130 - os: ubuntu-latest
131 target: x86_64-unknown-linux-musl
132 platform: linux-x64
133 cli_binary: codewhale
134 shim_binary: codew
135 cli_artifact: codewhale-linux-x64
136 shim_artifact: codew-linux-x64
137 compat_tui_artifact: codewhale-tui-linux-x64
138 - os: ubuntu-24.04-arm
139 target: aarch64-unknown-linux-musl
140 platform: linux-arm64
141 cli_binary: codewhale
142 shim_binary: codew
143 cli_artifact: codewhale-linux-arm64
144 shim_artifact: codew-linux-arm64
145 compat_tui_artifact: codewhale-tui-linux-arm64
146 - os: ubuntu-latest
147 target: aarch64-linux-android
148 platform: android-arm64
149 cli_binary: codewhale
150 shim_binary: codew
151 cli_artifact: codewhale-android-arm64
152 shim_artifact: codew-android-arm64
153 compat_tui_artifact: codewhale-tui-android-arm64
154 - os: macos-latest
155 target: x86_64-apple-darwin
156 platform: macos-x64
157 cli_binary: codewhale
158 shim_binary: codew
159 cli_artifact: codewhale-macos-x64
160 shim_artifact: codew-macos-x64
161 compat_tui_artifact: codewhale-tui-macos-x64
162 - os: macos-latest
163 target: aarch64-apple-darwin
164 platform: macos-arm64
165 cli_binary: codewhale
166 shim_binary: codew
167 cli_artifact: codewhale-macos-arm64
168 shim_artifact: codew-macos-arm64
169 compat_tui_artifact: codewhale-tui-macos-arm64
170 - os: windows-latest
171 target: x86_64-pc-windows-msvc
172 platform: windows-x64
173 cli_binary: codewhale.exe
174 shim_binary: codew.exe
175 cli_artifact: codewhale-windows-x64.exe
176 shim_artifact: codew-windows-x64.exe
177 compat_tui_artifact: codewhale-tui-windows-x64.exe
178 - os: windows-11-arm
179 target: aarch64-pc-windows-msvc
180 platform: windows-arm64
181 cli_binary: codewhale.exe
182 shim_binary: codew.exe
183 cli_artifact: codewhale-windows-arm64.exe
184 shim_artifact: codew-windows-arm64.exe
185 compat_tui_artifact: codewhale-tui-windows-arm64.exe
186 # Native HarmonyOS and OpenHarmony. The artifact is useless unsigned:
187 # the device refuses to execute an unsigned ELF (see
188 # docs/HarmonyOS.md), so this leg self-signs the binary before staging.
189 - os: ubuntu-latest
190 target: aarch64-unknown-linux-ohos
191 platform: ohos-arm64
192 cli_binary: codewhale
193 shim_binary: codew
194 cli_artifact: codewhale-ohos-arm64
195 shim_artifact: codew-ohos-arm64
196 compat_tui_artifact: codewhale-tui-ohos-arm64
197 runs-on: ${{ startsWith(matrix.os, 'macos-') && needs.pin.outputs.macos_self_hosted == 'true' && fromJSON('["self-hosted","macOS","ARM64","codewhale-mac"]') || (matrix.os == 'ubuntu-latest' && 'ubuntu-24.04' || matrix.os) }}
198 needs: pin
199 steps:
200 - name: Fresh rustup, Cargo home and temp for a self-hosted release build
201 if: runner.environment == 'self-hosted'
202 shell: bash
203 run: |
204 set -euo pipefail
205 fresh="${RUNNER_TEMP}/release-home"
206 rm -rf "${fresh}"
207 mkdir -p "${fresh}/tmp"
208 export HOME="${fresh}" CARGO_HOME="${fresh}/.cargo" RUSTUP_HOME="${fresh}/.rustup"
209 curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused -sSf https://sh.rustup.rs \
210 | sh -s -- -y --no-modify-path --profile minimal --default-toolchain none
211 read -ra flags <<< "${RUSTFLAGS}"
212 for prefix in "${CARGO_HOME}=/cargo" "$(cd "${fresh}" && pwd -P)/.cargo=/cargo" \
213 "${GITHUB_WORKSPACE}=/codewhale" "$(cd "${GITHUB_WORKSPACE}" && pwd -P)=/codewhale"; do
214 flags+=("--remap-path-prefix=${prefix}")
215 done
216 {
217 echo "HOME=${HOME}"
218 echo "CARGO_HOME=${CARGO_HOME}"
219 echo "RUSTUP_HOME=${RUSTUP_HOME}"
220 echo "TMPDIR=${fresh}/tmp"
221 echo "CARGO_BUILD_JOBS=6"
222 echo "CW_RELEASE_HOME=${fresh}"
223 printf 'CARGO_ENCODED_RUSTFLAGS=%s\n' "$(IFS=$'\037'; echo "${flags[*]}")"
224 } >> "${GITHUB_ENV}"
225 echo "${CARGO_HOME}/bin" >> "${GITHUB_PATH}"
226 # No ref: — GITHUB_SHA only. CodeQL treats workflow_call checkout-with-ref
227 # and any ref named *sha* as an untrusted checkout (cache-poisoning).
228 - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
229 - name: Start the self-hosted release build from an empty target
230 if: runner.environment == 'self-hosted'
231 shell: bash
232 run: |
233 set -euo pipefail
234 rm -rf target
235 test -z "$(git status --porcelain --ignored)"
236 - uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # master 2026-07-18
237 with:
238 toolchain: 1.100.0
239 targets: ${{ matrix.target }}
240 - uses: mozilla-actions/sccache-action@fc920bf0ec8de6ee65d409111f7ec508035751ba # v0.0.11
241 with:
242 version: "v0.19.0"
243 if: runner.os == 'Linux'
244 id: sccache
245 continue-on-error: true
246 - name: Enable sccache
247 if: steps.sccache.outcome == 'success' && runner.os == 'Linux'
248 shell: bash
249 run: |
250 {
251 echo "SCCACHE_GHA_ENABLED=true"
252 echo "RUSTC_WRAPPER=sccache"
253 echo "SCCACHE_IGNORE_SERVER_IO_ERROR=1"
254 echo "SCCACHE_IDLE_TIMEOUT=0"
255 } >> "${GITHUB_ENV}"
256 # Restore after the trusted lockfile is on disk. Key is OS + arch +
257 # explicit stable toolchain + rust-cache's Cargo.lock / rust-toolchain
258 # hash. Never interpolate github.event, github.ref, github.sha, or inputs.
259 - uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2
260 if: runner.environment != 'self-hosted'
261 with:
262 cache-bin: false
263 prefix-key: v1-${{ runner.os }}-${{ runner.arch }}-stable
264 - name: Add swap so the aarch64 dist build is not killed for memory
265 if: runner.os == 'Linux' && contains(matrix.target, 'aarch64')
266 shell: bash
267 run: |
268 set -euo pipefail
269 dir=/mnt
270 if ! sudo test -w /mnt; then dir=/; fi
271 avail=$(df -Pk "$dir" | awk 'NR==2 {print int($4 / 1048576)}')
272 if [ "$avail" -ge 30 ]; then size=16; elif [ "$avail" -ge 14 ]; then size=8; else size=0; fi
273 if [ "$size" -gt 0 ]; then
274 sudo fallocate -l "${size}G" "$dir/cw-swapfile"
275 sudo chmod 600 "$dir/cw-swapfile"
276 sudo mkswap "$dir/cw-swapfile" >/dev/null
277 sudo swapon "$dir/cw-swapfile"
278 fi
279 free -g
280 df -h "$dir"
281 - name: Build static Linux binaries (musl)
282 if: endsWith(matrix.target, '-unknown-linux-musl')
283 shell: bash
284 run: |
285 sudo apt-get update
286 sudo apt-get install -y binutils musl-tools
287 rustup target add ${{ matrix.target }}
288 cargo build --profile dist --locked --target ${{ matrix.target }} -p codewhale-cli
289 - name: Configure Android NDK linker
290 if: matrix.target == 'aarch64-linux-android' && runner.os == 'Linux'
291 shell: bash
292 env:
293 ANDROID_NDK_VERSION: 27.2.12479018
294 run: |
295 set -euo pipefail
296 sudo apt-get update
297 sudo apt-get install -y libclang-dev
298 ndk="${ANDROID_NDK_ROOT:-${ANDROID_NDK_HOME:-}}"
299 linker=""
300 if [[ -n "${ndk}" ]]; then
301 linker="${ndk}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang"
302 fi
303 if [[ -z "${linker}" || ! -x "${linker}" ]]; then
304 if ! command -v sdkmanager >/dev/null 2>&1; then
305 echo "sdkmanager is required to install Android NDK ${ANDROID_NDK_VERSION}" >&2
306 exit 1
307 fi
308 android_home="${ANDROID_HOME:-${ANDROID_SDK_ROOT:-}}"
309 if [[ -z "${android_home}" ]]; then
310 echo "ANDROID_HOME or ANDROID_SDK_ROOT is required to install Android NDK ${ANDROID_NDK_VERSION}" >&2
311 exit 1
312 fi
313 yes | sdkmanager --licenses >/dev/null || true
314 sdkmanager --install "ndk;${ANDROID_NDK_VERSION}"
315 ndk="${android_home}/ndk/${ANDROID_NDK_VERSION}"
316 linker="${ndk}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang"
317 fi
318 ar="${ndk}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar"
319 if [[ ! -x "${linker}" ]]; then
320 echo "Android linker not found: ${linker}" >&2
321 exit 1
322 fi
323 if [[ ! -x "${ar}" ]]; then
324 echo "Android archiver not found: ${ar}" >&2
325 exit 1
326 fi
327 {
328 echo "ANDROID_NDK_ROOT=${ndk}"
329 echo "ANDROID_NDK_HOME=${ndk}"
330 echo "CC_aarch64_linux_android=${linker}"
331 echo "AR_aarch64_linux_android=${ar}"
332 echo "CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=${linker}"
333 echo "BINDGEN_EXTRA_CLANG_ARGS_aarch64_linux_android=--target=aarch64-linux-android24 --sysroot=${ndk}/toolchains/llvm/prebuilt/linux-x86_64/sysroot"
334 } >> "${GITHUB_ENV}"
335 - name: Hold this machine's build lock (self-hosted)
336 if: runner.environment == 'self-hosted'
337 shell: bash
338 run: |
339 if [ -z "${CODEWHALE_BUILD_LOCK_FILE:-}" ]; then
340 echo "CODEWHALE_BUILD_LOCK_FILE is not set on this runner; building without the machine lock."
341 exit 0
342 fi
343 hold="$RUNNER_TEMP/cw-build-lock.hold"
344 ready="$RUNNER_TEMP/cw-build-lock.ready"
345 log="$RUNNER_TEMP/cw-build-lock.log"
346 touch "$hold"
347 rm -f "$ready"
348 # shellcheck disable=SC2016
349 nohup python3 scripts/build-lock.py "$CODEWHALE_BUILD_LOCK_FILE" -- \
350 sh -c 'touch "$1"; while [ -e "$2" ]; do sleep 2; done' _ "$ready" "$hold" \
351 >"$log" 2>&1 &
352 shown=0
353 until [ -e "$ready" ]; do
354 if [ "$shown" -eq 0 ] && [ -s "$log" ]; then cat "$log"; shown=1; fi
355 sleep 2
356 done
357 cat "$log"
358 echo "CODEWHALE_BUILD_LOCK_HELD=1" >> "$GITHUB_ENV"
359 - name: Build
360 if: ${{ !endsWith(matrix.target, '-unknown-linux-musl') && matrix.platform != 'ohos-arm64' }}
361 shell: bash
362 run: cargo build --profile dist --locked --target ${{ matrix.target }} -p codewhale-cli
363 - name: Release this machine's build lock (self-hosted)
364 if: always() && runner.environment == 'self-hosted'
365 shell: bash
366 run: rm -f "$RUNNER_TEMP/cw-build-lock.hold"
367 - name: Install OpenHarmony native SDK
368 if: matrix.platform == 'ohos-arm64'
369 id: ohos-sdk
370 # Pin the action: it downloads a published OpenHarmony SDK and verifies
371 # the archive checksum, so a broken mirror fails here instead of
372 # producing a binary linked against host headers.
373 uses: openharmony-rs/setup-ohos-sdk@b312caf8a43bb836aa24c08f65f97e1f09a89cad
374 with:
375 version: '6.1'
376 # `toolchains` carries binary-sign-tool.jar, which signs the binary
377 # below; a release without it would ship an ELF the device refuses to
378 # execute.
379 components: 'native;toolchains'
380 # One download per release is cheaper than letting a tag save a 715 MB
381 # cache entry that main's jobs then compete with.
382 cache: false
383 mirror: true
384 - name: Install Java for the OpenHarmony binary signer
385 if: matrix.platform == 'ohos-arm64'
386 uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0
387 with:
388 distribution: temurin
389 java-version: '17'
390 - name: Cross-compile and code-sign the OpenHarmony binary
391 if: matrix.platform == 'ohos-arm64'
392 shell: bash
393 env:
394 OHOS_NATIVE_SDK: ${{ steps.ohos-sdk.outputs.ohos_sdk_native }}
395 run: |
396 set -euo pipefail
397 test -x "${OHOS_NATIVE_SDK}/llvm/bin/clang"
398 test -d "${OHOS_NATIVE_SDK}/sysroot"
399 # ohos-env.sh also puts the SDK's cmake on PATH, which aws-lc-sys
400 # needs; without it the build dies inside its CMake probe.
401 . ./scripts/ohos/ohos-env.sh
402 cargo build --profile dist --locked --target "${{ matrix.target }}" -p codewhale-cli
403
404 bin="target/${{ matrix.target }}/dist/${{ matrix.cli_binary }}"
405 tools="$(dirname "${OHOS_NATIVE_SDK}")/toolchains/lib"
406 # SDK 6.1 publishes the native `binary-sign-tool` and no jar, while
407 # DevEco ships the Java build; both take the same arguments.
408 if [[ -f "${tools}/binary-sign-tool.jar" ]]; then
409 signer=(java -jar "${tools}/binary-sign-tool.jar")
410 elif [[ -f "${tools}/binary-sign-tool" ]]; then
411 chmod +x "${tools}/binary-sign-tool"
412 signer=("${tools}/binary-sign-tool")
413 else
414 echo "no binary-sign-tool in ${tools}; the device refuses an unsigned ELF" >&2
415 ls -la "${tools}" >&2
416 exit 1
417 fi
418 "${signer[@]}" sign -inFile "${bin}" -outFile "${bin}" -selfSign 1
419
420 # Capture then match. `tool | grep -q` cannot be used under
421 # `pipefail`: grep exits at the first match, the tool takes SIGPIPE,
422 # and llvm-readelf reports that as exit 74, which reads as a failed
423 # verification of a good binary.
424 signature="$("${signer[@]}" display-sign -inFile "${bin}")"
425 case "${signature}" in
426 *'code signature is self-sign'*) ;;
427 *)
428 echo 'the staged binary is not self-signed; the device would refuse to execute it' >&2
429 exit 1
430 ;;
431 esac
432
433 kind="$(file -b "${bin}")"
434 case "${kind}" in
435 *'ARM aarch64'*) ;;
436 *)
437 echo "not an aarch64 ELF: ${kind}" >&2
438 exit 1
439 ;;
440 esac
441
442 headers="$("${OHOS_NATIVE_SDK}/llvm/bin/llvm-readelf" -l "${bin}")"
443 case "${headers}" in
444 *'/lib/ld-musl-aarch64.so.1'*) ;;
445 *)
446 echo "unexpected ELF interpreter for ${bin}" >&2
447 exit 1
448 ;;
449 esac
450 - name: Materialize codew command alias
451 shell: bash
452 run: |
453 bin_dir="target/${{ matrix.target }}/dist"
454 cp "${bin_dir}/${{ matrix.cli_binary }}" "${bin_dir}/${{ matrix.shim_binary }}"
455 cmp "${bin_dir}/${{ matrix.cli_binary }}" "${bin_dir}/${{ matrix.shim_binary }}"
456 - name: Verify static Linux binaries and launch on matching native runners
457 if: >-
458 endsWith(matrix.target, '-unknown-linux-musl') &&
459 ((startsWith(matrix.target, 'x86_64-') && runner.arch == 'X64') ||
460 (startsWith(matrix.target, 'aarch64-') && runner.arch == 'ARM64'))
461 shell: bash
462 run: |
463 set -euo pipefail
464 bin_dir="target/${{ matrix.target }}/dist"
465 for binary in "${{ matrix.cli_binary }}" "${{ matrix.shim_binary }}"; do
466 bin_path="${bin_dir}/${binary}"
467 if readelf -l "${bin_path}" | grep -Fq 'INTERP'; then
468 echo "Expected a static musl binary, but ${bin_path} has an ELF interpreter" >&2
469 exit 1
470 fi
471 "${bin_path}" --version
472 done
473 - name: Smoke binaries on matching native runners
474 if: >-
475 matrix.target != 'aarch64-linux-android' &&
476 ((startsWith(matrix.target, 'x86_64-') && runner.arch == 'X64') ||
477 (startsWith(matrix.target, 'aarch64-') && runner.arch == 'ARM64'))
478 shell: bash
479 run: |
480 bin_dir="target/${{ matrix.target }}/dist"
481 "${bin_dir}/${{ matrix.cli_binary }}" --version
482 "${bin_dir}/${{ matrix.shim_binary }}" --version
483 - name: Windows Terminal clipboard-to-draft acceptance
484 if: matrix.platform == 'windows-x64'
485 timeout-minutes: 5
486 shell: pwsh
487 run: node scripts/release/windows-terminal-clipboard.mjs "target/${{ matrix.target }}/dist/codewhale.exe" "${{ runner.temp }}/windows-clipboard"
488 - name: Retain Windows Terminal clipboard-to-draft evidence
489 if: ${{ !cancelled() && matrix.platform == 'windows-x64' }}
490 uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
491 with:
492 name: release-windows-clipboard-${{ github.sha }}
493 path: ${{ runner.temp }}/windows-clipboard/
494 if-no-files-found: error
495 retention-days: ${{ inputs.retention_days }}
496 - name: Stage binaries
497 shell: bash
498 run: |
499 stage_binary() {
500 local binary="$1"
501 local artifact="$2"
502 local bin_path="target/${{ matrix.target }}/dist/${binary}"
503 if [[ ! -f "${bin_path}" ]]; then
504 echo "Binary not at ${bin_path}; searching target/ for ${binary}:" >&2
505 find target -name "${binary}" -type f
506 exit 1
507 fi
508 cp "${bin_path}" "${artifact}"
509 }
510
511 stage_binary "${{ matrix.cli_binary }}" "${{ matrix.cli_artifact }}"
512 stage_binary "${{ matrix.shim_binary }}" "${{ matrix.shim_artifact }}"
513 # Compatibility bridge for v0.9.4's hard-coded release
514 # completeness/updater contract. This is the same runtime, not a
515 # separately compiled or installed TUI command.
516 stage_binary "${{ matrix.cli_binary }}" "${{ matrix.compat_tui_artifact }}"
517 - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2
518 if: inputs.compiled_host_delivery && contains(format(',{0},', inputs.compiled_host_targets), format(',{0},', matrix.platform))
519 with:
520 bun-version: 1.4.0
521 - name: Stage exact qualified optional host image
522 if: inputs.compiled_host_delivery && contains(format(',{0},', inputs.compiled_host_targets), format(',{0},', matrix.platform))
523 shell: bash
524 env:
525 GH_TOKEN: ${{ github.token }}
526 QUALIFICATION_RUN: ${{ inputs.compiled_host_run_id }}
527 TARGET_PLATFORM: ${{ matrix.platform }}
528 RELEASE_VERSION: ${{ inputs.version }}
529 RUNTIME_CLOSURE_DIR: ${{ vars.CODEWHALE_COMPILED_HOST_CLOSURE_DIR }}
530 run: |
531 set -euo pipefail
532 proof_dir="${RUNNER_TEMP}/compiled-host-proof-${TARGET_PLATFORM}"
533 node scripts/release/fetch-compiled-host-proof.js --repo "${GITHUB_REPOSITORY}" --run-id "${QUALIFICATION_RUN}" --source-sha "${GITHUB_SHA}" --target "${TARGET_PLATFORM}" --output "${proof_dir}"
534 test -n "${RUNTIME_CLOSURE_DIR}" || { echo 'Enabled compiled-host delivery requires reviewed complete local runtime notices/relink-source closure' >&2; exit 1; }
535 bun_binary="$(bun -p 'process.execPath')"
536 extension=""
537 if [[ "${TARGET_PLATFORM}" == windows-* ]]; then extension=.exe; fi
538 node scripts/release/stage-compiled-host.mjs --bun "${bun_binary}" --compiled-image "${proof_dir}/codewhale-extension-host${extension}" --native-receipt "${proof_dir}/native-receipt.json" --runtime-closure "${RUNTIME_CLOSURE_DIR}/${TARGET_PLATFORM}.json" --target "${TARGET_PLATFORM}" --version "${RELEASE_VERSION}" --source-sha "${GITHUB_SHA}" --output-dir "compiled-host-${TARGET_PLATFORM}"
539 - name: Check every staged Windows executable import
540 if: startsWith(matrix.platform, 'windows-')
541 shell: pwsh
542 run: |
543 $ErrorActionPreference = 'Stop'
544 $binaries = @('${{ matrix.cli_artifact }}', '${{ matrix.shim_artifact }}', '${{ matrix.compat_tui_artifact }}')
545 $hostDirectory = 'compiled-host-${{ matrix.platform }}'
546 if (Test-Path $hostDirectory) {
547 $binaries += @(Get-ChildItem -Path $hostDirectory -Filter *.exe -Recurse -File | ForEach-Object { $_.FullName })
548 }
549 python scripts/release/check-windows-imports.py --expected-machine '${{ matrix.platform }}' --output '${{ runner.temp }}/windows-imports-${{ matrix.platform }}' @binaries
550 if ($LASTEXITCODE -ne 0) { throw 'Windows static import qualification failed' }
551 - name: Retain Windows import receipts
552 if: always() && startsWith(matrix.platform, 'windows-')
553 uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
554 with:
555 name: windows-imports-${{ matrix.platform }}-${{ github.sha }}
556 path: ${{ runner.temp }}/windows-imports-${{ matrix.platform }}/
557 if-no-files-found: warn
558 retention-days: ${{ inputs.retention_days }}
559 overwrite: true
560 - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
561 if: inputs.compiled_host_delivery && contains(format(',{0},', inputs.compiled_host_targets), format(',{0},', matrix.platform))
562 with:
563 name: codewhale-compiled-host-${{ matrix.platform }}
564 path: |
565 compiled-host-${{ matrix.platform }}/codewhale-extension-host-*
566 compiled-host-${{ matrix.platform }}/codewhale-extension-hosts.json
567 if-no-files-found: error
568 retention-days: ${{ inputs.retention_days }}
569 overwrite: true
570 - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
571 with:
572 name: ${{ matrix.cli_artifact }}
573 path: ${{ matrix.cli_artifact }}
574 if-no-files-found: error
575 retention-days: ${{ inputs.retention_days }}
576 overwrite: true
577 - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
578 with:
579 name: ${{ matrix.shim_artifact }}
580 path: ${{ matrix.shim_artifact }}
581 if-no-files-found: error
582 retention-days: ${{ inputs.retention_days }}
583 overwrite: true
584 - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
585 with:
586 name: ${{ matrix.compat_tui_artifact }}
587 path: ${{ matrix.compat_tui_artifact }}
588 if-no-files-found: error
589 retention-days: ${{ inputs.retention_days }}
590 overwrite: true
591 - name: Remove the fresh release home (self-hosted)
592 if: always() && runner.environment == 'self-hosted'
593 shell: bash
594 run: rm -rf -- "${CW_RELEASE_HOME:?}" target
595
596 bundle:
597 timeout-minutes: 15
598 needs: build
599 if: ${{ !cancelled() && needs.build.result == 'success' }}
600 runs-on: ubuntu-24.04
601 steps:
602 - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
603 - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
604 with:
605 path: artifacts
606 pattern: '*'
607 - name: Collect only qualified requested compiled hosts
608 if: inputs.compiled_host_delivery
609 shell: bash
610 run: node scripts/release/stage-compiled-host.mjs --collect artifacts --output-dir artifacts/codewhale-compiled-hosts
611 - name: Create and checksum platform archives
612 shell: bash
613 env:
614 SOURCE_SHA: ${{ github.sha }}
615 run: |
616 set -euo pipefail
617 source_date_epoch="$(git show -s --format=%ct "${SOURCE_SHA}")"
618 if [[ ! "${source_date_epoch}" =~ ^[0-9]+$ ]]; then
619 echo "Could not read a Unix timestamp for source commit ${SOURCE_SHA}" >&2
620 exit 1
621 fi
622 SOURCE_DATE_EPOCH="${source_date_epoch}" \
623 bash scripts/release/create-release-bundles.sh artifacts bundles
624 - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
625 with:
626 name: codewhale-bundles
627 path: |
628 bundles/*.tar.gz
629 bundles/*.zip
630 bundles/codewhale-bundles-sha256.txt
631 if-no-files-found: error
632 retention-days: ${{ inputs.retention_days }}
633 overwrite: true
634 - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
635 if: inputs.compiled_host_delivery
636 with:
637 name: codewhale-compiled-hosts
638 path: artifacts/codewhale-compiled-hosts/*
639 if-no-files-found: error
640 retention-days: ${{ inputs.retention_days }}
641 overwrite: true
642
643 windows-installer:
644 timeout-minutes: 15
645 needs: build
646 if: ${{ !cancelled() && needs.build.result == 'success' }}
647 runs-on: windows-latest
648 steps:
649 - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
650 - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
651 with:
652 path: artifacts
653 pattern: '*windows-x64*'
654 - name: Install NSIS
655 shell: pwsh
656 run: ./scripts/installer/install-nsis.ps1
657 - name: Build NSIS installer
658 shell: pwsh
659 run: |
660 $ErrorActionPreference = "Stop"
661 Copy-Item "artifacts\codewhale-windows-x64.exe\codewhale-windows-x64.exe" "scripts\installer\codewhale.exe"
662 Copy-Item "artifacts\codew-windows-x64.exe\codew-windows-x64.exe" "scripts\installer\codew.exe"
663 $makensis = "${env:ProgramFiles(x86)}\NSIS\makensis.exe"
664 if (!(Test-Path $makensis)) {
665 $makensis = "${env:ProgramFiles}\NSIS\makensis.exe"
666 }
667 if (!(Test-Path $makensis)) {
668 throw "makensis.exe not found after NSIS install"
669 }
670 $hostDefine = @()
671 $hostCatalog = "artifacts\codewhale-compiled-host-windows-x64\codewhale-extension-hosts.json"
672 if (Test-Path $hostCatalog) {
673 node -e "const h=require('./npm/codewhale/scripts/compiled-hosts'); const fs=require('fs'); const p=require('path'); const f=process.argv[1]; h.verifyDirectory(p.dirname(f), h.parseCatalog(fs.readFileSync(f),'${{ inputs.version }}'));" $hostCatalog
674 if ($LASTEXITCODE -ne 0) { throw 'Compiled host payload/catalog verification failed' }
675 $catalog = Get-Content -Raw $hostCatalog | ConvertFrom-Json
676 $hostEntry = @($catalog.hosts | Where-Object { $_.target -eq 'windows-x64' })
677 if ($hostEntry.Count -ne 1) { throw 'No unique qualified Windows host' }
678 $hostDir = Split-Path $hostCatalog
679 Copy-Item "$hostDir\$($hostEntry[0].asset)" "scripts\installer\codewhale-extension-host.exe"
680 Copy-Item "$hostDir\$($hostEntry[0].notices_asset)" "scripts\installer\codewhale-extension-host.LICENSES.txt"
681 Copy-Item "$hostDir\$($hostEntry[0].source_asset)" "scripts\installer\codewhale-extension-host.relink-source.tar.gz"
682 Copy-Item $hostCatalog "scripts\installer\codewhale-extension-host.release.json"
683 $hostDefine = @('/DCOMPILED_HOST=1')
684 }
685 Push-Location scripts\installer
686 & $makensis "/DVERSION=${{ inputs.version }}" @hostDefine "codewhale.nsi"
687 Pop-Location
688 if (!(Test-Path "scripts\installer\CodeWhaleSetup.exe")) {
689 throw "CodeWhaleSetup.exe was not produced"
690 }
691 - name: Check Windows installer and embedded executables
692 shell: pwsh
693 run: |
694 $ErrorActionPreference = 'Stop'
695 $evidenceDirectory = '${{ runner.temp }}/windows-installer-imports'
696 $embeddedDirectory = Join-Path $evidenceDirectory 'embedded'
697 New-Item -Path $evidenceDirectory -ItemType Directory -Force | Out-Null
698 & 7z l 'scripts/installer/CodeWhaleSetup.exe' | Out-File (Join-Path $evidenceDirectory 'archive-listing.txt') -Encoding utf8
699 if ($LASTEXITCODE -ne 0) { throw 'NSIS embedded payload inventory failed' }
700 & 7z x 'scripts/installer/CodeWhaleSetup.exe' "-o$embeddedDirectory" '$PLUGINSDIR/*.dll' | Out-File (Join-Path $evidenceDirectory 'archive-extraction.txt') -Encoding utf8
701 if ($LASTEXITCODE -ne 0) { throw 'NSIS embedded plugin extraction failed' }
702 $plugins = @(Get-ChildItem -Path $embeddedDirectory -Filter *.dll -Recurse -File)
703 if ($plugins.Name -notcontains 'System.dll' -or $plugins.Name -notcontains 'nsDialogs.dll') { throw 'Expected MUI2 System and nsDialogs plugin payloads' }
704 $binaries = @(Get-ChildItem -Path scripts/installer -Filter *.exe -File | ForEach-Object { $_.FullName })
705 if ($binaries.Count -lt 3) { throw 'Expected installer, CLI and shim executables' }
706 $binaries += @($plugins | ForEach-Object { $_.FullName })
707 python scripts/release/check-windows-imports.py --output $evidenceDirectory @binaries
708 if ($LASTEXITCODE -ne 0) { throw 'Windows installer static import qualification failed' }
709 - name: Retain Windows installer import receipts
710 if: always()
711 uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
712 with:
713 name: windows-installer-imports-${{ github.sha }}
714 path: ${{ runner.temp }}/windows-installer-imports/
715 if-no-files-found: warn
716 retention-days: ${{ inputs.retention_days }}
717 overwrite: true
718 - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
719 with:
720 name: CodeWhaleSetup.exe
721 path: scripts/installer/CodeWhaleSetup.exe
722 if-no-files-found: error
723 retention-days: ${{ inputs.retention_days }}
724 overwrite: true
725
726 assemble:
727 timeout-minutes: 15
728 needs: [bundle, windows-installer]
729 if: ${{ !cancelled() && needs.bundle.result == 'success' && needs.windows-installer.result == 'success' }}
730 runs-on: ubuntu-24.04
731 steps:
732 - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
733 - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
734 with:
735 node-version: 22
736 package-manager-cache: false
737 - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
738 with:
739 path: intermediate-artifacts
740 pattern: '*'
741 - name: Assemble exact authoritative release inventory
742 run: node scripts/release/assemble-release-assets.js intermediate-artifacts release-assets
743 - name: Sign the checksum manifest when the release key is configured
744 env:
745 CODEWHALE_RELEASE_SIGNING_KEY: ${{ secrets.CODEWHALE_RELEASE_SIGNING_KEY }}
746 REQUIRE_SIGNATURE: ${{ inputs.require_signature }}
747 VERSION: ${{ inputs.version }}
748 run: |
749 set -euo pipefail
750 if [[ -z "${CODEWHALE_RELEASE_SIGNING_KEY}" ]]; then
751 if [[ "${REQUIRE_SIGNATURE}" == "true" ]]; then
752 echo "CODEWHALE_RELEASE_SIGNING_KEY is not configured; a tagged release must be signed." >&2
753 exit 1
754 fi
755 echo "CODEWHALE_RELEASE_SIGNING_KEY is not configured; this release is unsigned and automatic updates wait for each user's OK."
756 exit 0
757 fi
758 bash scripts/release/sign-release-manifest.sh "${VERSION}" \
759 release-assets/codewhale-artifacts-sha256.txt \
760 release-assets/codewhale-artifacts-sha256.txt.sig
761 node scripts/release/assemble-release-assets.js --verify release-assets
762 - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
763 with:
764 name: codewhale-release-assets
765 path: release-assets/*
766 if-no-files-found: error
767 retention-days: ${{ inputs.retention_days }}
768 compression-level: 0
769 overwrite: true
770
771 smoke:
772 timeout-minutes: 15
773 needs: assemble
774 if: ${{ !cancelled() && needs.assemble.result == 'success' }}
775 runs-on: ubuntu-24.04
776 steps:
777 - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
778 - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
779 with:
780 node-version: 22
781 package-manager-cache: false
782 - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
783 with:
784 name: codewhale-release-assets
785 path: release-assets
786 - name: Verify 38-asset bridge inventory and checksum manifests (single binary)
787 run: node scripts/release/assemble-release-assets.js --verify release-assets
788 - name: Test release inventory contracts
789 run: |
790 node --test scripts/release/assemble-release-assets.test.js
791 node --test npm/codewhale/test/artifacts.test.js npm/codewhale/test/release-assets.test.js
792 - name: Render AUR metadata from candidate Linux archives
793 if: ${{ !contains(inputs.version, '-') }}
794 run: bash packaging/aur/render.sh release-assets "${RUNNER_TEMP}/codewhale-bin"
795 - name: Smoke packed npm wrapper against candidate assets
796 env:
797 CODEWHALE_SMOKE_ASSETS_DIR: ${{ github.workspace }}/release-assets
798 run: node scripts/release/npm-wrapper-smoke.js
799 - name: Record non-public candidate identity
800 shell: bash
801 run: |
802 {
803 echo "### Release artifact candidate"
804 echo ""
805 echo "- Source: \`${{ github.sha }}\`"
806 echo "- Version metadata: \`${{ inputs.version }}\`"
807 echo "- Inventory: 8 targets / 38 files (single binary; 8 legacy alias assets)"
808 echo "- Publication: none (Actions artifact \`codewhale-release-assets\` only)"
809 } >> "${GITHUB_STEP_SUMMARY}"
810
810 lines YAML