diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8823a5174a..4235ba4758 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -9,13 +9,12 @@ defaults: on: push: - tags: - # Stable tags are created only by a merged, reviewed release PR. Direct - # tag pushes are reserved for prerelease channels. - - "v*-*" - pull_request: - types: [closed] + # A stable release publishes from the push that merges its reviewed release PR into main. branches: [main] + tags: + # Stable tags are created only by the publish job. Direct tag pushes are reserved for + # prerelease channels. + - "v*-*" env: # Every package a release publishes, in publish order. The CLI is packed from @@ -26,10 +25,6 @@ env: @hyperframes/player @hyperframes/producer @hyperframes/shader-transitions @hyperframes/studio @hyperframes/aws-lambda @hyperframes/gcp-cloud-run hyperframes -concurrency: - group: publish-${{ github.event.pull_request.head.ref || github.ref }} - cancel-in-progress: false - jobs: release-source: name: Check the release commit @@ -37,15 +32,17 @@ jobs: timeout-minutes: 5 permissions: contents: read - if: >- - github.event_name == 'push' || - (github.event.pull_request.merged == true && - startsWith(github.event.pull_request.head.ref, 'release/v')) + pull-requests: read + outputs: + sha: ${{ steps.source.outputs.sha }} + version: ${{ steps.source.outputs.version }} + source: ${{ steps.source.outputs.source }} + ref: ${{ steps.source.outputs.ref }} steps: # A prerelease tag can name any commit; every job after this builds what it names. Alphas are cut from main, # next or alpha (release-channels.mdx), so the tagged commit must already be on one of them. - name: Check the tagged commit is on main, next or alpha - if: github.event_name == 'push' + if: github.ref_type == 'tag' env: GH_TOKEN: ${{ github.token }} REPO: ${{ github.repository }} @@ -59,6 +56,67 @@ jobs: echo "::error::the tagged commit $TAGGED is not an ancestor of main, next or alpha, so it does not publish" exit 1 + # Every later job reads the release from these outputs. A push to main that merges no release PR leaves them + # empty, so nothing after this job runs. + - name: Find the release this push publishes + id: source + env: + GH_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + SHA: ${{ github.sha }} + REF_TYPE: ${{ github.ref_type }} + REF_NAME: ${{ github.ref_name }} + HEAD_MESSAGE: ${{ github.event.head_commit.message }} + run: | + if [ "$REF_TYPE" = "tag" ]; then + { + echo "sha=$SHA" + echo "version=${REF_NAME#v}" + echo "source=tag" + echo "ref=$REF_NAME" + } >> "$GITHUB_OUTPUT" + exit 0 + fi + gh api "repos/$REPO/commits/$SHA/pulls" > "$RUNNER_TEMP/pulls.json" + heads="$(jq -r --arg sha "$SHA" --arg repo "$REPO" '.[] + | select(.merged_at != null and .base.ref == "main" and .merge_commit_sha == $sha) + | select(.head.repo.full_name == $repo) + | select(.head.ref | test("^release/v[0-9]+[.][0-9]+[.][0-9]+$")) + | [.head.ref, .number, .head.sha, .user.login] | @tsv' "$RUNNER_TEMP/pulls.json")" + if [ -z "$heads" ]; then + # A release commit GitHub has not linked to its PR yet must fail, where a rerun recovers it, not skip. + if [[ "${HEAD_MESSAGE%%$'\n'*}" =~ ^chore:\ release\ v[0-9] ]]; then + echo "::error::$SHA reads as a release commit but merges no release PR from this repo; rerun once GitHub lists it" + exit 1 + fi + echo "$SHA merges no release PR; nothing to publish" + exit 0 + fi + if [ "$(wc -l <<<"$heads")" -ne 1 ]; then + echo "::error::$SHA is the merge of more than one release PR: $(cut -f1 <<<"$heads" | tr '\n' ' ')" + exit 1 + fi + IFS=$'\t' read -r ref number head author <<<"$heads" + # Branch protection can be bypassed, so the release itself requires a person other than its author to have + # approved its final commit, with no change request from anyone still standing. Each latest verdict counts. + gh api --paginate "repos/$REPO/pulls/$number/reviews" > "$RUNNER_TEMP/reviews.json" + reviewed="$(jq -s -r --arg head "$head" --arg author "$author" 'add + | map(select(.user.login != $author and (.state == "APPROVED" or .state == "CHANGES_REQUESTED"))) + | group_by(.user.login) | map(max_by(.submitted_at)) + | any(.state == "APPROVED" and .commit_id == $head and .user.type == "User") + and all(.state != "CHANGES_REQUESTED")' \ + "$RUNNER_TEMP/reviews.json")" + if [ "$reviewed" != "true" ]; then + echo "::error::$ref (#$number) has no approval of its final commit by someone else, or a change request stands" + exit 1 + fi + { + echo "sha=$SHA" + echo "version=${ref#release/v}" + echo "source=release-pr" + echo "ref=$ref" + } >> "$GITHUB_OUTPUT" + lambda-arm64-ffmpeg: name: Lambda arm64 ffmpeg needs: [release-source] @@ -68,14 +126,8 @@ jobs: permissions: contents: read env: - EXPECTED_RELEASE_SHA: >- - ${{ github.event_name == 'pull_request' - && github.event.pull_request.merge_commit_sha - || github.sha }} - if: >- - github.event_name == 'push' || - (github.event.pull_request.merged == true && - startsWith(github.event.pull_request.head.ref, 'release/v')) + EXPECTED_RELEASE_SHA: ${{ needs.release-source.outputs.sha }} + if: needs.release-source.outputs.sha != '' steps: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 with: @@ -110,14 +162,8 @@ jobs: permissions: contents: read env: - EXPECTED_RELEASE_SHA: >- - ${{ github.event_name == 'pull_request' - && github.event.pull_request.merge_commit_sha - || github.sha }} - if: >- - github.event_name == 'push' || - (github.event.pull_request.merged == true && - startsWith(github.event.pull_request.head.ref, 'release/v')) + EXPECTED_RELEASE_SHA: ${{ needs.release-source.outputs.sha }} + if: needs.release-source.outputs.sha != '' outputs: sha256: ${{ steps.zip.outputs.sha256 }} steps: @@ -158,7 +204,7 @@ jobs: name: Build and pack outputs: bundle_id: ${{ steps.previous_bundle.outputs.artifact || steps.bundle.outputs.artifact-id }} - needs: [lambda-arm64-ffmpeg, lambda-handler-zip] + needs: [release-source, lambda-arm64-ffmpeg, lambda-handler-zip] runs-on: ubuntu-latest timeout-minutes: 30 # Every build and lifecycle script of the release commit runs here, with a @@ -167,21 +213,14 @@ jobs: contents: read actions: read env: - EXPECTED_RELEASE_SHA: >- - ${{ github.event_name == 'pull_request' - && github.event.pull_request.merge_commit_sha - || github.sha }} - if: >- - github.event_name == 'push' || - (github.event.pull_request.merged == true && - startsWith(github.event.pull_request.head.ref, 'release/v')) + EXPECTED_RELEASE_SHA: ${{ needs.release-source.outputs.sha }} + if: needs.release-source.outputs.sha != '' steps: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 with: fetch-depth: 0 - # Pin every release to an immutable ref. In particular, a merged - # release PR event exposes main as github.ref, which may advance - # before this job starts; use the event's exact merge commit instead. + # Pin every release to an immutable ref: main may advance before this job starts, so check out + # the exact commit release-source found. ref: ${{ env.EXPECTED_RELEASE_SHA }} persist-credentials: false @@ -217,15 +256,8 @@ jobs: if: steps.previous_bundle.outputs.artifact == '' id: version env: - EVENT_NAME: ${{ github.event_name }} - PR_HEAD_REF: ${{ github.event.pull_request.head.ref }} + VERSION: ${{ needs.release-source.outputs.version }} run: | - if [ "$EVENT_NAME" = "push" ]; then - VERSION="${GITHUB_REF_NAME#v}" - else - BRANCH="${PR_HEAD_REF}" - VERSION="${BRANCH#release/v}" - fi echo "version=${VERSION}" >> "$GITHUB_OUTPUT" # Detect pre-release tag (e.g. 0.1.16-alpha.1 → alpha, 0.1.16-beta.2 → beta) @@ -244,8 +276,8 @@ jobs: env: VERSION: ${{ steps.version.outputs.version }} DIST_TAG: ${{ steps.version.outputs.dist_tag }} - EVENT_NAME: ${{ github.event_name }} - PR_HEAD_REF: ${{ github.event.pull_request.head.ref }} + SOURCE: ${{ needs.release-source.outputs.source }} + RELEASE_REF: ${{ needs.release-source.outputs.ref }} run: node scripts/validate-release-channel.mjs # The release installs the bun it downloads, never one restored from the shared cache. @@ -363,9 +395,13 @@ jobs: publish: name: Publish - needs: [pack] + needs: [release-source, pack] runs-on: ubuntu-latest timeout-minutes: 30 + # Per release, not per ref: on main a later push would cancel a release run still waiting to start. + concurrency: + group: publish-${{ needs.release-source.outputs.version }} + cancel-in-progress: false # npm's trusted publishers name this environment, so every trigger uses it. It has no approval step: # stable releases come from reviewed release PRs, and only repository admins may push v*-* tags. environment: npm-publish @@ -377,16 +413,10 @@ jobs: actions: read id-token: write env: - EXPECTED_RELEASE_SHA: >- - ${{ github.event_name == 'pull_request' - && github.event.pull_request.merge_commit_sha - || github.sha }} - # Stable releases come only from reviewed release PRs. Tag pushes are + EXPECTED_RELEASE_SHA: ${{ needs.release-source.outputs.sha }} + # Stable releases come only from the merge of a reviewed release PR. Tag pushes are # prerelease-only because the trigger pattern requires a hyphenated version. - if: >- - github.event_name == 'push' || - (github.event.pull_request.merged == true && - startsWith(github.event.pull_request.head.ref, 'release/v')) + if: needs.release-source.outputs.sha != '' steps: # Only git reads this checkout, for the release tag. - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 @@ -406,19 +436,13 @@ jobs: exit 1 fi - # Resolved again from the event: the pack job ran release-commit code, so its outputs are not trusted here. + # Read from release-source, which runs no release-commit code: the pack job did, so its outputs are not + # trusted here. - name: Resolve version id: version env: - EVENT_NAME: ${{ github.event_name }} - PR_HEAD_REF: ${{ github.event.pull_request.head.ref }} + VERSION: ${{ needs.release-source.outputs.version }} run: | - if [ "$EVENT_NAME" = "push" ]; then - VERSION="${GITHUB_REF_NAME#v}" - else - BRANCH="${PR_HEAD_REF}" - VERSION="${BRANCH#release/v}" - fi echo "version=${VERSION}" >> "$GITHUB_OUTPUT" # Detect pre-release tag (e.g. 0.1.16-alpha.1 → alpha, 0.1.16-beta.2 → beta) @@ -436,7 +460,7 @@ jobs: # hold even when the release commit changes that script. - name: Check release channel env: - EVENT_NAME: ${{ github.event_name }} + SOURCE: ${{ needs.release-source.outputs.source }} VERSION: ${{ steps.version.outputs.version }} PRERELEASE: ${{ steps.version.outputs.prerelease }} DIST_TAG: ${{ steps.version.outputs.dist_tag }} @@ -445,11 +469,15 @@ jobs: echo "::error::Invalid release version \"$VERSION\". Expected x.y.z or x.y.z-channel.N." exit 1 fi - if [ "$EVENT_NAME" = "push" ] && [ "$PRERELEASE" != "true" ]; then + if [ "$SOURCE" != "tag" ] && [ "$SOURCE" != "release-pr" ]; then + echo "::error::Unknown release source \"$SOURCE\"." + exit 1 + fi + if [ "$SOURCE" = "tag" ] && [ "$PRERELEASE" != "true" ]; then echo "::error::Tag pushes publish prereleases only; v$VERSION is a stable version." exit 1 fi - if [ "$EVENT_NAME" = "pull_request" ] && [ "$PRERELEASE" != "false" ]; then + if [ "$SOURCE" = "release-pr" ] && [ "$PRERELEASE" != "false" ]; then echo "::error::Merged release PRs publish stable releases only; v$VERSION is a prerelease." exit 1 fi @@ -580,7 +608,7 @@ jobs: done < publish-order.tsv - name: Create release tag - if: github.event_name == 'pull_request' + if: needs.release-source.outputs.source == 'release-pr' env: VERSION: ${{ steps.version.outputs.version }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/docs/contributing/changelog-process.mdx b/docs/contributing/changelog-process.mdx index 8c84fc262a..5d79229ad6 100644 --- a/docs/contributing/changelog-process.mdx +++ b/docs/contributing/changelog-process.mdx @@ -59,7 +59,7 @@ The docs changelog lives in `docs/changelog.mdx` and uses Mintlify `` en Push the `release/v0.6.53` branch without its local tag, open a PR to `main`, and merge it after approval and CI. The publish workflow pins its checkout to the exact merge SHA, verifies that SHA, creates `v0.6.53`, and uses `releases/v0.6.53.md` as the GitHub Release body. If no reviewed release file is present, it falls back to GitHub-generated notes. - To recover a failed publish, rerun the original merged-PR workflow. Do not push the stable tag or use a manual dispatch; those paths are intentionally disabled so recovery cannot publish a different commit. + To recover a failed publish, rerun the failed jobs of the publish run on the release PR's merge into `main`. Do not push the stable tag or use a manual dispatch; those paths are intentionally disabled so recovery cannot publish a different commit. Retries reuse the original run's immutable `release-bundle` artifact, including the npm tarballs and Lambda assets. The publish job stores the release ID, source commit, run ID, and Lambda digests in a separate `lambda-release-receipt` artifact before uploading assets. It accepts an existing release only when that receipt matches, and skips an existing asset only when its digest matches the original bundle. Partially uploaded asset pairs can resume from those original bytes. An existing npm version with different contents fails even on a retry. diff --git a/scripts/publish-workflow.test.mjs b/scripts/publish-workflow.test.mjs index c497ef5285..b814ac6c95 100644 --- a/scripts/publish-workflow.test.mjs +++ b/scripts/publish-workflow.test.mjs @@ -47,19 +47,168 @@ function runCreateReleaseTag(cwd, version) { } test("stable publishing has one reviewed immutable event path", () => { - assert.deepEqual(config.on.push.tags, ["v*-*"]); - assert.equal(config.on.workflow_dispatch, undefined); - assert.equal( - normalizeExpression(publish.if), - "github.event_name == 'push' || (github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/v'))", - ); - assert.equal( - normalizeExpression(publish.env.EXPECTED_RELEASE_SHA), - "${{ github.event_name == 'pull_request' && github.event.pull_request.merge_commit_sha || github.sha }}", - ); + // fails without the fix: a merged release PR's event ran as refs/pull/N/merge, a ref the publish environment refuses. + assert.deepEqual(config.on, { push: { branches: ["main"], tags: ["v*-*"] } }); + for (const name of ["lambda-arm64-ffmpeg", "lambda-handler-zip", "pack", "publish"]) { + const job = config.jobs[name]; + assert.ok(job.needs.includes("release-source"), `${name} needs release-source`); + assert.equal(normalizeExpression(job.if), "needs.release-source.outputs.sha != ''", name); + assert.equal(job.env.EXPECTED_RELEASE_SHA, "${{ needs.release-source.outputs.sha }}", name); + } assert.equal(checkout.with.ref, "${{ env.EXPECTED_RELEASE_SHA }}"); }); +test("a release run waits behind another run of the same release, never behind main", () => { + // A ref-wide group on main lets any later push cancel a release run that is still pending. + assert.equal(config.concurrency, undefined); + assert.deepEqual(publish.concurrency, { + group: "publish-${{ needs.release-source.outputs.version }}", + "cancel-in-progress": false, + }); +}); + +test("a push to main publishes only the merge of exactly one approved release PR from this repo", () => { + const step = stepOf(config.jobs["release-source"], "Find the release this push publishes"); + const bin = mkdtempSync(join(tmpdir(), "hyperframes-fake-gh-")); + const sha = "a".repeat(40); + const head = "c".repeat(40); + const pull = (overrides = {}) => ({ + number: 8000, + user: { login: "releaser" }, + merged_at: "2026-11-17T02:24:00Z", + merge_commit_sha: sha, + base: { ref: "main" }, + head: { ref: "release/v0.9.61", sha: head, repo: { full_name: "heygen-com/hyperframes" } }, + ...overrides, + }); + const review = (login, state, hour, commit = head, type = "User") => ({ + user: { login, type }, + state, + commit_id: commit, + submitted_at: `2026-11-17T0${hour}:00:00Z`, + }); + const approved = [review("reviewer", "APPROVED", 1)]; + // The fake answers PR 8000's reviews from FAKE_REVIEWS and the commit's PR lookup from FAKE_PULLS. + writeFileSync( + join(bin, "gh"), + '#!/bin/sh\ncase "$*" in *pulls/8000/reviews*) printf \'%s\' "$FAKE_REVIEWS" ;; *) printf \'%s\' "$FAKE_PULLS" ;; esac\n', + ); + chmodSync(join(bin, "gh"), 0o755); + const main = { REF_TYPE: "branch", REF_NAME: "main" }; + const run = (pulls, ref = main, reviews = approved) => { + const out = join(bin, "out"); + writeFileSync(out, ""); + const result = runStep(step, { + cwd: bin, + env: { + REPO: "heygen-com/hyperframes", + SHA: sha, + RUNNER_TEMP: bin, + GITHUB_OUTPUT: out, + FAKE_PULLS: JSON.stringify(pulls), + FAKE_REVIEWS: JSON.stringify(reviews), + ...ref, + }, + path: `${bin}:${process.env.PATH}`, + }); + const outputs = Object.fromEntries( + readFileSync(out, "utf8") + .split("\n") + .filter(Boolean) + .map((line) => line.split(/=(.*)/s).slice(0, 2)), + ); + return { status: result.status, outputs }; + }; + try { + assert.deepEqual(run([pull()]), { + status: 0, + outputs: { sha, version: "0.9.61", source: "release-pr", ref: "release/v0.9.61" }, + }); + for (const [why, pulls] of [ + ["no PR", []], + ["not merged", [pull({ merged_at: null })]], + ["another commit of the PR", [pull({ merge_commit_sha: "b".repeat(40) })]], + ["not into main", [pull({ base: { ref: "next" } })]], + [ + "from a fork", + [pull({ head: { ref: "release/v0.9.61", repo: { full_name: "x/hyperframes" } } })], + ], + ["a deleted fork", [pull({ head: { ref: "release/v0.9.61", repo: null } })]], + [ + "not a release branch", + [pull({ head: { ref: "fix/x", repo: { full_name: "heygen-com/hyperframes" } } })], + ], + [ + "a prerelease branch", + [ + pull({ + head: { ref: "release/v0.9.61-alpha.1", repo: { full_name: "heygen-com/hyperframes" } }, + }), + ], + ], + ]) { + assert.deepEqual(run(pulls), { status: 0, outputs: {} }, why); + } + const releaseSubject = { + REF_TYPE: "branch", + REF_NAME: "main", + HEAD_MESSAGE: "chore: release v0.9.61 (#8000)\n\nnotes", + }; + assert.equal( + run([], releaseSubject).status, + 1, + "a release commit whose PR is not listed yet fails, never skips", + ); + assert.equal( + run([], { ...releaseSubject, HEAD_MESSAGE: "fix: name chore: release v1 in the docs" }) + .status, + 0, + "only the subject's start counts", + ); + for (const [why, reviews] of [ + ["no review", []], + ["only the author approved", [review("releaser", "APPROVED", 1)]], + ["an earlier commit was approved", [review("reviewer", "APPROVED", 1, "d".repeat(40))]], + ["a comment is not an approval", [review("reviewer", "COMMENTED", 1)]], + ["a dismissed approval", [review("reviewer", "DISMISSED", 1)]], + ["an app's approval", [review("review-app[bot]", "APPROVED", 1, head, "Bot")]], + [ + "an app's change request stands", + [...approved, review("review-app[bot]", "CHANGES_REQUESTED", 2, head, "Bot")], + ], + [ + "another reviewer's change request stands", + [...approved, review("other", "CHANGES_REQUESTED", 2)], + ], + [ + "the approver later asked for changes", + [...approved, review("reviewer", "CHANGES_REQUESTED", 2)], + ], + ]) { + assert.equal(run([pull()], main, reviews).status, 1, why); + } + const reapproved = [ + review("reviewer", "CHANGES_REQUESTED", 1), + review("reviewer", "APPROVED", 2), + ]; + assert.equal( + run([pull()], main, reapproved).status, + 0, + "a later approval answers its own change request", + ); + const second = pull({ + head: { ref: "release/v0.9.62", repo: { full_name: "heygen-com/hyperframes" } }, + }); + assert.equal(run([pull(), second]).status, 1, "two release PRs for one commit"); + assert.deepEqual(run([], { REF_TYPE: "tag", REF_NAME: "v0.9.61-alpha.1" }), { + status: 0, + outputs: { sha, version: "0.9.61-alpha.1", source: "tag", ref: "v0.9.61-alpha.1" }, + }); + } finally { + rmSync(bin, { recursive: true, force: true }); + } +}); + test("the executable checkout guard cannot be conditionally disabled", () => { assert.ok(checkoutGuard); assert.equal(checkoutGuard.if, undefined); @@ -79,7 +228,7 @@ test("the executable checkout guard cannot be conditionally disabled", () => { test("stable release tag recovery is idempotent and immutable", () => { assert.ok(createReleaseTag); - assert.equal(createReleaseTag.if, "github.event_name == 'pull_request'"); + assert.equal(createReleaseTag.if, "needs.release-source.outputs.source == 'release-pr'"); assert.equal( createReleaseTag.run.trim(), [ @@ -264,7 +413,7 @@ test("release-commit code runs only in a job without secrets", () => { assert.equal(name, "GH_TOKEN"); } } - assert.deepEqual(publish.needs, ["pack"]); + assert.deepEqual(publish.needs, ["release-source", "pack"]); }); test("the publish job runs no code from the release commit", () => { @@ -287,20 +436,21 @@ test("the publish job runs no code from the release commit", () => { test("the publish job checks the release channel without repo scripts", () => { const step = stepOf(publish, "Check release channel"); - const check = (EVENT_NAME, VERSION, PRERELEASE, DIST_TAG = "alpha") => - runStep(step, { cwd: tmpdir(), env: { EVENT_NAME, VERSION, PRERELEASE, DIST_TAG } }).status; - assert.equal(check("push", "0.9.55-alpha.1", "true"), 0); - assert.equal(check("pull_request", "0.9.55", "false"), 0); - assert.equal(check("push", "0.9.55", "false"), 1); - assert.equal(check("pull_request", "0.9.55-alpha.1", "true"), 1); - assert.equal(check("push", "0.9.55-alpha.1;id", "true"), 1); - assert.equal(check("push", "0.9.55-latest.1", "true", "latest"), 1); - assert.equal(check("push", "0.9.55-hdr.1", "true", "hdr"), 0); - assert.equal(check("push", "0.9.55-beta.1", "true", "beta"), 0); - assert.equal(check("push", "0.9.55-LATEST.1", "true", "LATEST"), 1); - assert.equal(check("push", "0.9.55-Latest.1", "true", "Latest"), 1); - assert.equal(check("push", "0.9.55-Alpha.1", "true", "Alpha"), 1); - assert.equal(check("push", "0.9.55-stable.1", "true", "stable"), 1); + const check = (SOURCE, VERSION, PRERELEASE, DIST_TAG = "alpha") => + runStep(step, { cwd: tmpdir(), env: { SOURCE, VERSION, PRERELEASE, DIST_TAG } }).status; + assert.equal(check("tag", "0.9.55-alpha.1", "true"), 0); + assert.equal(check("release-pr", "0.9.55", "false"), 0); + assert.equal(check("tag", "0.9.55", "false"), 1); + assert.equal(check("release-pr", "0.9.55-alpha.1", "true"), 1); + assert.equal(check("tag", "0.9.55-alpha.1;id", "true"), 1); + assert.equal(check("tag", "0.9.55-latest.1", "true", "latest"), 1); + assert.equal(check("tag", "0.9.55-hdr.1", "true", "hdr"), 0); + assert.equal(check("tag", "0.9.55-beta.1", "true", "beta"), 0); + assert.equal(check("tag", "0.9.55-LATEST.1", "true", "LATEST"), 1); + assert.equal(check("tag", "0.9.55-Latest.1", "true", "Latest"), 1); + assert.equal(check("tag", "0.9.55-Alpha.1", "true", "Alpha"), 1); + assert.equal(check("tag", "0.9.55-stable.1", "true", "stable"), 1); + assert.equal(check("", "0.9.55", "false", "latest"), 1, "no release source"); }); test("the publish job takes only tarballs that npm reads the way the check does", () => { @@ -717,9 +867,13 @@ test("a tag publishes only a commit already on main, next or alpha, before any j for (const name of ["lambda-arm64-ffmpeg", "lambda-handler-zip"]) { assert.deepEqual(config.jobs[name].needs, ["release-source"], name); } - assert.deepEqual(pack.needs.sort(), ["lambda-arm64-ffmpeg", "lambda-handler-zip"]); + assert.deepEqual([...pack.needs].sort(), [ + "lambda-arm64-ffmpeg", + "lambda-handler-zip", + "release-source", + ]); const step = stepOf(source, "Check the tagged commit is on main, next or alpha"); - assert.equal(step.if, "github.event_name == 'push'"); + assert.equal(step.if, "github.ref_type == 'tag'"); const bin = mkdtempSync(join(tmpdir(), "hyperframes-fake-gh-")); try { // The fake answers compare/... from FAKE_; an unset branch answers like a 404. diff --git a/scripts/release-lambda-assets.test.mjs b/scripts/release-lambda-assets.test.mjs index 15df05a962..74bd4ada4f 100644 --- a/scripts/release-lambda-assets.test.mjs +++ b/scripts/release-lambda-assets.test.mjs @@ -306,7 +306,7 @@ test("receipt and bundle persistence precede side effects and do not overwrite p s.with.path === "${{ runner.temp }}/release-bundle", ); assert.equal(download.with["artifact-ids"], "${{ needs.pack.outputs.bundle_id }}"); - assert.equal(workflow.concurrency["cancel-in-progress"], false); + assert.equal(workflow.jobs.publish.concurrency["cancel-in-progress"], false); }); // GitHub's implicit bash shell does not enable pipefail; explicit shell: bash does. diff --git a/scripts/validate-release-channel.mjs b/scripts/validate-release-channel.mjs index 10b5ad1956..011f8d2de6 100644 --- a/scripts/validate-release-channel.mjs +++ b/scripts/validate-release-channel.mjs @@ -33,11 +33,11 @@ function validateDistTag(version, distTag) { ]; } -function validateMergedReleasePr({ version, prHeadRef }) { +function validateMergedReleasePr({ version, releaseRef }) { const errors = []; - if (!RELEASE_PR_RE.test(prHeadRef)) { + if (!RELEASE_PR_RE.test(releaseRef)) { errors.push( - `Merged release PRs must come from release/vX.Y.Z branches, got "${prHeadRef || ""}".`, + `Merged release PRs must come from release/vX.Y.Z branches, got "${releaseRef || ""}".`, ); } if (expectedDistTag(version) !== "latest") { @@ -51,7 +51,7 @@ function validateMergedReleasePr({ version, prHeadRef }) { function validatePrereleaseTagPush({ version, distTag, remoteBranches }) { if (expectedDistTag(version) === "latest") { return [ - "Stable tag publishing is disabled. Merge a reviewed release/vX.Y.Z PR into main and rerun that immutable merge event for recovery.", + "Stable tag publishing is disabled. Merge a reviewed release/vX.Y.Z PR into main; to recover, rerun the failed jobs of the publish run on that merge.", ]; } @@ -63,14 +63,14 @@ function validatePrereleaseTagPush({ version, distTag, remoteBranches }) { ]; } -const EVENT_VALIDATORS = new Map([ - ["pull_request", validateMergedReleasePr], - ["push", validatePrereleaseTagPush], +const SOURCE_VALIDATORS = new Map([ + ["release-pr", validateMergedReleasePr], + ["tag", validatePrereleaseTagPush], ]); function validateReleaseSource(input) { - const validator = EVENT_VALIDATORS.get(input.eventName); - return validator ? validator(input) : [`Unsupported publish event "${input.eventName}".`]; + const validator = SOURCE_VALIDATORS.get(input.source); + return validator ? validator(input) : [`Unsupported release source "${input.source}".`]; } export function validateReleaseChannel(input) { @@ -93,18 +93,18 @@ function readEnv(name) { return process.env[name] ?? ""; } -function readRemoteBranchesForEvent(eventName) { - return eventName === "pull_request" ? [] : readRemoteBranchesContainingHead(); +function readRemoteBranchesForSource(source) { + return source === "tag" ? readRemoteBranchesContainingHead() : []; } function readValidationInput() { - const eventName = readEnv("EVENT_NAME"); + const source = readEnv("SOURCE"); return { version: readEnv("VERSION"), distTag: readEnv("DIST_TAG"), - eventName, - prHeadRef: readEnv("PR_HEAD_REF"), - remoteBranches: readRemoteBranchesForEvent(eventName), + source, + releaseRef: readEnv("RELEASE_REF"), + remoteBranches: readRemoteBranchesForSource(source), }; } diff --git a/scripts/validate-release-channel.test.mjs b/scripts/validate-release-channel.test.mjs index 076797884f..28e3d72adc 100644 --- a/scripts/validate-release-channel.test.mjs +++ b/scripts/validate-release-channel.test.mjs @@ -19,8 +19,8 @@ describe("release channel validation", () => { const errors = validateReleaseChannel({ version: "0.4.24", distTag: "latest", - eventName: "pull_request", - prHeadRef: "release/v0.4.24", + source: "release-pr", + releaseRef: "release/v0.4.24", remoteBranches: [], }); @@ -31,8 +31,8 @@ describe("release channel validation", () => { const errors = validateReleaseChannel({ version: "0.4.24", distTag: "latest", - eventName: "push", - prHeadRef: "", + source: "tag", + releaseRef: "", remoteBranches: ["origin/main", "origin/next"], }); @@ -44,8 +44,8 @@ describe("release channel validation", () => { const errors = validateReleaseChannel({ version: "0.4.24", distTag: "latest", - eventName: "push", - prHeadRef: "", + source: "tag", + releaseRef: "", remoteBranches: ["origin/release/v0.4.24"], }); @@ -57,8 +57,8 @@ describe("release channel validation", () => { const errors = validateReleaseChannel({ version: "0.4.24-alpha.1", distTag: "alpha", - eventName: "push", - prHeadRef: "", + source: "tag", + releaseRef: "", remoteBranches: ["origin/next"], }); @@ -69,8 +69,8 @@ describe("release channel validation", () => { const errors = validateReleaseChannel({ version: "0.4.24-alpha.1", distTag: "alpha", - eventName: "push", - prHeadRef: "", + source: "tag", + releaseRef: "", remoteBranches: ["origin/main"], }); @@ -82,8 +82,8 @@ describe("release channel validation", () => { const errors = validateReleaseChannel({ version: "0.4.24-alpha.1", distTag: "latest", - eventName: "push", - prHeadRef: "", + source: "tag", + releaseRef: "", remoteBranches: ["origin/next"], }); @@ -95,8 +95,8 @@ describe("release channel validation", () => { const errors = validateReleaseChannel({ version: "0.4.24-alpha.1", distTag: "alpha", - eventName: "pull_request", - prHeadRef: "release/v0.4.24-alpha.1", + source: "release-pr", + releaseRef: "release/v0.4.24-alpha.1", remoteBranches: [], }); @@ -105,16 +105,16 @@ describe("release channel validation", () => { assert.match(errors.join("\n"), /stable releases only/); }); - it("rejects manual publish events", () => { + it("rejects an unknown release source", () => { const errors = validateReleaseChannel({ version: "0.4.24", distTag: "latest", - eventName: "workflow_dispatch", - prHeadRef: "", + source: "workflow_dispatch", + releaseRef: "", remoteBranches: ["origin/main"], }); - assert.deepEqual(errors, ['Unsupported publish event "workflow_dispatch".']); + assert.deepEqual(errors, ['Unsupported release source "workflow_dispatch".']); }); it("normalizes git branch output", () => {