fix(release): publish from explicit source checkpoints (#1006)

* fix(release): publish from explicit source checkpoints

Dispatch preparation and publication against a frozen release branch.
Bind package builds and provenance to the same tagged commit, enable
release-branch PR CI, and document the maintainer workflow.

Assisted-by: Sakuya (gensokyo-skills:sakuya-checkpointed-execution)

* fix(release): stop publication when the checkpoint has moved

Reject unknown phases and a release-branch tip that differs from the
dispatch SHA before Release Please creates a tag. Keep registry jobs and
catalog pushes on their own phase, and run website checks for release PRs.

* fix(release): require a token that can trigger release CI

Stop falling back to GITHUB_TOKEN, which cannot start workflow runs for the release pull request it creates.

* test(release): require the CI-capable release token

Lock the workflow to RELEASE_PLEASE_TOKEN and fail preparation when that secret is missing.

* style(release): format the release-token test

---------

Co-authored-by: N0zoM1z0 <1705004398@qq.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
morluto
2026-10-08 01:15:54 +08:00
committed by GitHub
co-authored by N0zoM1z0 Cursor Agent
parent 64c71880ae
commit b4fc0ecaa1
5 changed files with 327 additions and 120 deletions
+85 -28
View File
@@ -1,15 +1,24 @@
name: Release name: Release
on: on:
push:
branches: ["release/*"]
workflow_dispatch: workflow_dispatch:
inputs:
release_branch:
description: Frozen release branch (release/VERSION)
required: true
type: string
phase:
description: Prepare the release PR, or publish its reviewed merge
required: true
default: prepare
type: choice
options: [prepare, publish]
env: env:
HUSKY: "0" HUSKY: "0"
concurrency: concurrency:
group: release-${{ github.ref }} group: release-${{ inputs.release_branch }}
cancel-in-progress: false cancel-in-progress: false
jobs: jobs:
@@ -21,77 +30,125 @@ jobs:
pull-requests: write pull-requests: write
outputs: outputs:
release_created: ${{ steps.release.outputs.release_created }} release_created: ${{ steps.release.outputs.release_created }}
tag_name: ${{ steps.release.outputs.tag_name }}
sha: ${{ steps.release.outputs.sha }} sha: ${{ steps.release.outputs.sha }}
steps: steps:
- name: Require a CI-capable release token
shell: bash
env:
RELEASE_PLEASE_TOKEN: ${{ secrets.RELEASE_PLEASE_TOKEN }}
run: |
if [[ -z "${RELEASE_PLEASE_TOKEN}" ]]; then
echo "RELEASE_PLEASE_TOKEN is required. Pull requests and catalog commits created with GITHUB_TOKEN do not start workflow runs, so the normalized release head would have no CI result to approve." >&2
exit 1
fi
- name: Validate release selection - name: Validate release selection
shell: bash shell: bash
env: env:
GH_TOKEN: ${{ github.token }} RELEASE_BRANCH: ${{ inputs.release_branch }}
RELEASE_BRANCH: ${{ github.ref_name }} RELEASE_PHASE: ${{ inputs.phase }}
run: | run: |
if [[ "${GITHUB_REF}" != "refs/heads/${RELEASE_BRANCH}" || "${RELEASE_BRANCH}" != release/* ]]; then if [[ "${RELEASE_PHASE}" != prepare && "${RELEASE_PHASE}" != publish ]]; then
echo "Select a release/ branch; main and tags are not release checkpoints." >&2 echo "phase must be prepare or publish." >&2
exit 1
fi
if [[ "${RELEASE_PHASE}" == prepare && "${GITHUB_REF}" != "refs/heads/main" ]]; then
echo "Run prepare from main; release_branch selects the frozen source." >&2
exit 1
fi
if [[ "${RELEASE_PHASE}" == publish && "${GITHUB_REF}" != "refs/heads/${RELEASE_BRANCH}" ]]; then
echo "Run publish from the selected frozen release branch so npm provenance records its source." >&2
exit 1
fi
if [[ ! "${RELEASE_BRANCH}" =~ ^release/[^/]+$ ]]; then
echo "release_branch must select a release/ branch; main is not a release checkpoint." >&2
exit 1 exit 1
fi fi
if ! git check-ref-format "refs/heads/${RELEASE_BRANCH}"; then if ! git check-ref-format "refs/heads/${RELEASE_BRANCH}"; then
echo "Invalid release branch: ${RELEASE_BRANCH}" >&2 echo "Invalid release_branch: ${RELEASE_BRANCH}" >&2
exit 1 exit 1
fi fi
selected_sha="$(gh api "repos/${GITHUB_REPOSITORY}/git/ref/heads/${RELEASE_BRANCH}" --jq '.object.sha')"
if [[ "${selected_sha}" != "${GITHUB_SHA}" ]]; then - name: Resolve release branch tip
echo "The release branch moved after this run was triggered; review its new checkpoint before publication." >&2 id: branch
shell: bash
env:
GH_TOKEN: ${{ github.token }}
RELEASE_BRANCH: ${{ inputs.release_branch }}
run: |
sha="$(gh api "repos/${GITHUB_REPOSITORY}/git/ref/heads/${RELEASE_BRANCH}" --jq '.object | select(.type == "commit") | .sha')"
if [[ ! "${sha}" =~ ^[0-9a-f]{40}$ ]]; then
echo "The release branch tip is not a commit." >&2
exit 1
fi
echo "sha=${sha}" >> "${GITHUB_OUTPUT}"
- name: Require the publish dispatch to match the branch tip
if: inputs.phase == 'publish'
shell: bash
env:
BRANCH_SHA: ${{ steps.branch.outputs.sha }}
run: |
if [[ "${BRANCH_SHA}" != "${GITHUB_SHA}" ]]; then
echo "The release branch tip differs from the dispatched checkpoint; refusing to create a release for a moved source." >&2
exit 1 exit 1
fi fi
printf 'Selected release checkpoint: %s\n' "${selected_sha}"
- uses: googleapis/release-please-action@v4 - uses: googleapis/release-please-action@v4
id: release id: release
with: with:
# A dedicated credential lets release-PR updates trigger CI. GitHub # A dedicated credential lets release-PR updates trigger CI.
# requires manual approval for pull_request events from GITHUB_TOKEN. # GITHUB_TOKEN-authored pull requests do not start workflow runs.
token: ${{ secrets.RELEASE_PLEASE_TOKEN || secrets.GITHUB_TOKEN }} token: ${{ secrets.RELEASE_PLEASE_TOKEN }}
target-branch: ${{ github.ref_name }} target-branch: ${{ inputs.release_branch }}
skip-github-release: ${{ inputs.phase == 'prepare' }}
skip-github-pull-request: ${{ inputs.phase == 'publish' }}
- name: Bind publication to the triggering checkpoint - name: Require a merged release PR for publication
if: steps.release.outputs.release_created == 'true' if: inputs.phase == 'publish' && steps.release.outputs.release_created != 'true'
run: |
echo "No new release was created. Merge the reviewed release PR into its frozen branch before publishing. For a partial publication, re-run failed jobs in the original run." >&2
exit 1
- name: Bind publication to the dispatched checkpoint
if: inputs.phase == 'publish' && steps.release.outputs.release_created == 'true'
shell: bash shell: bash
env: env:
RELEASE_SHA: ${{ steps.release.outputs.sha }} RELEASE_SHA: ${{ steps.release.outputs.sha }}
run: | run: |
if [[ "${RELEASE_SHA}" != "${GITHUB_SHA}" ]]; then if [[ "${RELEASE_SHA}" != "${GITHUB_SHA}" ]]; then
echo "The tagged release SHA differs from the triggering checkpoint; refusing to publish mismatched source provenance." >&2 echo "The tagged release SHA differs from the dispatched checkpoint; refusing to publish mismatched source provenance. The GitHub release already exists; do not dispatch publish again." >&2
exit 1 exit 1
fi fi
- name: Check out release pull request - name: Check out release pull request
if: steps.release.outputs.prs_created == 'true' if: inputs.phase == 'prepare' && steps.release.outputs.prs_created == 'true'
uses: actions/checkout@v6 uses: actions/checkout@v6
with: with:
ref: ${{ fromJSON(steps.release.outputs.pr).headBranchName }} ref: ${{ fromJSON(steps.release.outputs.pr).headBranchName }}
persist-credentials: false persist-credentials: false
- name: Set up Node.js for generated documentation - name: Set up Node.js for generated documentation
if: steps.release.outputs.prs_created == 'true' if: inputs.phase == 'prepare' && steps.release.outputs.prs_created == 'true'
uses: actions/setup-node@v6 uses: actions/setup-node@v6
with: with:
node-version-file: .nvmrc node-version-file: .nvmrc
package-manager-cache: false package-manager-cache: false
- name: Install dependencies - name: Install dependencies
if: steps.release.outputs.prs_created == 'true' if: inputs.phase == 'prepare' && steps.release.outputs.prs_created == 'true'
run: npm ci run: npm ci
- name: Regenerate release documentation - name: Regenerate release documentation
if: steps.release.outputs.prs_created == 'true' if: inputs.phase == 'prepare' && steps.release.outputs.prs_created == 'true'
run: npm run docs:generate run: npm run docs:generate
- name: Commit canonical release catalog - name: Commit canonical release catalog
if: steps.release.outputs.prs_created == 'true' if: inputs.phase == 'prepare' && steps.release.outputs.prs_created == 'true'
shell: bash shell: bash
env: env:
# Use the same identity for the follow-up commit so it also triggers CI. # Use the same identity for the follow-up commit so it also triggers CI.
GH_TOKEN: ${{ secrets.RELEASE_PLEASE_TOKEN || secrets.GITHUB_TOKEN }} GH_TOKEN: ${{ secrets.RELEASE_PLEASE_TOKEN }}
RELEASE_PR_JSON: ${{ steps.release.outputs.pr }} RELEASE_PR_JSON: ${{ steps.release.outputs.pr }}
run: | run: |
release_pr_branch="$(node --input-type=module -e ' release_pr_branch="$(node --input-type=module -e '
@@ -127,7 +184,7 @@ jobs:
publish: publish:
name: Publish to npm name: Publish to npm
needs: release-please needs: release-please
if: needs.release-please.outputs.release_created == 'true' if: inputs.phase == 'publish' && needs.release-please.outputs.release_created == 'true'
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
contents: read contents: read
@@ -198,7 +255,7 @@ jobs:
publish-mcp: publish-mcp:
name: Publish to MCP Registry name: Publish to MCP Registry
needs: [release-please, publish] needs: [release-please, publish]
if: needs.release-please.outputs.release_created == 'true' && needs.publish.result == 'success' if: inputs.phase == 'publish' && needs.release-please.outputs.release_created == 'true' && needs.publish.result == 'success'
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
contents: read contents: read
+1 -1
View File
@@ -2,7 +2,7 @@ name: Website checks
on: on:
pull_request: pull_request:
branches: [main] branches: [main, "release/*"]
paths: paths:
- "website/**" - "website/**"
- "scripts/verify-website.py" - "scripts/verify-website.py"
+12 -10
View File
@@ -28,19 +28,21 @@ Keep dependencies flowing inward through the existing domain, contracts, provide
## Documentation website ## Documentation website
The VitePress site uses the Markdown files in `docs/` and deploys to The VitePress site uses the Markdown files in `docs/`. Run `npm run docs:dev`
<https://morluto.github.io/rea/>. Run `npm run docs:dev` for live editing, for live editing, `npm run docs:build` to check the production build and
`npm run docs:build` to check the production build and links, and links, and `npm run docs:preview` to preview that build at `/rea/`.
`npm run docs:preview` to preview that build at `/rea/`.
Site navigation lives in `docs/.vitepress/config.ts`. Keep links to guides Site navigation lives in `docs/.vitepress/config.ts`. Keep links to guides
relative so they work on GitHub and the website; link to repository files relative so they work on GitHub and the website; link to repository files
outside `docs/` using their full GitHub URLs. Generated reference documents outside `docs/` using their full GitHub URLs. Generated reference documents
still use `npm run docs:generate`; `docs:build` only builds the website. still use `npm run docs:generate`; `docs:build` only builds the website.
The documentation workflow builds pull requests and deploys changes on `main`. Pull requests run `npm run docs:check`. `.github/workflows/pages.yml` is a
The repository's **Settings → Pages → Build and deployment → Source** must be manual VitePress build and does not publish. The public site at
set to **GitHub Actions** before the first deployment. <https://morluto.github.io/rea/> is published only by the manual website
workflow on `main`. The repository's **Settings → Pages → Build and
deployment → Source** must be set to **GitHub Actions** before the first
deployment.
## Development feedback and PR verification ## Development feedback and PR verification
@@ -121,9 +123,9 @@ Describe the behavior change and verification performed in the pull request. Nev
## Maintainer release checklist ## Maintainer release checklist
Use the [checkpoint release guide](docs/releasing.md). Releases start from an Use the [checkpoint release guide](docs/releasing.md). Releases start from an
explicit `release/VERSION` branch cut at a recorded commit. Pushing the branch prepares explicit `release/VERSION` branch cut at a recorded commit. Manually prepare
the bot PR. Wait for its exact-head CI and review; merging into that frozen the bot PR, wait for its exact-head CI and review, merge into that frozen
branch triggers publication through the official Release workflow. Main branch, and manually publish through the official Release workflow. Main
pushes do not update release PRs or publish packages. Both publishers build pushes do not update release PRs or publish packages. Both publishers build
the exact SHA tagged by Release Please. the exact SHA tagged by Release Please.
+51 -36
View File
@@ -1,10 +1,10 @@
# Releasing from a checkpoint # Releasing from a checkpoint
REA releases use a frozen source checkpoint. Main can continue accepting REA releases use an explicit source checkpoint. Main can continue accepting
changes while a release is tested and published. The Release workflow runs changes while a release is tested and published. The Release workflow runs
on `release/*` branches; main pushes do not refresh release PRs. only when a maintainer dispatches it; main pushes do not refresh release PRs.
## 1. Cut the release branch ## 1. Select the source
Choose the next version from the unreleased Conventional Commits, including Choose the next version from the unreleased Conventional Commits, including
breaking changes. Record the full source SHA and create `release/VERSION` at breaking changes. Record the full source SHA and create `release/VERSION` at
@@ -25,43 +25,54 @@ older checkpoint, backport only the release infrastructure first and record
that additional commit. Do not merge later implementation changes into the that additional commit. Do not merge later implementation changes into the
release branch or rebase the candidate onto a moving main. release branch or rebase the candidate onto a moving main.
The branch push runs Release Please against that branch and opens a PR for ## 2. Prepare the bot PR
the version, changelog, and registry metadata. The generation step normalizes
the product catalog. To retry preparation after a failed run, select the same Run the workflow definition from main and select the frozen source separately:
frozen branch explicitly:
```bash ```bash
gh workflow run release.yml --ref release/5.0.0 gh workflow run release.yml --ref main \
-f release_branch=release/5.0.0 -f phase=prepare
``` ```
## 2. Review and merge the bot PR Release Please targets that branch and prepares its version, changelog, and
registry metadata. Preparation requires the `RELEASE_PLEASE_TOKEN` repository
secret. That credential opens the release pull request and pushes the catalog
normalization commit, so both start CI on the exact normalized head. The
default `GITHUB_TOKEN` cannot do that: events it authors do not start
workflow runs, and there is then no blocked run to approve. The existing
generation step normalizes the product catalog. Preparation cannot create a
GitHub release or publish a package. Record the final bot PR head after
normalization and wait for that head's CI.
Record the final bot PR head after normalization. Approve GitHub-blocked bot Review the candidate's version, notes, generated metadata, and package
workflow runs for that head when needed. Review the candidate's version, contents. Wait for the candidate's CI and relevant real-provider checks.
notes, generated metadata, and package contents. Wait for the candidate's CI Routine local iterations need focused checks; CI owns full deterministic
and relevant real-provider checks. Routine local iterations need focused coverage and platform lanes. If an artifact or real-provider check is
checks; CI owns full deterministic coverage and platform lanes. If an artifact unavailable, report that limit before deciding to publish.
or real-provider check is unavailable, report that limit before deciding to
publish.
Merge the reviewed PR into `release/5.0.0` with its head SHA matched. **This Merge the reviewed PR into `release/5.0.0` with its head SHA matched. Further
merge authorizes and triggers publication.** Further main commits do not change main commits do not change this candidate. A necessary release fix belongs
this candidate. Do not push or merge anything else into the release branch on the release branch, must be reviewed and tested, and establishes a new
while publication is running. A necessary release fix must be reviewed and recorded checkpoint.
tested before the bot PR merges and establishes a new recorded checkpoint.
## 3. Verify publication ## 3. Publish the reviewed merge
The merge push runs Release Please again, creates the tag and GitHub release, After the release PR has merged:
and publishes npm followed by MCP Registry metadata. Both publishers check
out Release Please's exact release SHA. The triggering workflow also runs
from that release commit so npm's provenance records the actual source.
Before invoking Release Please, the workflow checks that the release branch ```bash
still equals the triggering SHA and rejects main or tag refs. Before either gh workflow run release.yml --ref release/5.0.0 \
registry publish, it rejects a mismatch between the tagged release SHA and -f release_branch=release/5.0.0 -f phase=publish
the triggering SHA. These checks detect moved branches; maintainers must also ```
keep the release branch frozen throughout publication.
Publication creates the release from the merged bot PR without preparing or
updating another PR. Both npm and MCP Registry jobs check out Release Please's
exact release SHA. They do not build the current main tip or a mutable branch.
The publish dispatch runs from the frozen release branch so npm's provenance
records the actual release commit. Before Release Please creates a tag, the
workflow accepts only `prepare` or `publish` and requires the selected branch
tip to equal the dispatch SHA. Registry jobs run only during `publish`. After
a tag exists, a mismatch between that tag's SHA and the dispatch SHA stops
both registry publishes.
See [npm's provenance implementation](https://github.com/npm/cli/blob/v11.16.0/workspaces/libnpmpublish/lib/provenance.js) See [npm's provenance implementation](https://github.com/npm/cli/blob/v11.16.0/workspaces/libnpmpublish/lib/provenance.js)
for the use of GitHub's workflow ref and commit SHA. for the use of GitHub's workflow ref and commit SHA.
@@ -78,7 +89,7 @@ Record these outcomes separately:
A GitHub tag alone does not establish npm or MCP Registry publication. A GitHub tag alone does not establish npm or MCP Registry publication.
## Sync metadata back to main ## 4. Sync metadata back to main
After publication, open a PR from the release branch back to main. Preserve After publication, open a PR from the release branch back to main. Preserve
main's later implementation changes and resolve generated-file conflicts by main's later implementation changes and resolve generated-file conflicts by
@@ -88,6 +99,9 @@ tag remains in main's ancestry. Keep the released tag unchanged.
Close any superseded rolling release PR. Future releases repeat the checkpoint Close any superseded rolling release PR. Future releases repeat the checkpoint
procedure from main; never resume automatic release-PR refreshes on main pushes. procedure from main; never resume automatic release-PR refreshes on main pushes.
The generated-metadata workflow stays limited to pull requests into main so it
does not push commits onto a frozen candidate. Preparation normalizes
`docs/product-catalog.json` on the bot pull request.
## Partial publication and retries ## Partial publication and retries
@@ -97,7 +111,8 @@ publishing it again. Re-run failed jobs in the original publication run so its
release SHA and outputs stay fixed. If only MCP publication failed, retry that release SHA and outputs stay fixed. If only MCP publication failed, retry that
job after checking that the npm canary succeeded. job after checking that the npm canary succeeded.
Do not start a fresh workflow run to repair an already-created release: A branch tip that moved after dispatch fails before Release Please creates a
Release Please will not create the same release again. Do not move the tag, tag. Do not dispatch a fresh publish phase to repair an already-created
delete the release, or unpublish npm as a retry. A defective public package release: Release Please will not create the same release again. Do not move
requires a reviewed correction and a new version. the tag, delete the release, or unpublish npm as a retry. A defective public
package requires a reviewed correction and a new version.
+178 -45
View File
@@ -1,21 +1,21 @@
import { execFile } from "node:child_process"; import { execFile } from "node:child_process";
import { readFile, writeFile } from "node:fs/promises"; import { readFile } from "node:fs/promises";
import { delimiter, join } from "node:path";
import { promisify } from "node:util"; import { promisify } from "node:util";
import { expect, it } from "vitest"; import { expect, it } from "vitest";
import { parse } from "yaml"; import { parse } from "yaml";
import { z } from "zod"; import { z } from "zod";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const execFileAsync = promisify(execFile); const execFileAsync = promisify(execFile);
const stepSchema = z.object({ const stepSchema = z.object({
name: z.string().optional(), name: z.string().optional(),
uses: z.string().optional(), uses: z.string().optional(),
run: z.string().optional(), run: z.string().optional(),
if: z.string().optional(),
with: z.record(z.string(), z.unknown()).optional(), with: z.record(z.string(), z.unknown()).optional(),
env: z.record(z.string(), z.unknown()).optional(),
}); });
const jobSchema = z.object({ const jobSchema = z.object({
if: z.string().optional(),
outputs: z.record(z.string(), z.string()).optional(), outputs: z.record(z.string(), z.string()).optional(),
steps: z.array(stepSchema), steps: z.array(stepSchema),
}); });
@@ -40,23 +40,67 @@ async function readReleaseWorkflow() {
); );
} }
it("prepares and publishes only from frozen release branches", async () => { it("requires explicit release preparation or publication instead of main pushes", async () => {
const workflow = await readReleaseWorkflow(); const workflow = await readReleaseWorkflow();
expect(workflow.on.push).toEqual({ branches: ["release/*"] }); expect(Object.keys(workflow.on)).toEqual(["workflow_dispatch"]);
expect(workflow.on).toHaveProperty("workflow_dispatch"); expect(workflow.on.workflow_dispatch).toMatchObject({
expect(workflow.on.workflow_dispatch).toBeNull(); inputs: {
release_branch: { required: true, type: "string" },
phase: {
required: true,
type: "choice",
default: "prepare",
options: ["prepare", "publish"],
},
},
});
const release = workflow.jobs["release-please"].steps.find((step) => const release = workflow.jobs["release-please"].steps.find((step) =>
step.uses?.startsWith("googleapis/release-please-action@"), step.uses?.startsWith("googleapis/release-please-action@"),
); );
expect(release?.with?.["target-branch"]).toBe("${{ github.ref_name }}"); expect(release?.with).toMatchObject({
expect(release?.with).not.toHaveProperty("skip-github-release"); token: "${{ secrets.RELEASE_PLEASE_TOKEN }}",
expect(release?.with).not.toHaveProperty("skip-github-pull-request"); "target-branch": "${{ inputs.release_branch }}",
"skip-github-release": "${{ inputs.phase == 'prepare' }}",
"skip-github-pull-request": "${{ inputs.phase == 'publish' }}",
});
const catalogCommit = workflow.jobs["release-please"].steps.find(
(step) => step.name === "Commit canonical release catalog",
);
expect(catalogCommit?.env?.GH_TOKEN).toBe(
"${{ secrets.RELEASE_PLEASE_TOKEN }}",
);
});
it("stops preparation when the CI-capable release token is missing", async () => {
const workflow = await readReleaseWorkflow();
const command = z
.string()
.parse(
workflow.jobs["release-please"].steps.find(
(step) => step.name === "Require a CI-capable release token",
)?.run,
);
await expect(
execFileAsync("bash", ["-e", "-o", "pipefail", "-c", command], {
env: { ...process.env, RELEASE_PLEASE_TOKEN: "" },
}),
).rejects.toMatchObject({
code: 1,
stderr: expect.stringMatching(/RELEASE_PLEASE_TOKEN/u),
});
}); });
it("binds npm and MCP publication to the same immutable release SHA", async () => { it("binds npm and MCP publication to the same immutable release SHA", async () => {
const workflow = await readReleaseWorkflow(); const workflow = await readReleaseWorkflow();
expect(workflow.jobs["release-please"].outputs?.sha).toBe( expect(workflow.jobs["release-please"].outputs).toEqual({
"${{ steps.release.outputs.sha }}", release_created: "${{ steps.release.outputs.release_created }}",
sha: "${{ steps.release.outputs.sha }}",
});
expect(workflow.jobs.publish.if).toBe(
"inputs.phase == 'publish' && needs.release-please.outputs.release_created == 'true'",
);
expect(workflow.jobs["publish-mcp"].if).toBe(
"inputs.phase == 'publish' && needs.release-please.outputs.release_created == 'true' && needs.publish.result == 'success'",
); );
for (const job of [workflow.jobs.publish, workflow.jobs["publish-mcp"]]) { for (const job of [workflow.jobs.publish, workflow.jobs["publish-mcp"]]) {
const checkout = job.steps.find((step) => const checkout = job.steps.find((step) =>
@@ -67,6 +111,21 @@ it("binds npm and MCP publication to the same immutable release SHA", async () =
"persist-credentials": false, "persist-credentials": false,
}); });
} }
const preparation = [
"Check out release pull request",
"Set up Node.js for generated documentation",
"Install dependencies",
"Regenerate release documentation",
"Commit canonical release catalog",
];
for (const name of preparation) {
expect(
workflow.jobs["release-please"].steps.find((step) => step.name === name)
?.if,
).toBe(
"inputs.phase == 'prepare' && steps.release.outputs.prs_created == 'true'",
);
}
}); });
it it
@@ -86,26 +145,25 @@ it
execFileAsync("bash", ["-e", "-o", "pipefail", "-c", command], { execFileAsync("bash", ["-e", "-o", "pipefail", "-c", command], {
env: { env: {
...process.env, ...process.env,
GITHUB_REF: `refs/heads/${releaseBranch}`, GITHUB_REF: "refs/heads/main",
RELEASE_BRANCH: releaseBranch, RELEASE_BRANCH: releaseBranch,
RELEASE_PHASE: "prepare",
}, },
}), }),
).rejects.toMatchObject({ ).rejects.toMatchObject({
code: 1, code: 1,
stderr: expect.stringMatching(/release.*branch/u), stderr: expect.stringMatching(/release_branch/u),
}); });
}, },
); );
it it.skipIf(process.platform === "win32").each([
.skipIf(process.platform === "win32") { phase: "prepare", ref: "refs/heads/feature/unreviewed-workflow" },
.each([ { phase: "publish", ref: "refs/heads/main" },
"refs/heads/main", { phase: "publish", ref: "refs/heads/release/another-version" },
"refs/tags/release/5.0.0", ])(
"refs/heads/release/another-version", "rejects $phase from $ref before contacting GitHub",
])( async ({ phase, ref }) => {
"rejects a ref that does not select the release branch: %s",
async (ref) => {
const workflow = await readReleaseWorkflow(); const workflow = await readReleaseWorkflow();
const command = z const command = z
.string() .string()
@@ -120,18 +178,56 @@ it
...process.env, ...process.env,
GITHUB_REF: ref, GITHUB_REF: ref,
RELEASE_BRANCH: "release/5.0.0", RELEASE_BRANCH: "release/5.0.0",
RELEASE_PHASE: phase,
}, },
}), }),
).rejects.toMatchObject({ ).rejects.toMatchObject({
code: 1, code: 1,
stderr: expect.stringContaining("Select a release/ branch"), stderr: expect.stringContaining(`Run ${phase} from`),
}); });
}, },
); );
it.skipIf(process.platform === "win32").each([true, false])( it.skipIf(process.platform === "win32")(
"checks the release branch still matches its triggering commit before tagging (match: %s)", "checks the checkpoint locally and resolves the branch tip separately",
async (match) => { async () => {
const workflow = await readReleaseWorkflow();
const validate = z
.string()
.parse(
workflow.jobs["release-please"].steps.find(
(step) => step.name === "Validate release selection",
)?.run,
);
expect(validate).not.toMatch(/\bgh\b/u);
const resolve = z
.string()
.parse(
workflow.jobs["release-please"].steps.find(
(step) => step.name === "Resolve release branch tip",
)?.run,
);
expect(resolve).toContain("gh api");
for (const releaseBranch of ["release/5.0.0", "release/5.0.0-rc.1"]) {
await expect(
execFileAsync("bash", ["-e", "-o", "pipefail", "-c", validate], {
env: {
...process.env,
GITHUB_REF: "refs/heads/main",
RELEASE_BRANCH: releaseBranch,
RELEASE_PHASE: "prepare",
},
}),
).resolves.toMatchObject({ stderr: "" });
}
},
);
it
.skipIf(process.platform === "win32")
.each(["", "release", "prepare ", "true"])(
"rejects phase %j before contacting GitHub",
async (phase) => {
const workflow = await readReleaseWorkflow(); const workflow = await readReleaseWorkflow();
const command = z const command = z
.string() .string()
@@ -140,39 +236,55 @@ it.skipIf(process.platform === "win32").each([true, false])(
(step) => step.name === "Validate release selection", (step) => step.name === "Validate release selection",
)?.run, )?.run,
); );
const directory = await createTestTempDirectory("rea-release-selection-"); await expect(
await writeFile( execFileAsync("bash", ["-e", "-o", "pipefail", "-c", command], {
join(directory, "gh"), env: {
'#!/bin/sh\nprintf "%s\\n" "$TEST_RELEASE_REF_SHA"\n', ...process.env,
{ mode: 0o755 }, GITHUB_REF: "refs/heads/main",
); RELEASE_BRANCH: "release/5.0.0",
RELEASE_PHASE: phase,
},
}),
).rejects.toMatchObject({
code: 1,
stderr: expect.stringContaining("phase must be prepare or publish"),
});
},
);
it.skipIf(process.platform === "win32").each([true, false])(
"creates a release only when the branch tip is the dispatched checkpoint (match: %s)",
async (match) => {
const workflow = await readReleaseWorkflow();
const command = z
.string()
.parse(
workflow.jobs["release-please"].steps.find(
(step) =>
step.name ===
"Require the publish dispatch to match the branch tip",
)?.run,
);
const result = execFileAsync( const result = execFileAsync(
"bash", "bash",
["-e", "-o", "pipefail", "-c", command], ["-e", "-o", "pipefail", "-c", command],
{ {
env: { env: {
...process.env, ...process.env,
PATH: `${directory}${delimiter}${process.env.PATH ?? ""}`,
GITHUB_REF: "refs/heads/release/5.0.0",
RELEASE_BRANCH: "release/5.0.0",
GITHUB_REPOSITORY: "fixture/fixture",
GITHUB_SHA: "1111111111111111111111111111111111111111", GITHUB_SHA: "1111111111111111111111111111111111111111",
TEST_RELEASE_REF_SHA: match BRANCH_SHA: match
? "1111111111111111111111111111111111111111" ? "1111111111111111111111111111111111111111"
: "2222222222222222222222222222222222222222", : "2222222222222222222222222222222222222222",
}, },
}, },
); );
if (match) { if (match) {
await expect(result).resolves.toMatchObject({ await expect(result).resolves.toMatchObject({ stderr: "" });
stdout: expect.stringContaining("Selected release checkpoint:"),
stderr: "",
});
} else { } else {
await expect(result).rejects.toMatchObject({ await expect(result).rejects.toMatchObject({
code: 1, code: 1,
stderr: expect.stringContaining( stderr: expect.stringContaining(
"release branch moved after this run was triggered", "refusing to create a release for a moved source",
), ),
}); });
} }
@@ -188,7 +300,7 @@ it.skipIf(process.platform === "win32").each([true, false])(
.parse( .parse(
workflow.jobs["release-please"].steps.find( workflow.jobs["release-please"].steps.find(
(step) => (step) =>
step.name === "Bind publication to the triggering checkpoint", step.name === "Bind publication to the dispatched checkpoint",
)?.run, )?.run,
); );
const result = execFileAsync( const result = execFileAsync(
@@ -239,6 +351,27 @@ it("runs release PR CI without enabling implementation pushes on release branche
); );
}); });
it("checks website changes on release-branch pull requests", async () => {
const workflow = z
.object({
on: z.object({
pull_request: z.object({ branches: z.array(z.string()) }),
}),
})
.parse(
parse(
await readFile(
new URL(
"../../../.github/workflows/website-check.yml",
import.meta.url,
),
"utf8",
),
),
);
expect(workflow.on.pull_request.branches).toEqual(["main", "release/*"]);
});
// Publishing is irreversible. Keep the release authority invariant as a static // Publishing is irreversible. Keep the release authority invariant as a static
// boundary check; it is not proof that package installation or publishing works. // boundary check; it is not proof that package installation or publishing works.
it("requires package verification before publishing and retains the registry canary", async () => { it("requires package verification before publishing and retains the registry canary", async () => {