Skip to content
Merged
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
79 changes: 76 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ jobs:
pull-requests: read
id-token: write
attestations: write
# #1207: the fragment names the notes had missed, for the release log line
# the `stranded-log` job below posts. Empty when this tag stranded nothing.
outputs:
stranded: ${{ steps.stranded.outputs.names }}
steps:
# #861: this job holds `contents: write`, `packages: write`,
# `id-token: write` and `attestations: write`, and the next step runs
Expand All @@ -65,7 +69,7 @@ jobs:
- name: Verify the changelog section
env:
RELEASE_TAG: ${{ inputs.tag || github.ref_name }}
run: node scripts/changelog.mjs notes "$RELEASE_TAG" > /tmp/release-notes.md
run: node scripts/changelog.mjs notes "$RELEASE_TAG" > "${RUNNER_TEMP}/release-notes.md"

- name: Verify the version and tag
env:
Expand Down Expand Up @@ -187,6 +191,26 @@ jobs:
;;
esac

# #1207: the notes above were assembled when the release pull request was
# built, and the fold that did it is the only reader of `changelog.d` — so
# every change merged into `main` while that pull request waited rides in
# this tag and is missing from the notes it publishes. The checkout here is
# the tag, so a fragment still in `changelog.d` is by construction one of
# those changes: it is named in the body before the body is published.
#
# This runs before the image is built on purpose. An unreadable
# `changelog.d` fails the step and the run, and no image or release is
# published from a body that would read complete without the release's own
# changes; `fragmentNames` throws rather than answering zero (#548).
- name: Name the changes that merged after the notes were assembled
id: stranded
if: ${{ steps.guard.outputs.published != 'true' }}
env:
RELEASE_TAG: ${{ inputs.tag || github.ref_name }}
run: |
set -euo pipefail
node scripts/release-stranded-notes.mjs "$RELEASE_TAG" "${RUNNER_TEMP}/release-notes.md"

# #183: stamp the image so /healthz on the published tag names the commit
# it was cut from. The tag checkout is not necessarily github.sha, so the
# commit comes from the checked-out tree, the same way docs/deploy.md
Expand Down Expand Up @@ -381,7 +405,7 @@ jobs:
echo "Image: ${IMAGE}:${RELEASE_TAG}@${DIGEST}"
echo "SBOM: https://github.com/${GITHUB_REPOSITORY}/releases/download/${RELEASE_TAG}/sbom.spdx.json"
echo "Attestation: ${DIGEST}"
} >> /tmp/release-notes.md
} >> "${RUNNER_TEMP}/release-notes.md"

- name: Create the GitHub release
if: ${{ steps.guard.outputs.published != 'true' }}
Expand Down Expand Up @@ -418,7 +442,7 @@ jobs:
echo "::error::${RELEASE_TAG} gained a GitHub Release while this run was publishing (${STATE}); refusing to rewrite it"
exit 1
fi
gh release create "$RELEASE_TAG" --title "$RELEASE_TAG" --notes-file /tmp/release-notes.md
gh release create "$RELEASE_TAG" --title "$RELEASE_TAG" --notes-file "${RUNNER_TEMP}/release-notes.md"

# #883 item 4: the SBOM is a Release asset, so it outlives the run that
# made it. The body wrote its download URL before the release existed; this
Expand Down Expand Up @@ -447,3 +471,52 @@ jobs:
set -euo pipefail
# `verify-release` takes the bare X.Y.Z; the tag carries the leading v.
node scripts/verify-release.mjs --version "${RELEASE_TAG#v}"

# #1207 step 3: the published notes and the release log on #80 have to agree
# about what a tag carried. The publish job reports the fragment names it
# appended; this job says them on #80. It is a separate job with `issues:
# write` alone because the publish job's token holds `contents: write`,
# `packages: write`, `id-token: write` and `attestations: write` and must not
# gain a scope it never uses. It runs only after a publish that named
# something: an ordinary night leaves it skipped, and a tag that already has a
# release never reaches the step that fills the output.
stranded-log:
name: name the stranded changes on #80
needs: release
if: ${{ needs.release.outputs.stranded != '' }}
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
issues: write
env:
RELEASE_TAG: ${{ inputs.tag || github.ref_name }}
STRANDED: ${{ needs.release.outputs.stranded }}
# gh resolves the repository for `gh issue comment` from GH_REPO or a git
# remote; `GITHUB_REPOSITORY` is an expression this file builds the API path
# from, not a variable gh reads, and this job has no checkout. Without this
# the comment fails after the release is already published: notes right,
# #80 line missing, run red (#1207 review).
GH_REPO: ${{ github.repository }}
steps:
- name: Comment on #80
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
# The marker carries the tag and the fragment set, so a re-run of one
# tag repeats nothing, and a later release with the same fragments is
# still its own line.
MARKER="<!-- stranded-notes:${RELEASE_TAG}:${STRANDED} -->"
LAST_LINE="$(gh api --paginate "repos/${GITHUB_REPOSITORY}/issues/80/comments?per_page=100" \
| jq -s -r 'flatten | map(.body | split("\n") | first) | map(select(startswith("<!-- stranded-notes:"))) | last // ""')"
if [ "$LAST_LINE" = "$MARKER" ]; then
echo "already commented ${MARKER}" >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
BODY="$(printf '%s\n' \
"$MARKER" \
"Written-by: HugoXK" \
"" \
"\`${RELEASE_TAG}\` shipped changes its notes were assembled too early to name; the [published notes](https://github.com/${GITHUB_REPOSITORY}/releases/tag/${RELEASE_TAG}) now list them: ${STRANDED} (#1207).")"
gh issue comment 80 --body "$BODY"
echo "commented ${MARKER} on #80" >> "$GITHUB_STEP_SUMMARY"
1 change: 1 addition & 0 deletions changelog.d/1207.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A release's notes now name every change its tag carries: a change merged into `main` while the release pull request waited is listed in a final section of the published notes, and the release log names the fragments that arrived that way.
26 changes: 26 additions & 0 deletions docs/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,32 @@ branches` ruleset (`bypass_actors: []`), and relaxing that is a ruleset edit, no
a commit. The runbook is still: delete or adopt the branch after adding the
identity to the ruleset bypass, then let the next run tag the merge.

### Naming the changes a release carried but its notes did not (#1207)

A release's notes are assembled once, when the release pull request is built:
`node scripts/changelog.mjs release` folds every fragment it can see and deletes
it, and nothing reads `changelog.d/` again before the tag is written. Every
change merged into `main` while that pull request waited for its merge click is
therefore carried by the tag and missing from the notes the tag publishes —
v0.4.5 shipped three that way while its pull request body said "changelog
fragments: 22".

The publish run now checks the checkout at the tag before it builds anything. A
fragment still present in `changelog.d/` there is by construction a change the
release does not name, so `scripts/release-stranded-notes.mjs` appends one
section to the assembled body that lists each of them and says why it arrived
late; the three chain lines (`Image:`, `SBOM:`, `Attestation:`) are appended
after it and read exactly as before. The step fails, and the image is never
built, when `changelog.d` cannot be read: a body that reads complete without the
release's own changes is worse than no body. The fragment names are then said on
#80 by a separate job that holds `issues: write` and nothing else, so the release
log and the published notes agree.

Nothing else moves: the same tag, image and `CHANGELOG.md`; no push to `main`,
no second release, no re-tag. A stranded fragment is still folded into the next
release's section, so a change can be named twice until the fold itself is
reworked.

### Automatic tag deployment and verification

The release plan → release pull request → tag half lives in
Expand Down
35 changes: 35 additions & 0 deletions scripts/lib/stranded-fragments.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// #1207: a release's notes are assembled once, when the release pull request is
// built — `scripts/changelog.mjs release` folds every fragment it can see and
// deletes them — and nothing reads `changelog.d/` again before the tag is
// written. So every change merged into `main` while that pull request waited is
// carried by the tag and missing from the notes that tag publishes, and its
// fragment is left in the tree to be folded into a later release as though it
// had shipped then. v0.4.5 shipped three changes that way.
//
// The publish run checks out the tag, so a fragment still present in
// `changelog.d/` there is by construction a change this release carries and its
// notes were assembled too early to name. This module is the one place that
// turns that set into the text the notes gain, so the workflow, the tests and
// the #80 line cannot describe the same change differently.

export const STRANDED_HEADING = '## Changes that merged after these notes were assembled'

/**
* The section a release's notes gain for the fragments the fold could not see.
*
* @param {{ name: string, body: string }[]} fragments - sorted, as `fragmentNames` returns them.
* @returns {string} markdown to append, or '' when nothing was stranded.
*/
export function strandedSection(fragments) {
if (fragments.length === 0) return ''
const entries = fragments.map((fragment) => `- ${fragment.body}`)
return [
'',
STRANDED_HEADING,
'',
'These changes merged into `main` while this release waited to be merged, so the tag ships them even though the notes above were assembled before they arrived. They are part of this release:',
'',
...entries,
'',
].join('\n')
}
59 changes: 59 additions & 0 deletions scripts/release-stranded-notes.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env node
// #1207: name the changes a release's notes were assembled too early to see.
//
// node scripts/release-stranded-notes.mjs <tag> <notes-file>
//
// The publish job checks the tag out, and the notes were assembled when the
// release pull request was built. A fragment still present in `changelog.d/` at
// the tag is by construction a change the release carries and its notes do not
// name, so this appends one section that names each of them and writes the
// fragment names to $GITHUB_OUTPUT for the release log line on #80.
//
// An unreadable `changelog.d` fails the step: a body that reads complete is
// worse than no body, and `fragmentNames` throws instead of answering zero
// (#548).

import { appendFileSync, readFileSync } from 'node:fs'
import { join } from 'node:path'
import { fragmentNames } from './lib/changelog-fragments.mjs'
import { strandedSection } from './lib/stranded-fragments.mjs'

const [, , rawTag, notesFile] = process.argv
if (rawTag === undefined || rawTag === '' || notesFile === undefined || notesFile === '') {
console.error('usage: node scripts/release-stranded-notes.mjs <tag> <notes-file>')
process.exit(1)
}
const tag = rawTag.startsWith('v') ? rawTag : `v${rawTag}`

// The notes the publish path already assembled are the body this section is
// appended to. An empty or missing file means the section would become a body
// that reads complete without naming the release's own changes, so it is a
// failure rather than a new file.
const notes = readFileSync(notesFile, 'utf8')
if (notes.trim() === '') {
console.error(`release-stranded-notes: ${notesFile} is empty; refusing to write a body that omits the release's own notes`)
process.exit(1)
}

const names = fragmentNames()
const fragments = names.map((name) => ({ name, body: readFileSync(join('changelog.d', name), 'utf8').trim() }))

if (process.env.GITHUB_STEP_SUMMARY !== undefined) {
appendFileSync(
process.env.GITHUB_STEP_SUMMARY,
fragments.length === 0
? `${tag}: no stranded change — the notes name everything the tag carries\n`
: `${tag}: ${fragments.length} stranded change(s), named in the notes: ${names.join(', ')}\n`,
)
}
if (process.env.GITHUB_OUTPUT !== undefined) {
appendFileSync(process.env.GITHUB_OUTPUT, `names=${names.join(',')}\n`)
}

if (fragments.length === 0) {
console.log(`${tag}: no stranded change`)
process.exit(0)
}

appendFileSync(notesFile, strandedSection(fragments))
console.log(`${tag}: ${fragments.length} stranded change(s) named in ${notesFile}: ${names.join(', ')}`)
10 changes: 8 additions & 2 deletions test/releasePublishGuard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ const LOOKUP = 'scripts/lib/release-lookup.mjs'
function stepBlocks(workflow: string): string[] {
const start = workflow.indexOf(' steps:\n')
assert.notEqual(start, -1, 'release.yml has a steps list')
return workflow
.slice(start + ' steps:\n'.length)
// #1207 added a second job (`stranded-log`, which posts the #80 line), so the
// publish job's steps end where the next two-space job key begins. The list
// below is still exactly the publish job's steps: the guard assertions that
// read it are unchanged.
const rest = workflow.slice(start + ' steps:\n'.length)
const nextJob = rest.search(/\n {2}[A-Za-z0-9_-]+:\s*\n/)
const steps = nextJob === -1 ? rest : rest.slice(0, nextJob)
return steps
.split(/\n - /)
.map((block, index) => (index === 0 ? block : `- ${block}`))
.filter((block) => block.trim() !== '')
Expand Down
Loading
Loading