| 1 | name: Release |
| 2 | |
| 3 | on: |
| 4 | push: |
| 5 | tags: ['v*'] |
| 6 | workflow_dispatch: |
| 7 | inputs: |
| 8 | version: |
| 9 | description: 'Release version without v; dispatch from the matching existing vX.Y.Z or vX.Y.Z-prerelease tag ref' |
| 10 | required: true |
| 11 | type: string |
| 12 | |
| 13 | concurrency: |
| 14 | group: release-${{ github.ref_name }} |
| 15 | cancel-in-progress: false |
| 16 | |
| 17 | permissions: |
| 18 | contents: read |
| 19 | |
| 20 | env: |
| 21 | CARGO_TERM_COLOR: always |
| 22 | CARGO_INCREMENTAL: 0 |
| 23 | RUSTFLAGS: -Dwarnings |
| 24 | |
| 25 | jobs: |
| 26 | resolve: |
| 27 | timeout-minutes: 10 |
| 28 | runs-on: ubuntu-24.04 |
| 29 | permissions: |
| 30 | contents: read |
| 31 | # Read release-candidate.yml runs for the RC receipt check below. |
| 32 | actions: read |
| 33 | outputs: |
| 34 | tag: ${{ steps.release.outputs.tag }} |
| 35 | sha: ${{ steps.release.outputs.sha }} |
| 36 | version: ${{ steps.release.outputs.version }} |
| 37 | prerelease: ${{ steps.release.outputs.prerelease }} |
| 38 | steps: |
| 39 | - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 |
| 40 | with: |
| 41 | fetch-depth: 0 |
| 42 | - name: Resolve release source |
| 43 | id: release |
| 44 | shell: bash |
| 45 | env: |
| 46 | INPUT_VERSION: ${{ inputs.version }} |
| 47 | run: | |
| 48 | set -euo pipefail |
| 49 | |
| 50 | if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then |
| 51 | if ! [[ "${INPUT_VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then |
| 52 | echo "::error::Release version '${INPUT_VERSION}' must use X.Y.Z or X.Y.Z-prerelease." >&2 |
| 53 | exit 1 |
| 54 | fi |
| 55 | tag="v${INPUT_VERSION}" |
| 56 | if [[ "${GITHUB_REF}" != "refs/tags/${tag}" ]]; then |
| 57 | echo "::error::Dispatch release.yml from --ref ${tag}, not ${GITHUB_REF}." >&2 |
| 58 | exit 1 |
| 59 | fi |
| 60 | else |
| 61 | tag="${GITHUB_REF_NAME}" |
| 62 | fi |
| 63 | |
| 64 | if ! [[ "${tag}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then |
| 65 | echo "::error::Release tag '${tag}' must use vX.Y.Z or vX.Y.Z-prerelease." >&2 |
| 66 | exit 1 |
| 67 | fi |
| 68 | if ! git rev-parse --verify "refs/tags/${tag}^{commit}" >/dev/null 2>&1; then |
| 69 | echo "::error::Release tag ${tag} does not exist. Create it from the frozen main commit before dispatching." >&2 |
| 70 | exit 1 |
| 71 | fi |
| 72 | |
| 73 | sha="$(git rev-parse "refs/tags/${tag}^{commit}")" |
| 74 | event_sha="$(git rev-parse "${GITHUB_SHA}^{commit}")" |
| 75 | if [[ "${event_sha}" != "${sha}" ]]; then |
| 76 | echo "::error::Trigger SHA ${event_sha} does not match ${tag} at ${sha}; the tag moved after this run was created." >&2 |
| 77 | exit 1 |
| 78 | fi |
| 79 | |
| 80 | version="${tag#v}" |
| 81 | { |
| 82 | echo "tag=${tag}" |
| 83 | echo "sha=${sha}" |
| 84 | echo "version=${version}" |
| 85 | if [[ "${version}" == *-* ]]; then |
| 86 | echo "prerelease=true" |
| 87 | else |
| 88 | echo "prerelease=false" |
| 89 | fi |
| 90 | } >> "${GITHUB_OUTPUT}" |
| 91 | - name: Validate tagged release metadata |
| 92 | shell: bash |
| 93 | env: |
| 94 | SHA: ${{ steps.release.outputs.sha }} |
| 95 | TAG: ${{ steps.release.outputs.tag }} |
| 96 | run: | |
| 97 | set -euo pipefail |
| 98 | git checkout --detach "${SHA}" |
| 99 | expected="${TAG#v}" |
| 100 | workspace_version="$(grep -E '^version = "' Cargo.toml | head -n1 | sed -E 's/^version = "([^"]+)".*/\1/')" |
| 101 | npm_version="$(node -p "require('./npm/codewhale/package.json').version")" |
| 102 | binary_version="$(node -p "require('./npm/codewhale/package.json').codewhaleBinaryVersion")" |
| 103 | sdk_version="$(node -p "require('./npm/runtime-sdk/package.json').version")" |
| 104 | vscode_version="$(node -p "require('./extensions/vscode/package.json').version")" |
| 105 | for pair in \ |
| 106 | "workspace:${workspace_version}" \ |
| 107 | "npm:${npm_version}" \ |
| 108 | "npm binary:${binary_version}" \ |
| 109 | "runtime-sdk:${sdk_version}" \ |
| 110 | "vscode:${vscode_version}"; do |
| 111 | label="${pair%%:*}" |
| 112 | actual="${pair#*:}" |
| 113 | if [[ "${actual}" != "${expected}" ]]; then |
| 114 | echo "::error::${label} version ${actual} does not match tag ${TAG}." >&2 |
| 115 | exit 1 |
| 116 | fi |
| 117 | done |
| 118 | ./scripts/release/check-versions.sh --require-dated-release |
| 119 | - name: Require release source on main |
| 120 | run: ./scripts/release/ensure-release-on-main.sh "${{ steps.release.outputs.sha }}" |
| 121 | - name: Require a green release-candidate receipt for this exact SHA |
| 122 | # Fail fast, before the long parity and artifact builds: the tag must |
| 123 | # point at a commit a release-candidate run already validated, |
| 124 | # Parity included. A missing receipt means run the RC on this SHA, |
| 125 | # never move the tag (v0.10.0 was re-pointed after the RC skipped |
| 126 | # parity). |
| 127 | env: |
| 128 | GH_TOKEN: ${{ github.token }} |
| 129 | SHA: ${{ steps.release.outputs.sha }} |
| 130 | run: ./scripts/release/require-rc-receipt.sh "${GITHUB_REPOSITORY}" "${SHA}" |
| 131 | - name: Refuse an existing public asset set |
| 132 | env: |
| 133 | GH_TOKEN: ${{ github.token }} |
| 134 | TAG: ${{ steps.release.outputs.tag }} |
| 135 | run: node scripts/release/ensure-release-assets-absent.js "${GITHUB_REPOSITORY}" "${TAG}" |
| 136 | |
| 137 | parity: |
| 138 | name: Parity |
| 139 | needs: resolve |
| 140 | uses: ./.github/workflows/release-parity.yml |
| 141 | |
| 142 | artifacts: |
| 143 | permissions: |
| 144 | contents: read |
| 145 | actions: read |
| 146 | needs: [parity, resolve] |
| 147 | if: ${{ !cancelled() && needs.resolve.result == 'success' && needs.parity.result == 'success' }} |
| 148 | uses: ./.github/workflows/release-artifacts.yml |
| 149 | with: |
| 150 | source_sha: ${{ needs.resolve.outputs.sha }} |
| 151 | version: ${{ needs.resolve.outputs.version }} |
| 152 | compiled_host_delivery: ${{ vars.CODEWHALE_COMPILED_HOST_DELIVERY == '1' }} |
| 153 | compiled_host_run_id: ${{ vars.CODEWHALE_COMPILED_HOST_QUALIFICATION_RUN_ID || '' }} |
| 154 | compiled_host_targets: ${{ vars.CODEWHALE_COMPILED_HOST_TARGETS || 'linux-x64,macos-arm64,windows-x64' }} |
| 155 | retention_days: 14 |
| 156 | require_signature: true |
| 157 | secrets: |
| 158 | CODEWHALE_RELEASE_SIGNING_KEY: ${{ secrets.CODEWHALE_RELEASE_SIGNING_KEY }} |
| 159 | |
| 160 | docker-build: |
| 161 | needs: [artifacts, resolve] |
| 162 | if: ${{ !cancelled() && needs.artifacts.result == 'success' && needs.resolve.outputs.prerelease != 'true' }} |
| 163 | name: Docker ${{ matrix.platform }} |
| 164 | timeout-minutes: 60 |
| 165 | strategy: |
| 166 | fail-fast: false |
| 167 | matrix: |
| 168 | include: |
| 169 | - runner: ubuntu-latest |
| 170 | platform: linux/amd64 |
| 171 | architecture: amd64 |
| 172 | cli_artifact: codewhale-linux-x64 |
| 173 | shim_artifact: codew-linux-x64 |
| 174 | - runner: ubuntu-24.04-arm |
| 175 | platform: linux/arm64 |
| 176 | architecture: arm64 |
| 177 | cli_artifact: codewhale-linux-arm64 |
| 178 | shim_artifact: codew-linux-arm64 |
| 179 | runs-on: ${{ matrix.runner == 'ubuntu-latest' && 'ubuntu-24.04' || matrix.runner }} |
| 180 | permissions: |
| 181 | contents: read |
| 182 | packages: write |
| 183 | steps: |
| 184 | - name: Checkout release infrastructure |
| 185 | uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 |
| 186 | with: |
| 187 | ref: ${{ needs.resolve.outputs.sha }} |
| 188 | path: infra |
| 189 | - name: Download Codewhale release binary |
| 190 | uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8 |
| 191 | with: |
| 192 | name: ${{ matrix.cli_artifact }} |
| 193 | path: docker-context/bin |
| 194 | - name: Download codew release alias |
| 195 | uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8 |
| 196 | with: |
| 197 | name: ${{ matrix.shim_artifact }} |
| 198 | path: docker-context/bin |
| 199 | - name: Verify native release bytes |
| 200 | shell: bash |
| 201 | env: |
| 202 | CLI_ARTIFACT: ${{ matrix.cli_artifact }} |
| 203 | SHIM_ARTIFACT: ${{ matrix.shim_artifact }} |
| 204 | run: | |
| 205 | set -euo pipefail |
| 206 | mv -- "docker-context/bin/${CLI_ARTIFACT}" docker-context/bin/codewhale |
| 207 | mv -- "docker-context/bin/${SHIM_ARTIFACT}" docker-context/bin/codew |
| 208 | chmod 0755 docker-context/bin/codewhale docker-context/bin/codew |
| 209 | cmp docker-context/bin/codewhale docker-context/bin/codew |
| 210 | docker-context/bin/codewhale --version |
| 211 | docker-context/bin/codew --version |
| 212 | - name: Set up Docker Buildx |
| 213 | uses: docker/setup-buildx-action@594f3bf4285d9ea8dc53c9a0c9c4092420091003 # v4 |
| 214 | - name: Log in to GitHub Container Registry |
| 215 | uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4 |
| 216 | with: |
| 217 | registry: ghcr.io |
| 218 | username: ${{ github.repository_owner }} |
| 219 | password: ${{ secrets.GITHUB_TOKEN }} |
| 220 | - name: Normalize image name |
| 221 | id: image |
| 222 | shell: bash |
| 223 | run: echo "name=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT" |
| 224 | - name: Extract image labels |
| 225 | id: meta |
| 226 | uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6 |
| 227 | with: |
| 228 | images: | |
| 229 | ${{ steps.image.outputs.name }} |
| 230 | tags: | |
| 231 | type=raw,value=${{ needs.resolve.outputs.version }} |
| 232 | - name: Revalidate release tag before container upload |
| 233 | env: |
| 234 | EXPECTED_SHA: ${{ needs.resolve.outputs.sha }} |
| 235 | TAG: ${{ needs.resolve.outputs.tag }} |
| 236 | run: | |
| 237 | ./infra/scripts/release/verify-remote-tag.sh \ |
| 238 | "https://github.com/${GITHUB_REPOSITORY}.git" \ |
| 239 | "${TAG}" \ |
| 240 | "${EXPECTED_SHA}" |
| 241 | - name: Assemble and push native image by digest |
| 242 | id: build |
| 243 | uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7 |
| 244 | env: |
| 245 | DOCKER_BUILD_RECORD_UPLOAD: false |
| 246 | DOCKER_BUILD_SUMMARY: false |
| 247 | with: |
| 248 | context: docker-context |
| 249 | file: infra/packaging/docker/Dockerfile.release |
| 250 | platforms: ${{ matrix.platform }} |
| 251 | provenance: mode=max |
| 252 | sbom: true |
| 253 | labels: ${{ steps.meta.outputs.labels }} |
| 254 | outputs: type=image,name=${{ steps.image.outputs.name }},push-by-digest=true,name-canonical=true,push=true |
| 255 | - name: Smoke native image digest |
| 256 | shell: bash |
| 257 | env: |
| 258 | IMAGE: ${{ steps.image.outputs.name }}@${{ steps.build.outputs.digest }} |
| 259 | run: | |
| 260 | set -euo pipefail |
| 261 | docker pull "${IMAGE}" |
| 262 | docker run --rm --entrypoint codewhale "${IMAGE}" --version |
| 263 | docker run --rm --entrypoint codew "${IMAGE}" --version |
| 264 | - name: Export image digest |
| 265 | shell: bash |
| 266 | env: |
| 267 | DIGEST: ${{ steps.build.outputs.digest }} |
| 268 | run: | |
| 269 | set -euo pipefail |
| 270 | if ! [[ "${DIGEST}" =~ ^sha256:[0-9a-f]{64}$ ]]; then |
| 271 | echo "Unexpected image digest: ${DIGEST}" >&2 |
| 272 | exit 1 |
| 273 | fi |
| 274 | mkdir -p digests |
| 275 | touch "digests/${DIGEST#sha256:}" |
| 276 | - name: Upload image digest |
| 277 | uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 |
| 278 | with: |
| 279 | name: docker-digest-${{ matrix.architecture }} |
| 280 | path: digests/* |
| 281 | if-no-files-found: error |
| 282 | retention-days: 1 |
| 283 | overwrite: true |
| 284 | |
| 285 | # Derived channel: the tagged/latest manifest is published only after the |
| 286 | # canonical GitHub Release exists. docker-build pushes by digest (untagged) |
| 287 | # and smokes each image before the release, so a broken image still stops |
| 288 | # the release, but no public tag can point at a version whose GitHub |
| 289 | # Release was never published. |
| 290 | docker: |
| 291 | timeout-minutes: 30 |
| 292 | needs: [docker-build, release, resolve] |
| 293 | if: ${{ !cancelled() && needs.docker-build.result == 'success' && needs.release.result == 'success' && needs.resolve.outputs.prerelease != 'true' }} |
| 294 | runs-on: ubuntu-24.04 |
| 295 | permissions: |
| 296 | contents: read |
| 297 | packages: write |
| 298 | steps: |
| 299 | - name: Checkout release infrastructure |
| 300 | uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 |
| 301 | with: |
| 302 | ref: ${{ needs.resolve.outputs.sha }} |
| 303 | path: infra |
| 304 | - name: Download native image digests |
| 305 | uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8 |
| 306 | with: |
| 307 | path: digests |
| 308 | pattern: docker-digest-* |
| 309 | merge-multiple: true |
| 310 | - name: Set up Docker Buildx |
| 311 | uses: docker/setup-buildx-action@594f3bf4285d9ea8dc53c9a0c9c4092420091003 # v4 |
| 312 | - name: Log in to GitHub Container Registry |
| 313 | uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4 |
| 314 | with: |
| 315 | registry: ghcr.io |
| 316 | username: ${{ github.repository_owner }} |
| 317 | password: ${{ secrets.GITHUB_TOKEN }} |
| 318 | - name: Normalize image name |
| 319 | id: image |
| 320 | shell: bash |
| 321 | run: echo "name=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT" |
| 322 | - name: Extract metadata |
| 323 | id: meta |
| 324 | uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6 |
| 325 | with: |
| 326 | images: | |
| 327 | ${{ steps.image.outputs.name }} |
| 328 | tags: | |
| 329 | type=semver,pattern={{version}} |
| 330 | type=semver,pattern={{major}}.{{minor}} |
| 331 | type=semver,pattern=v{{major}} |
| 332 | type=ref,event=tag |
| 333 | type=semver,pattern={{version}},value=${{ needs.resolve.outputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' }} |
| 334 | type=semver,pattern={{major}}.{{minor}},value=${{ needs.resolve.outputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' }} |
| 335 | type=semver,pattern=v{{major}},value=${{ needs.resolve.outputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' }} |
| 336 | type=raw,value=${{ inputs.version }},enable=${{ github.event_name == 'workflow_dispatch' }} |
| 337 | type=raw,value=v${{ inputs.version }},enable=${{ github.event_name == 'workflow_dispatch' }} |
| 338 | type=raw,value=latest |
| 339 | - name: Revalidate release tag before container publish |
| 340 | env: |
| 341 | EXPECTED_SHA: ${{ needs.resolve.outputs.sha }} |
| 342 | TAG: ${{ needs.resolve.outputs.tag }} |
| 343 | run: | |
| 344 | ./infra/scripts/release/verify-remote-tag.sh \ |
| 345 | "https://github.com/${GITHUB_REPOSITORY}.git" \ |
| 346 | "${TAG}" \ |
| 347 | "${EXPECTED_SHA}" |
| 348 | - name: Publish multi-architecture manifest |
| 349 | shell: bash |
| 350 | env: |
| 351 | IMAGE: ${{ steps.image.outputs.name }} |
| 352 | TAGS: ${{ steps.meta.outputs.tags }} |
| 353 | run: | |
| 354 | set -euo pipefail |
| 355 | mapfile -t digest_files < <(find digests -maxdepth 1 -type f -printf '%f\n' | sort) |
| 356 | if [[ "${#digest_files[@]}" -ne 2 ]]; then |
| 357 | echo "Expected exactly two native image digests; found ${#digest_files[@]}." >&2 |
| 358 | exit 1 |
| 359 | fi |
| 360 | |
| 361 | sources=() |
| 362 | for digest in "${digest_files[@]}"; do |
| 363 | if ! [[ "${digest}" =~ ^[0-9a-f]{64}$ ]]; then |
| 364 | echo "Unexpected image digest file: ${digest}" >&2 |
| 365 | exit 1 |
| 366 | fi |
| 367 | sources+=("${IMAGE}@sha256:${digest}") |
| 368 | done |
| 369 | |
| 370 | tag_args=() |
| 371 | while IFS= read -r tag; do |
| 372 | [[ -n "${tag}" ]] && tag_args+=(--tag "${tag}") |
| 373 | done <<< "${TAGS}" |
| 374 | if [[ "${#tag_args[@]}" -eq 0 ]]; then |
| 375 | echo "No container tags were generated." >&2 |
| 376 | exit 1 |
| 377 | fi |
| 378 | |
| 379 | docker buildx imagetools create "${tag_args[@]}" "${sources[@]}" |
| 380 | - name: Verify and smoke published container |
| 381 | shell: bash |
| 382 | env: |
| 383 | IMAGE: ${{ steps.image.outputs.name }}:${{ needs.resolve.outputs.tag }} |
| 384 | run: | |
| 385 | set -euo pipefail |
| 386 | docker buildx imagetools inspect "${IMAGE}" |
| 387 | raw_manifest="$(docker buildx imagetools inspect --raw "${IMAGE}")" |
| 388 | jq -e \ |
| 389 | '[.manifests[] | select(.platform.os == "linux") | "linux/\(.platform.architecture)"] | unique | sort == ["linux/amd64", "linux/arm64"]' \ |
| 390 | <<< "${raw_manifest}" |
| 391 | docker pull "${IMAGE}" |
| 392 | docker run --rm --entrypoint codewhale "${IMAGE}" --version |
| 393 | docker run --rm --entrypoint codew "${IMAGE}" --version |
| 394 | |
| 395 | release: |
| 396 | timeout-minutes: 30 |
| 397 | needs: [artifacts, docker-build, resolve] |
| 398 | if: ${{ !cancelled() && needs.artifacts.result == 'success' && (needs.resolve.outputs.prerelease == 'true' || needs.docker-build.result == 'success') }} |
| 399 | runs-on: ubuntu-24.04 |
| 400 | permissions: |
| 401 | contents: write |
| 402 | steps: |
| 403 | - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 |
| 404 | with: |
| 405 | ref: ${{ needs.resolve.outputs.sha }} |
| 406 | path: repo |
| 407 | - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 |
| 408 | with: |
| 409 | node-version: 22 |
| 410 | package-manager-cache: false |
| 411 | - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8 |
| 412 | with: |
| 413 | name: codewhale-release-assets |
| 414 | path: artifacts |
| 415 | - name: Revalidate exact authoritative asset set |
| 416 | run: node repo/scripts/release/assemble-release-assets.js --verify artifacts |
| 417 | - name: Generate release body from CHANGELOG |
| 418 | shell: bash |
| 419 | run: | |
| 420 | ./repo/scripts/release/generate-release-body.sh \ |
| 421 | "${{ needs.resolve.outputs.tag }}" repo/CHANGELOG.md > release-body.md |
| 422 | - name: Revalidate release tag before GitHub Release write |
| 423 | env: |
| 424 | EXPECTED_SHA: ${{ needs.resolve.outputs.sha }} |
| 425 | TAG: ${{ needs.resolve.outputs.tag }} |
| 426 | run: | |
| 427 | ./repo/scripts/release/verify-remote-tag.sh \ |
| 428 | "https://github.com/${GITHUB_REPOSITORY}.git" \ |
| 429 | "${TAG}" \ |
| 430 | "${EXPECTED_SHA}" |
| 431 | - name: Reconfirm public asset set is still empty |
| 432 | env: |
| 433 | GH_TOKEN: ${{ github.token }} |
| 434 | TAG: ${{ needs.resolve.outputs.tag }} |
| 435 | run: node repo/scripts/release/ensure-release-assets-absent.js "${GITHUB_REPOSITORY}" "${TAG}" |
| 436 | # Upload into a DRAFT: 34 sequential uploads that die halfway must leave |
| 437 | # nothing public (and nothing a rerun's immutability guard refuses). |
| 438 | - uses: softprops/action-gh-release@8a0cd651e5b2365bd640854a3fa5dfc70e4875f3 # v3 |
| 439 | with: |
| 440 | tag_name: ${{ needs.resolve.outputs.tag }} |
| 441 | name: Codewhale ${{ needs.resolve.outputs.tag }} |
| 442 | files: artifacts/* |
| 443 | draft: true |
| 444 | prerelease: ${{ needs.resolve.outputs.prerelease == 'true' }} |
| 445 | body_path: release-body.md |
| 446 | overwrite_files: false |
| 447 | fail_on_unmatched_files: true |
| 448 | - name: Verify the draft's exact asset set, then publish it at once |
| 449 | env: |
| 450 | GH_TOKEN: ${{ github.token }} |
| 451 | TAG: ${{ needs.resolve.outputs.tag }} |
| 452 | run: | |
| 453 | node repo/scripts/release/verify-release-inventory.js \ |
| 454 | --draft --asset-dir artifacts --publish \ |
| 455 | "${GITHUB_REPOSITORY}" "${TAG}" |
| 456 | |
| 457 | # CNB tag pushes start its public binary pipeline, so mirror only after |
| 458 | # the canonical release is complete. Calling the reusable workflow here |
| 459 | # also works when GITHUB_TOKEN publication suppresses release events. |
| 460 | cnb: |
| 461 | needs: [release, resolve] |
| 462 | if: ${{ !cancelled() && needs.release.result == 'success' && needs.resolve.outputs.prerelease != 'true' }} |
| 463 | uses: ./.github/workflows/sync-cnb.yml |
| 464 | with: |
| 465 | release_tag: ${{ needs.resolve.outputs.tag }} |
| 466 | source_sha: ${{ needs.resolve.outputs.sha }} |
| 467 | secrets: |
| 468 | CNB_GIT_TOKEN: ${{ secrets.CNB_GIT_TOKEN }} |
| 469 | |
| 470 | gitcode: |
| 471 | needs: [release, resolve] |
| 472 | if: ${{ !cancelled() && needs.release.result == 'success' && vars.GITCODE_MIRROR == 'enabled' && needs.resolve.outputs.prerelease != 'true' }} |
| 473 | uses: ./.github/workflows/sync-gitcode.yml |
| 474 | with: |
| 475 | release_tag: ${{ needs.resolve.outputs.tag }} |
| 476 | source_sha: ${{ needs.resolve.outputs.sha }} |
| 477 | secrets: |
| 478 | GITCODE_TOKEN: ${{ secrets.GITCODE_TOKEN }} |
| 479 | |
| 480 | npm: |
| 481 | timeout-minutes: 20 |
| 482 | needs: [release, resolve] |
| 483 | if: ${{ !cancelled() && needs.release.result == 'success' }} |
| 484 | runs-on: ubuntu-24.04 |
| 485 | permissions: |
| 486 | contents: read |
| 487 | id-token: write |
| 488 | steps: |
| 489 | - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 |
| 490 | with: |
| 491 | ref: ${{ needs.resolve.outputs.sha }} |
| 492 | fetch-depth: 0 |
| 493 | - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 |
| 494 | with: |
| 495 | node-version: 24 |
| 496 | registry-url: https://registry.npmjs.org |
| 497 | package-manager-cache: false |
| 498 | - name: Pin OIDC-capable npm CLI |
| 499 | run: npm install --global npm@12.0.2 |
| 500 | - name: Revalidate release tag before npm publish |
| 501 | env: |
| 502 | EXPECTED_SHA: ${{ needs.resolve.outputs.sha }} |
| 503 | TAG: ${{ needs.resolve.outputs.tag }} |
| 504 | run: | |
| 505 | ./scripts/release/verify-remote-tag.sh \ |
| 506 | "https://github.com/${GITHUB_REPOSITORY}.git" \ |
| 507 | "${TAG}" \ |
| 508 | "${EXPECTED_SHA}" |
| 509 | - name: Revalidate public release assets |
| 510 | env: |
| 511 | GH_TOKEN: ${{ github.token }} |
| 512 | run: ./scripts/release/verify-release-assets.sh "${{ needs.resolve.outputs.version }}" |
| 513 | - name: Test npm wrapper |
| 514 | working-directory: npm/codewhale |
| 515 | run: npm test |
| 516 | - name: Publish npm wrapper with trusted publishing |
| 517 | working-directory: npm/codewhale |
| 518 | env: |
| 519 | # npm runs prepublishOnly in this step; that guard revalidates the |
| 520 | # public GitHub Release and therefore needs the same read token as |
| 521 | # the explicit asset gate above. |
| 522 | GH_TOKEN: ${{ github.token }} |
| 523 | PRERELEASE: ${{ needs.resolve.outputs.prerelease }} |
| 524 | run: | |
| 525 | set -euo pipefail |
| 526 | if [[ "${PRERELEASE}" == "true" ]]; then |
| 527 | npm publish --access public --tag next |
| 528 | else |
| 529 | npm publish --access public |
| 530 | fi |
| 531 | |
| 532 | crates: |
| 533 | timeout-minutes: 360 |
| 534 | needs: [npm, release, resolve] |
| 535 | if: ${{ !cancelled() && needs.release.result == 'success' && needs.npm.result == 'success' && needs.resolve.outputs.prerelease != 'true' && github.repository == 'codewhale-hq/Codewhale' && github.ref == format('refs/tags/{0}', needs.resolve.outputs.tag) }} |
| 536 | runs-on: ubuntu-24.04 |
| 537 | environment: release |
| 538 | concurrency: |
| 539 | group: crates-io-${{ needs.resolve.outputs.tag }} |
| 540 | cancel-in-progress: false |
| 541 | permissions: |
| 542 | contents: read |
| 543 | env: |
| 544 | RUSTFLAGS: '' |
| 545 | steps: |
| 546 | - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 |
| 547 | with: |
| 548 | ref: ${{ needs.resolve.outputs.sha }} |
| 549 | fetch-depth: 0 |
| 550 | persist-credentials: false |
| 551 | - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 |
| 552 | with: |
| 553 | node-version: 22 |
| 554 | package-manager-cache: false |
| 555 | # No rust-cache or sccache: a shared cache must not feed builds in the job that holds the registry token. |
| 556 | - uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # master 2026-07-18 |
| 557 | with: |
| 558 | toolchain: 1.100.0 |
| 559 | - name: Install Linux system dependencies |
| 560 | run: | |
| 561 | for i in 1 2 3 4 5; do |
| 562 | sudo apt-get update && break |
| 563 | echo "apt-get update failed (attempt $i); retrying in 15s" |
| 564 | sleep 15 |
| 565 | done |
| 566 | sudo apt-get install -y libdbus-1-dev pkg-config |
| 567 | - name: Ubuntu build headroom |
| 568 | shell: bash |
| 569 | run: bash scripts/ci/prepare-ubuntu-build-headroom.sh |
| 570 | - name: Require the clean release tag checkout before crates.io publish |
| 571 | env: |
| 572 | VERSION: ${{ needs.resolve.outputs.version }} |
| 573 | run: ./scripts/release/require-release-tag-checkout.sh "${VERSION}" |
| 574 | - name: Publish crates to crates.io |
| 575 | env: |
| 576 | CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} |
| 577 | GH_TOKEN: ${{ github.token }} |
| 578 | run: | |
| 579 | set -euo pipefail |
| 580 | if [[ -z "${CARGO_REGISTRY_TOKEN:-}" ]]; then |
| 581 | echo "::error::Secret CARGO_REGISTRY_TOKEN is not set in the 'release' environment. Store a crates.io publish token there and re-run this job, or publish with the manual fallback in docs/RELEASE_RUNBOOK.md (Rust Crates Release, step 5)." >&2 |
| 582 | exit 1 |
| 583 | fi |
| 584 | root="${RUNNER_TEMP}/crates-publish" |
| 585 | mkdir "${root}" |
| 586 | CARGO_HOME="${root}/cargo-home" CARGO_TARGET_DIR="${root}/target" \ |
| 587 | ./scripts/release/publish-crates.sh publish |
| 588 | - name: Verify crates.io and npm serve the release |
| 589 | env: |
| 590 | VERSION: ${{ needs.resolve.outputs.version }} |
| 591 | run: ./scripts/release/check-published.sh "${VERSION}" |
| 592 | |
| 593 | homebrew: |
| 594 | timeout-minutes: 20 |
| 595 | needs: [release, resolve] |
| 596 | if: ${{ !cancelled() && needs.release.result == 'success' && needs.resolve.outputs.prerelease != 'true' }} |
| 597 | runs-on: ubuntu-24.04 |
| 598 | permissions: |
| 599 | contents: read |
| 600 | steps: |
| 601 | - name: Check Homebrew tap token |
| 602 | # A real release must update the tap. Skipping silently (the old |
| 603 | # behaviour) left `brew install codewhale` on the previous version |
| 604 | # with a green release run; fail loudly like release-republish.yml. |
| 605 | env: |
| 606 | TOKEN: ${{ secrets.HOMEBREW_TAP_PAT || secrets.RELEASE_TAG_PAT }} |
| 607 | run: | |
| 608 | if [[ -z "${TOKEN:-}" ]]; then |
| 609 | echo "::error::No Homebrew tap token configured (HOMEBREW_TAP_PAT or RELEASE_TAG_PAT); cannot update the tap for this release." >&2 |
| 610 | exit 1 |
| 611 | fi |
| 612 | - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 |
| 613 | with: |
| 614 | ref: ${{ needs.resolve.outputs.sha }} |
| 615 | - name: Download checksum manifest |
| 616 | env: |
| 617 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 618 | run: | |
| 619 | gh release download "${{ needs.resolve.outputs.tag }}" \ |
| 620 | --repo "${{ github.repository }}" \ |
| 621 | --pattern 'codewhale-artifacts-sha256.txt' \ |
| 622 | --dir /tmp |
| 623 | - name: Revalidate release tag before Homebrew tap write |
| 624 | env: |
| 625 | EXPECTED_SHA: ${{ needs.resolve.outputs.sha }} |
| 626 | TAG: ${{ needs.resolve.outputs.tag }} |
| 627 | run: | |
| 628 | ./scripts/release/verify-remote-tag.sh \ |
| 629 | "https://github.com/${GITHUB_REPOSITORY}.git" \ |
| 630 | "${TAG}" \ |
| 631 | "${EXPECTED_SHA}" |
| 632 | - name: Update Homebrew tap |
| 633 | env: |
| 634 | TAG: ${{ needs.resolve.outputs.tag }} |
| 635 | MANIFEST: /tmp/codewhale-artifacts-sha256.txt |
| 636 | TAP_REPO: Hmbown/homebrew-deepseek-tui |
| 637 | TOKEN: ${{ secrets.HOMEBREW_TAP_PAT || secrets.RELEASE_TAG_PAT }} |
| 638 | run: bash .github/scripts/update-homebrew-tap.sh |
| 639 | |
| 640 | # Every publish used to turn Web Frontend red: `check:latest-release` |
| 641 | # compares the checked-in release record with GitHub's latest release, and |
| 642 | # nothing wrote the record, so someone hand-committed it after each release. |
| 643 | # This job writes the record, proves it against the web gates, and proposes |
| 644 | # it to main as a bot PR. It never pushes to the default branch: the ruleset |
| 645 | # requires a PR there. While the PR is open (up to 24h after publish, and |
| 646 | # only when the record is exactly one release behind), `check:latest-release` |
| 647 | # warns instead of failing on every event (see web/scripts/sync-latest-release.mjs). |
| 648 | # |
| 649 | # Known limit: repo settings stop GITHUB_TOKEN from opening PRs, so the PR is |
| 650 | # opened with RELEASE_TAG_PAT. Without it the job pushes the branch and fails |
| 651 | # with the compare link, which is still one click instead of a hand commit. |
| 652 | sync-release-record: |
| 653 | timeout-minutes: 15 |
| 654 | needs: [release, resolve] |
| 655 | if: ${{ !cancelled() && needs.release.result == 'success' && needs.resolve.outputs.prerelease != 'true' }} |
| 656 | runs-on: ubuntu-24.04 |
| 657 | permissions: |
| 658 | contents: write |
| 659 | steps: |
| 660 | - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 |
| 661 | with: |
| 662 | ref: ${{ github.event.repository.default_branch }} |
| 663 | # derive-facts.mjs dates model ids from git history (web.yml pins 0 |
| 664 | # for the same reason); a shallow clone rewrites every addedAt. |
| 665 | fetch-depth: 0 |
| 666 | - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 |
| 667 | with: |
| 668 | node-version: 22 |
| 669 | package-manager-cache: false |
| 670 | - name: Refresh the release record from the published release |
| 671 | env: |
| 672 | GITHUB_TOKEN: ${{ github.token }} |
| 673 | run: | |
| 674 | set -euo pipefail |
| 675 | node web/scripts/sync-latest-release.mjs |
| 676 | node web/scripts/derive-facts.mjs |
| 677 | node web/scripts/derive-release-docs.mjs |
| 678 | - name: Prove the record passes the web fact gates |
| 679 | env: |
| 680 | GITHUB_TOKEN: ${{ github.token }} |
| 681 | run: | |
| 682 | set -euo pipefail |
| 683 | node web/scripts/sync-latest-release.mjs --check |
| 684 | node web/scripts/check-cloud-facts.mjs |
| 685 | node web/scripts/check-facts.mjs |
| 686 | node web/scripts/check-release-docs.mjs |
| 687 | - name: Propose the record to the default branch |
| 688 | env: |
| 689 | TAG: ${{ needs.resolve.outputs.tag }} |
| 690 | DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} |
| 691 | PR_TOKEN: ${{ secrets.RELEASE_TAG_PAT }} |
| 692 | run: | |
| 693 | set -euo pipefail |
| 694 | paths=( |
| 695 | web/data/latest-published-release.json |
| 696 | web/data/release-baseline.json |
| 697 | docs/public-surface-facts.json |
| 698 | docs/cloud-facts/stable.json |
| 699 | web/lib/facts.generated.ts |
| 700 | web/data/agent-docs.release.json |
| 701 | web/data/agent-docs.release-index.json |
| 702 | web/data/features.generated.json |
| 703 | ) |
| 704 | if git diff --quiet -- "${paths[@]}"; then |
| 705 | echo "Release record already current on ${DEFAULT_BRANCH}; nothing to propose." |
| 706 | exit 0 |
| 707 | fi |
| 708 | # GitHub's latest may already be newer than this run's tag; the |
| 709 | # record always follows GitHub, so name the branch after what it says. |
| 710 | recorded="$(node -p "require('./web/data/latest-published-release.json').tag")" |
| 711 | branch="chore/release-record-${recorded}" |
| 712 | title="chore(web): record ${recorded} as the published release" |
| 713 | |
| 714 | git config user.name "CodeWhale Bot" |
| 715 | git config user.email "bot@codewhale.net" |
| 716 | git switch --quiet -c "${branch}" |
| 717 | git add -- "${paths[@]}" |
| 718 | git commit --quiet \ |
| 719 | -m "${title}" \ |
| 720 | -m "Written by release.yml sync-release-record after ${TAG} published. Gates run in the job: sync-latest-release --check, check-cloud-facts, check-facts." |
| 721 | git show --stat --format='%h %s' HEAD |
| 722 | |
| 723 | if git ls-remote --exit-code --heads origin "${branch}" >/dev/null; then |
| 724 | echo "::notice title=Release record already proposed::Branch ${branch} exists; leaving it for review." |
| 725 | exit 0 |
| 726 | fi |
| 727 | git push origin "HEAD:refs/heads/${branch}" |
| 728 | |
| 729 | compare="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/compare/${DEFAULT_BRANCH}...${branch}?expand=1" |
| 730 | if [[ -n "${PR_TOKEN}" ]] && GH_TOKEN="${PR_TOKEN}" gh pr create \ |
| 731 | --repo "${GITHUB_REPOSITORY}" --base "${DEFAULT_BRANCH}" --head "${branch}" \ |
| 732 | --title "${title}" \ |
| 733 | --body "Written by release.yml \`sync-release-record\` after ${TAG} published. Merging it turns \`check:latest-release\` green on ${DEFAULT_BRANCH}. No-Issue: release automation."; then |
| 734 | echo "::notice title=Release record proposed::Opened a PR from ${branch}." |
| 735 | exit 0 |
| 736 | fi |
| 737 | echo "::error title=Release record PR not opened::Branch ${branch} is pushed; open and merge it: ${compare}" |
| 738 | exit 1 |
| 739 | |
| 740 | web_deploy: |
| 741 | name: Deploy website |
| 742 | timeout-minutes: 45 |
| 743 | needs: [npm, release, resolve] |
| 744 | if: ${{ !cancelled() && needs.release.result == 'success' && needs.npm.result == 'success' && needs.resolve.outputs.prerelease != 'true' && github.repository == 'codewhale-hq/Codewhale' && github.ref == format('refs/tags/{0}', needs.resolve.outputs.tag) }} |
| 745 | runs-on: ubuntu-24.04 |
| 746 | concurrency: |
| 747 | group: release-web-deploy-${{ needs.resolve.outputs.tag }} |
| 748 | cancel-in-progress: false |
| 749 | permissions: |
| 750 | actions: write |
| 751 | contents: read |
| 752 | steps: |
| 753 | - name: Dispatch web.yml on main and wait for deploy |
| 754 | shell: bash |
| 755 | env: |
| 756 | GH_TOKEN: ${{ github.token }} |
| 757 | RELEASE_SHA: ${{ needs.resolve.outputs.sha }} |
| 758 | run: | |
| 759 | set -euo pipefail |
| 760 | main_sha="$(gh api "repos/${GITHUB_REPOSITORY}/commits/main" --jq .sha)" |
| 761 | if [[ "${#main_sha}" -ne 40 || "${main_sha}" =~ [^0-9a-f] ]]; then |
| 762 | echo "::error::Could not resolve main to a 40-character commit SHA, got '${main_sha}'." >&2 |
| 763 | exit 1 |
| 764 | fi |
| 765 | relation="$(gh api "repos/${GITHUB_REPOSITORY}/compare/${RELEASE_SHA}...${main_sha}" --jq .status)" |
| 766 | if [[ "${relation}" != "identical" && "${relation}" != "ahead" ]]; then |
| 767 | echo "::error::main (${main_sha}) does not contain release commit ${RELEASE_SHA} (compare status: ${relation})." >&2 |
| 768 | exit 1 |
| 769 | fi |
| 770 | |
| 771 | before_id="$(gh api "repos/${GITHUB_REPOSITORY}/actions/workflows/web.yml/runs?event=workflow_dispatch&per_page=1" --jq '.workflow_runs[0].id // 0')" |
| 772 | if ! [[ "${before_id}" =~ ^[0-9]+$ ]]; then |
| 773 | echo "::error::Unexpected workflow run id '${before_id}' before dispatch." >&2 |
| 774 | exit 1 |
| 775 | fi |
| 776 | |
| 777 | gh workflow run web.yml --repo "${GITHUB_REPOSITORY}" --ref main -f expected_sha="${main_sha}" |
| 778 | |
| 779 | run_id="" |
| 780 | run_url="" |
| 781 | for _ in $(seq 1 24); do |
| 782 | sleep 5 |
| 783 | matched="$(gh api "repos/${GITHUB_REPOSITORY}/actions/workflows/web.yml/runs?event=workflow_dispatch&branch=main&per_page=20" \ |
| 784 | --jq ".workflow_runs | map(select(.id > ${before_id} and .event == \"workflow_dispatch\" and .head_branch == \"main\" and .head_sha == \"${main_sha}\" and .path == \".github/workflows/web.yml\")) | sort_by(.id) | .[0] | select(. != null) | [.id, .html_url] | @tsv")" |
| 785 | if [[ -n "${matched}" ]]; then |
| 786 | IFS=$'\t' read -r run_id run_url <<< "${matched}" |
| 787 | break |
| 788 | fi |
| 789 | done |
| 790 | if [[ -z "${run_id}" || ! "${run_id}" =~ ^[0-9]+$ ]]; then |
| 791 | echo "::error::Timed out waiting for dispatched web.yml run for main (${main_sha}) to appear." >&2 |
| 792 | exit 1 |
| 793 | fi |
| 794 | echo "Watching dispatched web.yml run for ${main_sha}: ${run_url}" |
| 795 | |
| 796 | completed=false |
| 797 | conclusion="" |
| 798 | for _ in $(seq 1 140); do |
| 799 | state="$(gh api "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}" --jq '[.status, (.conclusion // "")] | @tsv')" |
| 800 | IFS=$'\t' read -r status conclusion <<< "${state}" |
| 801 | if [[ "${status}" == "completed" ]]; then |
| 802 | completed=true |
| 803 | break |
| 804 | fi |
| 805 | sleep 15 |
| 806 | done |
| 807 | if [[ "${completed}" != "true" ]]; then |
| 808 | echo "::error::Timed out after 35m waiting for web.yml run ${run_url} to complete." >&2 |
| 809 | exit 1 |
| 810 | fi |
| 811 | if [[ "${conclusion}" != "success" ]]; then |
| 812 | echo "::error::Dispatched web.yml run ${run_url} finished with conclusion='${conclusion}'." >&2 |
| 813 | exit 1 |
| 814 | fi |
| 815 | |
| 816 | jobs_verdict='if (.jobs | length) != .total_count then "incomplete job list" |
| 817 | elif (any(.jobs[]; .name == "Lint & Type Check" and .conclusion == "success") and any(.jobs[]; .name == "Deploy to Cloudflare" and .conclusion == "success")) | not then "deploy job did not succeed" |
| 818 | else "ok" |
| 819 | end' |
| 820 | verdict="$(gh api "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}/jobs?filter=latest&per_page=100" --jq "${jobs_verdict}")" |
| 821 | if [[ "${verdict}" != "ok" ]]; then |
| 822 | echo "::error::Web Frontend run ${run_url} did not complete both Lint & Type Check and Deploy to Cloudflare (${verdict})." >&2 |
| 823 | exit 1 |
| 824 | fi |
| 825 | |
| 826 | - name: Verify live site names the released version |
| 827 | shell: bash |
| 828 | env: |
| 829 | VERSION: ${{ needs.resolve.outputs.version }} |
| 830 | run: | |
| 831 | set -euo pipefail |
| 832 | expected="Version ${VERSION} is released" |
| 833 | page="" |
| 834 | for attempt in $(seq 1 24); do |
| 835 | if page="$(curl -fsSL --max-time 15 -H 'User-Agent: codewhale-release-verify' https://codewhale.net/en 2>/dev/null)" \ |
| 836 | && grep -Fq "${expected}" <<< "${page}"; then |
| 837 | echo "Verified https://codewhale.net/en prints '${expected}' (attempt ${attempt})." | tee -a "${GITHUB_STEP_SUMMARY}" |
| 838 | exit 0 |
| 839 | fi |
| 840 | if [[ "${attempt}" -lt 24 ]]; then |
| 841 | sleep 5 |
| 842 | fi |
| 843 | done |
| 844 | observed="$(grep -Eo 'Version [0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)? is released' <<< "${page}" | head -n1 || true)" |
| 845 | echo "::error::https://codewhale.net/en did not print '${expected}' within 120s after deploy (observed: '${observed:-none}')." >&2 |
| 846 | exit 1 |
| 847 |