From 7557fb618290637279cb78b63b6976f37d93a741 Mon Sep 17 00:00:00 2001 From: Day Dreamer <87640074+HugoXK@users.noreply.github.com> Date: Sun, 22 Nov 2026 03:08:23 +0800 Subject: [PATCH 1/3] fix(release): name the changes a tag carried but its notes assembled too early to see A release's notes are assembled once, when the release pull request is built, and nothing reads changelog.d/ again before the tag is written. Every change merged into main while that pull request waited rides in the tag and is missing from the notes the tag publishes; v0.4.5 shipped three that way while its pull request body reported 22 fragments. The publish run now reads changelog.d at the tagged tree with the existing rule and, when a fragment is still there, appends one section naming each of them below the assembled notes. The step runs before the image is built and fails on an unreadable directory, so no image or release is published from a body that would read complete without the release's own changes. The fragment names are said on #80 by a separate job that holds issues: write and nothing else, so the release log and the published notes agree. test/releaseStrandedFragments.test.ts drives the real step body out of release.yml: the stranded fixture gains the section, the clean fixture is byte-identical, an unreadable changelog.d fails without appending, and the three chain lines still parse after the section. At the base the step does not exist, so all six fail. Written-by: Fledge Platform Dev-2 --- .github/workflows/release.yml | 73 +++++++- changelog.d/1207.fixed.md | 1 + docs/deploy.md | 26 +++ scripts/lib/stranded-fragments.mjs | 35 ++++ scripts/release-stranded-notes.mjs | 59 ++++++ test/releasePublishGuard.test.ts | 10 +- test/releaseStrandedFragments.test.ts | 254 ++++++++++++++++++++++++++ 7 files changed, 453 insertions(+), 5 deletions(-) create mode 100644 changelog.d/1207.fixed.md create mode 100644 scripts/lib/stranded-fragments.mjs create mode 100644 scripts/release-stranded-notes.mjs create mode 100644 test/releaseStrandedFragments.test.ts diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f49267e1..9f21b149 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 @@ -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: @@ -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 @@ -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' }} @@ -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 @@ -447,3 +471,46 @@ 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 }} + 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="" + 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("/, 'a re-run of one tag repeats nothing') +}) From c782443de2c04358947e498b762d6187fed4a229 Mon Sep 17 00:00:00 2001 From: Day Dreamer <87640074+HugoXK@users.noreply.github.com> Date: Sun, 22 Nov 2026 08:43:59 +0000 Subject: [PATCH 2/3] fix(release): hand gh the repository for the #80 line, and drive that step in the suite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The stranded-log job runs with no checkout, and gh resolves the repository for `gh issue comment 80` from GH_REPO or a git remote: GITHUB_REPOSITORY is only an expression this file builds the API path from, not a variable gh reads. So on the night the job exists for it would have failed after the release was already published — correct notes, no line on #80, red run. The job env now sets GH_REPO to the repository, which both calls use. The suite could not see it because it only matched the job's text. Two tests now drive the Comment on #80 body with a stub gh that answers as the client does: an API path needs no repository, an issue comment without GH_REPO, --repo or a token fails. The first test posts and asserts gh received GH_REPO; the second proves a re-run of one tag posts nothing. Against the pre-fix workflow the first fails on the missing repository. Refs #1207 --- .github/workflows/release.yml | 6 ++ test/releaseStrandedFragments.test.ts | 139 +++++++++++++++++++++++++- 2 files changed, 144 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9f21b149..84d5b9f0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -491,6 +491,12 @@ jobs: 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: diff --git a/test/releaseStrandedFragments.test.ts b/test/releaseStrandedFragments.test.ts index 6ca42da8..edaa53ec 100644 --- a/test/releaseStrandedFragments.test.ts +++ b/test/releaseStrandedFragments.test.ts @@ -1,7 +1,7 @@ import test from 'node:test' import assert from 'node:assert/strict' import { spawnSync } from 'node:child_process' -import { copyFileSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs' +import { chmodSync, copyFileSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs' import { tmpdir } from 'node:os' import { dirname, join } from 'node:path' // The publish run parses the body with this script, so the test uses it too — a @@ -252,3 +252,140 @@ test('the #80 line is its own job, with issues: write and no publish scope', () assert.match(job, /gh issue comment 80/, 'the line lands on the release log') assert.match(job, //, 'a re-run of one tag repeats nothing') }) + +// The #80 job has no checkout, and `gh` resolves the repository for `gh issue +// comment` from `GH_REPO` or a git remote — `GITHUB_REPOSITORY` is not something +// gh reads; the body only uses it to build the API path. The review at +// `7557fb61` found the job failing on the one night it exists for: notes right, +// no line on #80, red run. These tests drive the step body with a stub `gh` that +// refuses an `issue comment` it cannot place, the way the client does, so the +// job's own env decides whether the line can post — a job that names no +// repository fails here instead of in production. +const COMMENT_STEP = 'Comment on #80' + +const ENV_FIXTURES: Record = { + '${{ inputs.tag || github.ref_name }}': 'v0.3.2', + '${{ needs.release.outputs.stranded }}': '999.fixed.md', + '${{ github.repository }}': 'HugoXK/fledge', + '${{ secrets.GITHUB_TOKEN }}': 'stub-token', +} + +// Env is the thing under test, so it is read out of the workflow and handed to +// the body as a runner would: job keys sit at six spaces, step keys at ten, and a +// value the test cannot stand in for is a failure, not a literal passed through. +function workflowEnv(text: string): Record { + const env: Record = {} + for (const line of text.split('\n')) { + const entry = /^ {6}(?: {4})?([A-Z][A-Z0-9_]*): (.+)$/.exec(line) + if (entry === null) continue + const value = (entry[2] ?? '').trim() + const fixture = ENV_FIXTURES[value] + assert.ok(fixture !== undefined, `the test knows what "${value}" stands for`) + env[entry[1] ?? ''] = fixture + } + return env +} + +function commentBlock(job: string): string { + const at = job.indexOf(` - name: ${COMMENT_STEP}`) + assert.notEqual(at, -1, `the stranded-log job declares the step "${COMMENT_STEP}"`) + return job.slice(at) +} + +interface CommentRun { + status: number | null + commands: string + repoSeen: string + summary: string + stderr: string +} + +function runCommentStep(apiJson: string): CommentRun { + const dir = mkdtempSync(join(tmpdir(), 'stranded-log-')) + try { + const bin = join(dir, 'bin') + mkdirSync(bin) + const commands = join(dir, 'commands') + writeFileSync(commands, '') + const repoSeen = join(dir, 'repo') + writeFileSync(repoSeen, '') + const api = join(dir, 'comments.json') + writeFileSync(api, apiJson) + // The stub answers as `gh` does: an API path needs no repository, and an + // `issue comment` without `GH_REPO`, `--repo` or a token is the failure this + // job hit in production. + const stub = [ + '#!/usr/bin/env bash', + 'printf "%s\\n" "$*" >> "$STUB_LOG"', + 'printf "%s\\n" "${GH_REPO:-}" > "$STUB_REPO"', + 'case "$1 $2" in', + ' "api --paginate") cat "$STUB_API"; exit 0 ;;', + ' "issue comment")', + ' case " $* " in *" --repo "*|*" -R "*) exit 0 ;; esac', + ' if [ -z "${GH_REPO:-}" ]; then', + ' echo "gh: could not determine base repo; set GH_REPO or --repo" >&2', + ' exit 1', + ' fi', + ' if [ -z "${GH_TOKEN:-}" ]; then', + ' echo "gh: no authentication token; set GH_TOKEN" >&2', + ' exit 4', + ' fi', + ' exit 0 ;;', + 'esac', + 'exit 0', + '', + ].join('\n') + const ghPath = join(bin, 'gh') + writeFileSync(ghPath, stub) + chmodSync(ghPath, 0o755) + const job = jobBlocks(release).get('stranded-log') + assert.ok(job !== undefined, 'release.yml carries the stranded-log job') + const block = commentBlock(job) + const summary = join(dir, 'summary.md') + writeFileSync(summary, '') + const result = spawnSync('bash', ['-euo', 'pipefail', '-c', runBody(block)], { + encoding: 'utf8', + env: { + ...process.env, + ...workflowEnv(job), + PATH: `${bin}:${process.env.PATH ?? ''}`, + GITHUB_STEP_SUMMARY: summary, + GITHUB_REPOSITORY: 'HugoXK/fledge', + STUB_LOG: commands, + STUB_REPO: repoSeen, + STUB_API: api, + }, + }) + return { + status: result.status, + commands: readFileSync(commands, 'utf8'), + repoSeen: readFileSync(repoSeen, 'utf8'), + summary: readFileSync(summary, 'utf8'), + stderr: result.stderr, + } + } finally { + rmSync(dir, { recursive: true, force: true }) + } +} + +test('the #80 job hands gh a repository, so its line can post after the release', () => { + const job = jobBlocks(release).get('stranded-log') + assert.ok(job !== undefined, 'release.yml carries the stranded-log job') + assert.match(job, /^ GH_REPO: \$\{\{ github\.repository \}\}$/m, 'the job names the repository gh must use') + const run = runCommentStep('[]') + assert.equal(run.status, 0, `the step body failed with the job's own env: ${run.stderr}`) + assert.match(run.commands, /^issue comment 80 --body /m, 'the line is posted') + assert.equal( + run.repoSeen.trim(), + 'HugoXK/fledge', + 'gh received GH_REPO — the API path carries the repository in its URL, the comment call does not', + ) + assert.match(run.summary, /^commented /m, 'the summary names what landed') +}) + +test('a re-run of one tag posts no second line on #80', () => { + const run = runCommentStep('[{"body":"\\n\\nearlier"}]') + assert.equal(run.status, 0, `the step body failed on an existing marker: ${run.stderr}`) + assert.doesNotMatch(run.commands, /^issue comment /m, 'no comment when the marker is the last line on the issue') + assert.match(run.summary, /already commented/, 'the summary says why nothing was posted') +}) From e5f58ea90b9ec41592e7bece9acd168b25ae3b13 Mon Sep 17 00:00:00 2001 From: Day Dreamer <87640074+HugoXK@users.noreply.github.com> Date: Sun, 22 Nov 2026 08:51:04 +0000 Subject: [PATCH 3/3] test(release): drive the #80 body before matching its text The review at 7557fb61 asked for a test that drives the step body rather than one that matches the job's text, so the failure a future removal produces is the one the job would produce: with the pre-fix workflow this test stops on `gh: could not determine base repo; set GH_REPO or --repo`, not on a missing string in release.yml. Refs #1207 --- test/releaseStrandedFragments.test.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/releaseStrandedFragments.test.ts b/test/releaseStrandedFragments.test.ts index edaa53ec..577d052d 100644 --- a/test/releaseStrandedFragments.test.ts +++ b/test/releaseStrandedFragments.test.ts @@ -369,11 +369,11 @@ function runCommentStep(apiJson: string): CommentRun { } test('the #80 job hands gh a repository, so its line can post after the release', () => { - const job = jobBlocks(release).get('stranded-log') - assert.ok(job !== undefined, 'release.yml carries the stranded-log job') - assert.match(job, /^ GH_REPO: \$\{\{ github\.repository \}\}$/m, 'the job names the repository gh must use') + // The behaviour first: the body is driven with the job's own env, so a job + // that names no repository fails here — on `gh: could not determine base repo` + // — instead of on the text assertion below. const run = runCommentStep('[]') - assert.equal(run.status, 0, `the step body failed with the job's own env: ${run.stderr}`) + assert.equal(run.status, 0, `the step body could not post with the job's own env: ${run.stderr}`) assert.match(run.commands, /^issue comment 80 --body /m, 'the line is posted') assert.equal( run.repoSeen.trim(), @@ -381,6 +381,9 @@ test('the #80 job hands gh a repository, so its line can post after the release' 'gh received GH_REPO — the API path carries the repository in its URL, the comment call does not', ) assert.match(run.summary, /^commented /m, 'the summary names what landed') + const job = jobBlocks(release).get('stranded-log') + assert.ok(job !== undefined, 'release.yml carries the stranded-log job') + assert.match(job, /^ GH_REPO: \$\{\{ github\.repository \}\}$/m, 'the job names the repository gh must use') }) test('a re-run of one tag posts no second line on #80', () => {