fix(release): take the release notes from the PR merged into main (#1129)
Some checks are pending
Publish help / build (push) Waiting to run
Publish help / deploy (push) Blocked by required conditions

## 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/<sha>/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.
This commit is contained in:
Pascal André 2026-10-24 16:21:30 +02:00 • committed by GitHub
parent 036a008c2c
commit 9ff4db6447
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 62 additions and 3 deletions

22
.github/scripts/release-pr-notes.cjs vendored Normal file
View file

@ -0,0 +1,22 @@
// Prints the description of the pull request whose merge produced a release commit.
// Usage: gh api "repos/<repo>/pulls?state=closed&base=main&sort=updated&direction=desc&per_page=50" \
// | node .github/scripts/release-pr-notes.cjs <merge commit sha>
// The PR is matched by merge_commit_sha: commits/<sha>/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 }

View file

@ -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/)
})

View file

@ -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:

View file

@ -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