From 9ff4db6447cd8fd342e4c87638df8051e1e85670 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20Andr=C3=A9?= Date: Sat, 24 Oct 2026 16:21:30 +0200 Subject: [PATCH] fix(release): take the release notes from the PR merged into main (#1129) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Problem A stable release should open with the description of its `dev → main` PR, followed by GitHub's generated change list. **v1.0.0** (and before it **v0.20.1**, whose notes were completed by hand) got only the generated list. The `Create GitHub release` step found the PR through `commits//pulls`. For the v1.0.0 merge commit, which exists only on `main` while the **default branch** is `dev`, that endpoint returned no PR, still minutes after the merge, so the notes fell back to `--generate-notes` alone. ## Fix The step now lists the closed PRs based on `main` and picks the merged one whose `merge_commit_sha` is the release commit, through `.github/scripts/release-pr-notes.cjs`. This does not depend on the default branch. A release commit without such a PR still gets the generated notes only, and the existing-release path is unchanged. ## Validation - `release-pr-notes.test.cjs` covers the matching rules (merged, base `main`, exact merge commit), a Unicode body passed through the command unchanged, and the workflow wiring. It runs with the other `.github/scripts` tests in PR Build Validation (3/3 locally). - The workflow's exact command, run against real data: | Commit | Old lookup | New lookup | | --- | --- | --- | | v1.0.0 merge (`8370937`) | empty | #1028's description (8,759 chars) | | v0.20.1 merge (`a8545a3`) | #843 (now on `dev`) | #843's description | | `dev` HEAD (no release PR) | — | empty → generated notes only | - The **v1.0.0 release notes were repaired** with the same lookup: #1028's description followed by the generated "What's Changed" list. --- .github/scripts/release-pr-notes.cjs | 22 ++++++++++++++ .github/scripts/release-pr-notes.test.cjs | 37 +++++++++++++++++++++++ .github/workflows/pr-build.yml | 2 +- .github/workflows/reusable-release.yml | 4 +-- 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 .github/scripts/release-pr-notes.cjs create mode 100644 .github/scripts/release-pr-notes.test.cjs diff --git a/.github/scripts/release-pr-notes.cjs b/.github/scripts/release-pr-notes.cjs new file mode 100644 index 000000000..273a96d93 --- /dev/null +++ b/.github/scripts/release-pr-notes.cjs @@ -0,0 +1,22 @@ +// Prints the description of the pull request whose merge produced a release commit. +// Usage: gh api "repos//pulls?state=closed&base=main&sort=updated&direction=desc&per_page=50" \ +// | node .github/scripts/release-pr-notes.cjs +// The PR is matched by merge_commit_sha: commits//pulls returned no PR for a fresh +// release merge commit, which exists only on main while the default branch is dev. + +function releasePullRequestBody(pulls, sha, base = "main") { + if (!Array.isArray(pulls)) throw new Error("Expected a pull request list") + const pull = pulls.find((entry) => entry?.merged_at && entry.base?.ref === base && entry.merge_commit_sha === sha) + return typeof pull?.body === "string" ? pull.body : "" +} + +if (require.main === module) { + const sha = process.argv[2] + if (!/^[0-9a-f]{40}$/.test(sha ?? "")) throw new Error("Pass the full merge commit SHA") + let input = "" + process.stdin.setEncoding("utf8") + process.stdin.on("data", (chunk) => { input += chunk }) + process.stdin.on("end", () => process.stdout.write(releasePullRequestBody(JSON.parse(input), sha))) +} + +module.exports = { releasePullRequestBody } diff --git a/.github/scripts/release-pr-notes.test.cjs b/.github/scripts/release-pr-notes.test.cjs new file mode 100644 index 000000000..fb9606fe0 --- /dev/null +++ b/.github/scripts/release-pr-notes.test.cjs @@ -0,0 +1,37 @@ +const assert = require("node:assert/strict") +const fs = require("node:fs") +const path = require("node:path") +const { spawnSync } = require("node:child_process") +const test = require("node:test") +const { releasePullRequestBody } = require("./release-pr-notes.cjs") + +const sha = "83709373b982908a9976247eca4616f0df8f984b" +const pull = (number, fields) => ({ number, merged_at: "2026-10-24T13:57:43Z", base: { ref: "main" }, merge_commit_sha: sha, body: `notes ${number}`, ...fields }) + +test("the release notes come from the PR merged into main by the release commit", () => { + const pulls = [ + pull(1, { merge_commit_sha: "0".repeat(40) }), + pull(2, { merged_at: null }), + pull(3, { base: { ref: "dev" } }), + pull(1028, {}), + ] + assert.equal(releasePullRequestBody(pulls, sha), "notes 1028") + assert.equal(releasePullRequestBody(pulls.slice(0, 3), sha), "", "no generated-notes-only fallback is mistaken for a PR") + assert.equal(releasePullRequestBody([pull(4, { body: null })], sha), "") + assert.throws(() => releasePullRequestBody({}, sha)) +}) + +test("the command prints the body unchanged, including Unicode and line breaks", () => { + const body = "# CodeNomad 1.0.0 — OpenCode V2\n\n- Café\n" + const result = spawnSync(process.execPath, [path.join(__dirname, "release-pr-notes.cjs"), sha], { + input: JSON.stringify([pull(1028, { body })]), encoding: "utf8", + }) + assert.equal(result.status, 0, result.stderr) + assert.equal(result.stdout, body) +}) + +test("the release workflow uses this lookup, not the default-branch-only commit association", () => { + const workflow = fs.readFileSync(path.join(__dirname, "../workflows/reusable-release.yml"), "utf8") + assert.match(workflow, /pulls\?state=closed&base=main[^\n]*\n[^\n]*node \.github\/scripts\/release-pr-notes\.cjs "\$\{GITHUB_SHA\}"/) + assert.doesNotMatch(workflow, /commits\/\$\{GITHUB_SHA\}\/pulls/) +}) diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index e060c5df6..1da053e07 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -263,7 +263,7 @@ jobs: run: node --test scripts/desktop-server-resources.test.cjs scripts/prepare-node-runtime.test.cjs packages/tauri-app/scripts/configure-updater.test.mjs packages/tauri-app/scripts/updater-artifacts.test.mjs - name: Test CI fixture diagnostics and artifact announcements - run: node --test scripts/native-fixture-diagnostics.test.mjs .github/scripts/comment-pr-artifacts.test.cjs .github/scripts/runtime-maintenance.test.cjs .github/scripts/binary-build-order.test.cjs + run: node --test scripts/native-fixture-diagnostics.test.mjs .github/scripts/comment-pr-artifacts.test.cjs .github/scripts/runtime-maintenance.test.cjs .github/scripts/binary-build-order.test.cjs .github/scripts/release-pr-notes.test.cjs - name: Test Electron client state env: diff --git a/.github/workflows/reusable-release.yml b/.github/workflows/reusable-release.yml index dbd74b9a4..ed0d5b187 100644 --- a/.github/workflows/reusable-release.yml +++ b/.github/workflows/reusable-release.yml @@ -89,8 +89,8 @@ jobs: if [ "${IS_PRERELEASE}" = "true" ]; then args+=(--prerelease) else - pr_body="$(gh api "repos/${GITHUB_REPOSITORY}/commits/${GITHUB_SHA}/pulls" \ - --jq 'map(select(.merged_at != null and .base.ref == "main")) | sort_by(.merged_at) | last | .body // ""')" + pr_body="$(gh api "repos/${GITHUB_REPOSITORY}/pulls?state=closed&base=main&sort=updated&direction=desc&per_page=50" \ + | node .github/scripts/release-pr-notes.cjs "${GITHUB_SHA}")" if [ -n "$pr_body" ]; then args+=(--notes "$pr_body") fi