Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions .github/RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,20 @@ produce a patch version while the changelog still displays a title containing

## Automated release train

Release Please maintains one release pull request against `master`. Every Monday
(and on manual dispatch), the release workflow requests Mergify queueing.
`release:hold` prevents queueing and merging. While the open release PR carries
`merge-ready` or `queued`, Release Please freezes its head for the queue.
On each `master` push, Release Please calculates the next version and release
notes and updates a single **Celox release tracker** issue. This planning step
creates no branch or pull request, so ordinary changes do not trigger release
PR CI. The planner uses the pinned dependency in `scripts/release-please/`;
update its package and lockfile together when upgrading Release Please.

Every Monday at 12:00 JST (and on manual dispatch), the release workflow creates
or updates the release pull request against `master` and requests Mergify queueing.
It closes the tracker with a link to the PR once preparation succeeds.
`release:hold` on the tracker postpones PR creation and queueing. After a PR
exists, put `release:hold` on that PR to prevent queueing and merging. While the
open release PR carries `merge-ready` or `queued`, Release Please freezes its
head for the queue. The push workflow only updates the issue, including while a
release PR is open; it never rewrites that PR.

The release PR uses the lightweight merge queue. After it merges,
`stage-release-candidate.yml` advances `release` to that exact merge commit.
Expand Down
46 changes: 44 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,36 @@ concurrency:
permissions: {}

jobs:
release-issue:
name: Update release issue
if: github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
# GitHub's generate-notes endpoint requires contents:write, even though
# planning does not save a release, tag, branch or commit.
contents: write
issues: write
pull-requests: read
steps:
- uses: actions/checkout@v7
- name: Install release planner
run: npm ci --ignore-scripts --prefix scripts/release-please
- name: Update release tracker without opening a pull request
env:
GH_TOKEN: ${{ github.token }}
run: node scripts/release-issue.mjs

release-please:
name: Update release pull request
name: Prepare weekly release pull request
outputs:
held: ${{ steps.release-issue.outputs.held }}
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7

# Resources created with GITHUB_TOKEN do not start follow-up workflows.
# Use an installation token so release PR checks and release-triggered
# publisher workflows run normally. Workflows permission also allows a
Expand All @@ -35,6 +61,14 @@ jobs:
permission-pull-requests: write
permission-workflows: write

- name: Check whether the release issue is held
id: release-issue
env:
GH_TOKEN: ${{ steps.release-token.outputs.token }}
run: |
held="$(node scripts/release-issue.mjs held)"
echo "held=$held" >> "$GITHUB_OUTPUT"

# Freeze the source PR as soon as queueing is requested, including while
# waiting for admission or after a dequeue. Rewriting it invalidates the
# queue's speculative trees, including those of PRs stacked behind it.
Expand All @@ -54,6 +88,7 @@ jobs:

- name: Create release or update release pull request
id: release
if: steps.release-issue.outputs.held != 'true'
uses: googleapis/release-please-action@v5
with:
token: ${{ steps.release-token.outputs.token }}
Expand All @@ -63,10 +98,17 @@ jobs:
skip-github-release: true
skip-github-pull-request: ${{ steps.release-pr.outputs.frozen == 'true' }}

- name: Close tracker after preparing the release PR
if: steps.release.outputs.prs_created == 'true'
env:
GH_TOKEN: ${{ steps.release-token.outputs.token }}
RELEASE_PR_NUMBER: ${{ fromJSON(steps.release.outputs.pr).number }}
run: node scripts/release-issue.mjs

queue-release:
name: Queue weekly release
needs: release-please
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
if: needs.release-please.outputs.held != 'true' && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch')
runs-on: ubuntu-latest
permissions:
contents: read
Expand Down
8 changes: 4 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# The xezim reference simulator for the shared test suite, pinned by
# revision so that Renovate proposes updates.
xezim = {
url = "github:aionhw/xezim/9fadb2eb4996d5b18100455e82e27f0de573fa4f";
url = "github:aionhw/xezim/e8266416d52b0bed45c0b78b8b7db39098221391";
flake = false;
};
};
Expand Down
71 changes: 71 additions & 0 deletions scripts/release-issue.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { execFileSync } from "node:child_process";
import { createRequire } from "node:module";
import { pathToFileURL } from "node:url";

export const TRACKER_TITLE = "Celox release tracker";
export const TRACKER_MARKER = "<!-- celox-release-tracker -->";

export function selectTracker(issues) {
const matches = issues.filter(issue => issue.title === TRACKER_TITLE && issue.body?.startsWith(TRACKER_MARKER));
if (matches.length > 1) throw new Error("Multiple Celox release trackers are open");
return matches[0] ?? null;
}

export async function updateReleaseIssue({ github, manifest, pullNumber }) {
const issue = selectTracker(await github.listIssues());
if (pullNumber) {
if (!/^\d+$/.test(String(pullNumber))) throw new Error("Invalid release PR number");
if (issue) await github.closeIssue(issue.number, `Release preparation continues in #${pullNumber}.`);
return;
}
// Building candidates calculates the same version and notes as Release Please,
// without creating commits, branches, pull requests, tags or releases.
const candidates = await manifest.buildPullRequests();
if (candidates.length > 1) throw new Error("Expected a single Celox release candidate");
if (candidates.length === 0) {
if (issue) await github.closeIssue(issue.number, "No unreleased changes remain.");
return;
}
const pull = candidates[0];
const body = `${TRACKER_MARKER}\n\n${pull.title.toString()}\n\nThis issue tracks the next Celox release. The release PR is created on Monday at 12:00 JST or by manually running Release Management. Apply \`release:hold\` here to postpone PR creation. Once a PR exists, apply the hold to that PR.\n\n${pull.body.notes()}`;
if (!issue) await github.createIssue(TRACKER_TITLE, body);
else if (issue.body !== body) await github.updateIssue(issue.number, body);
}

export class IssueGitHub {
constructor(repository) {
if (!/^[\w.-]+\/[\w.-]+$/.test(repository)) throw new Error("Invalid repository");
this.repository = repository;
}
run(args, input) {
return execFileSync("gh", args, { encoding: "utf8", input, maxBuffer: 10 * 1024 * 1024 });
}
api(path, payload, method = "POST") {
return JSON.parse(this.run(["api", `repos/${this.repository}/${path}`, ...(payload ? ["--method", method, "--input", "-"] : [])], payload && JSON.stringify(payload)));
}
listIssues() {
return JSON.parse(this.run(["issue", "list", "--repo", this.repository, "--state", "open", "--search", `in:title "${TRACKER_TITLE}"`, "--limit", "1000", "--json", "number,title,body,labels"]));
}
createIssue(title, body) { return this.api("issues", { title, body }); }
updateIssue(number, body) { return this.api(`issues/${number}`, { body }, "PATCH"); }
async closeIssue(number, comment) {
await this.api(`issues/${number}/comments`, { body: comment });
return this.api(`issues/${number}`, { state: "closed" }, "PATCH");
}
}

if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
const github = new IssueGitHub(process.env.GITHUB_REPOSITORY);
if (process.argv[2] === "held") {
const issue = selectTracker(await github.listIssues());
console.log(issue?.labels.some(label => label.name === "release:hold") ? "true" : "false");
} else if (process.env.RELEASE_PR_NUMBER) {
await updateReleaseIssue({ github, pullNumber: process.env.RELEASE_PR_NUMBER });
} else {
const releasePlease = createRequire(new URL("./release-please/package.json", import.meta.url))("release-please");
const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/");
const client = await releasePlease.GitHub.create({ owner, repo, token: process.env.GH_TOKEN });
const manifest = await releasePlease.Manifest.fromManifest(client, "master");
await updateReleaseIssue({ github, manifest });
}
}
97 changes: 97 additions & 0 deletions scripts/release-issue.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import assert from "node:assert/strict";
import test from "node:test";
import { readFileSync } from "node:fs";
import { IssueGitHub, selectTracker, TRACKER_MARKER, TRACKER_TITLE, updateReleaseIssue } from "./release-issue.mjs";

const tracker = (extra = {}) => ({ number: 12, title: TRACKER_TITLE, body: `${TRACKER_MARKER}\nOld notes`, labels: [], ...extra });
function fixture(issues = [], candidates = [{ title: "chore(master): release 0.13.0", body: { notes: () => "Release notes" } }]) {
const calls = [];
return {
calls,
github: {
listIssues: async () => issues,
createIssue: async (...args) => calls.push(["create", ...args]),
updateIssue: async (...args) => calls.push(["update", ...args]),
closeIssue: async (...args) => calls.push(["close", ...args]),
},
manifest: { buildPullRequests: async () => candidates },
};
}

test("pushes create one release issue with the planner's version and notes", async () => {
const f = fixture();
await updateReleaseIssue(f);
assert.equal(f.calls.length, 1);
assert.equal(f.calls[0][0], "create");
assert.equal(f.calls[0][1], TRACKER_TITLE);
assert.ok(f.calls[0][2].startsWith(TRACKER_MARKER));
assert.match(f.calls[0][2], /release 0\.13\.0/);
assert.match(f.calls[0][2], /Release notes/);
});

test("subsequent pushes edit the same held tracker and skip unchanged notes", async () => {
const f = fixture([tracker({ labels: [{ name: "release:hold" }] })]);
await updateReleaseIssue(f);
assert.equal(f.calls[0][0], "update");
assert.equal(f.calls[0][1], 12);
const body = f.calls[0][2];
f.github.listIssues = async () => [tracker({ body })];
f.calls.length = 0;
await updateReleaseIssue(f);
assert.deepEqual(f.calls, []);
});

test("does not create an empty release and closes an obsolete tracker", async () => {
const f = fixture([], []);
await updateReleaseIssue(f);
assert.deepEqual(f.calls, []);
f.github.listIssues = async () => [tracker()];
await updateReleaseIssue(f);
assert.equal(f.calls[0][0], "close");
});

test("weekly PR handoff closes the tracker without invoking the planner", async () => {
const f = fixture([tracker()]);
f.manifest.buildPullRequests = () => { throw new Error("Must not plan again"); };
await updateReleaseIssue({ ...f, pullNumber: "2716" });
assert.deepEqual(f.calls, [["close", 12, "Release preparation continues in #2716."]]);
});

test("lookup and planner failures do not overwrite or close the tracker", async () => {
for (const failLookup of [true, false]) {
const f = fixture([tracker()]);
const fail = () => { throw new Error("API unavailable"); };
if (failLookup) f.github.listIssues = fail;
else f.manifest.buildPullRequests = fail;
await assert.rejects(updateReleaseIssue(f), /API unavailable/);
assert.deepEqual(f.calls, []);
}
assert.equal(selectTracker([tracker({ body: "Unrelated issue" })]), null);
assert.throws(() => selectTracker([tracker(), tracker({ number: 13 })]), /Multiple/);
});

test("issue client uses JSON input and PATCH for updates, preserving hold labels", async () => {
const github = new IssueGitHub("celox-sim/celox");
const calls = [];
github.run = (args, input) => { calls.push([args, input]); return "{}"; };
const body = 'Literal `$(echo secret)`\nnew line';
await github.updateIssue(12, body);
assert.deepEqual(calls, [[["api", "repos/celox-sim/celox/issues/12", "--method", "PATCH", "--input", "-"], JSON.stringify({ body })]]);
});

test("push path can only update issues; weekly and manual paths create PRs and honor hold", () => {
const workflow = readFileSync(new URL("../.github/workflows/release.yml", import.meta.url), "utf8");
const preview = workflow.split(" release-issue:\n")[1].split(" release-please:\n")[0];
const prepare = workflow.split(" release-please:\n")[1].split(" queue-release:\n")[0];
assert.match(preview, /if: github.event_name == 'push'/);
assert.match(preview, /contents: write/);
assert.match(preview, /issues: write/);
assert.match(preview, /pull-requests: read/);
assert.doesNotMatch(preview, /release-please-action|release-token|pull-requests: write/);
assert.match(prepare, /if: github.event_name == 'schedule' \|\| github.event_name == 'workflow_dispatch'/);
assert.match(prepare, /if: steps.release-issue.outputs.held != 'true'/);
assert.match(prepare, /held="\$\(node scripts\/release-issue.mjs held\)"/);
assert.match(prepare, /if: steps.release.outputs.prs_created == 'true'/);
assert.match(prepare, /fromJSON\(steps.release.outputs.pr\).number/);
assert.match(workflow.split(" queue-release:\n")[1], /needs.release-please.outputs.held != 'true'/);
});
Loading
Loading