From b925795df570664034add65a14d6bdc2d769ed72 Mon Sep 17 00:00:00 2001 From: "James L. Cowan Jr." <112015792+jameslcowan@users.noreply.github.com> Date: Thu, 12 Nov 2026 14:04:19 -0300 Subject: [PATCH] ci(release): create the GitHub release from the CHANGELOG section Problem: release.yml published to npm and left the GitHub release to a manual step that CONTRIBUTING.md described. The step was skipped 9 times: the newest GitHub release was 0.4.1 while npm had 0.11.0, and a visitor to the repository saw a project 7 releases behind its package. Change: a github-release job runs after the publish job and creates the release for the tag, or edits it on a re-run. Its notes are the version's CHANGELOG.md section, which scripts/release-notes.mjs reads from the heading `## YYYY-MM-DD X.Y.Z: summary` to the next heading, with the wrapped lines of each paragraph joined. The publish job checks that the section exists before it publishes anything. Permissions: the workflow default is contents: read; the publish job keeps id-token: write; only the new job gets contents: write. cli/test/release-notes.test.js covers the reader and fails when cli/package.json names a version with no section. CONTRIBUTING.md states the heading format. Intent: every published version has a GitHub release with real notes, with no manual step to forget. Assisted-by: Claude --- .github/workflows/release.yml | 35 +++++++++++++- CHANGELOG.md | 4 ++ CONTRIBUTING.md | 12 +++-- cli/test/release-notes.test.js | 83 ++++++++++++++++++++++++++++++++++ scripts/release-notes.mjs | 55 ++++++++++++++++++++++ 5 files changed, 183 insertions(+), 6 deletions(-) create mode 100644 cli/test/release-notes.test.js create mode 100644 scripts/release-notes.mjs diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4baa723..7f7586c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,16 +2,20 @@ # (OIDC): no token in secrets, no second factor prompt, provenance attached. # The tag must match cli/package.json, and the package must be configured on # npmjs.com with this repository and workflow as its trusted publisher. +# After both packages publish, the github-release job creates the GitHub +# release from the version's section in CHANGELOG.md. name: release on: push: tags: ['v*.*.*'] permissions: contents: read - id-token: write jobs: publish: runs-on: ubuntu-latest + permissions: + contents: read + id-token: write steps: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 @@ -27,8 +31,37 @@ jobs: mcp=$(node -p "require('./packages/complex-md-mcp/package.json').version") [ "$cli" = "$mcp" ] || { echo "cli/package.json $cli does not match complex-md-mcp/package.json $mcp"; exit 1; } [ "refs/tags/v$cli" = "$GITHUB_REF" ] || { echo "tag $GITHUB_REF does not match package version $cli"; exit 1; } + # The release notes come from this section, so a release without one + # stops here, before anything is published. + - name: CHANGELOG.md has a section for the version + run: node scripts/release-notes.mjs "${GITHUB_REF_NAME#v}" > /dev/null - run: cd cli && npm ci && npm test - run: cd packages/complex-md-mcp && npm ci && npm test - run: npm run build - run: cd cli && npm publish --access public --provenance - run: cd packages/complex-md-mcp && npm publish --access public --provenance + github-release: + needs: publish + runs-on: ubuntu-latest + # The only job that writes to the repository: it creates the release. + permissions: + contents: write + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + persist-credentials: false + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 + with: + node-version: 22 + # A re-run of this job edits the release that the first run created. + - name: create the GitHub release from CHANGELOG.md + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + run: | + node scripts/release-notes.mjs "${GITHUB_REF_NAME#v}" > "$RUNNER_TEMP/notes.md" + if gh release view "$GITHUB_REF_NAME" > /dev/null 2>&1; then + gh release edit "$GITHUB_REF_NAME" --title "complex-md ${GITHUB_REF_NAME#v}" --notes-file "$RUNNER_TEMP/notes.md" + else + gh release create "$GITHUB_REF_NAME" --verify-tag --title "complex-md ${GITHUB_REF_NAME#v}" --notes-file "$RUNNER_TEMP/notes.md" + fi diff --git a/CHANGELOG.md b/CHANGELOG.md index 05b153b..0057ad5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ format. ## Unreleased +**Intent:** the release workflow published to npm and left the GitHub release to a manual step. The newest GitHub release was 0.4.1 while npm had 0.11.0, and 9 tags had no release. + +**Change:** after both packages publish, `release.yml` creates the GitHub release for the tag with the version's `CHANGELOG.md` section as its notes. `scripts/release-notes.mjs` reads the section under `## YYYY-MM-DD X.Y.Z: summary` and joins its wrapped lines. The workflow checks that the section exists before it publishes. Only the new job may write to the repository; the publish job keeps `id-token: write` and read access. `cli/test/release-notes.test.js` covers the reader and fails when the version in `cli/package.json` has no section. + **Intent:** a key that a commit added stays in every clone of the history after a later commit deletes it, and the map had no way to show it. The bundle redaction also had its own 11 rules in code, so a second detector would drift from it. **Change:** new opt in command `complex-md exposure` (E1). It scans the tracked files and every line that a commit reachable from HEAD added (`--all-refs` for every ref, `--no-history` for the files only), with `git log -p` streamed and lockfiles, `node_modules`, `vendor` and minified files excluded in the git command. A partial clone skips the history and says so, since git would fetch each old blob. The 54 rules are data in `cli/rules/exposure.json` (53 known shapes, CWE ids, a severity, a confidence and a directive each, and 1 heuristic, `generic-assignment`, at low confidence); every quantifier is bounded and a rule names predicates, never code. The bundle redaction now uses the same rules. Output: `.complex-md/exposure-report.json` and with `--sarif` a SARIF 2.1.0 file with `partialFingerprints`; no output holds a value, only rule, path, line, commits, length, entropy and a fingerprint. `.complex-md/exposure.json` holds disabled rules, allows with a reason and an expiry compared with the commit date of HEAD, a baseline (`--baseline` writes it) and own rules; `--config-ref` reads it from a commit for CI; a comment `complex-md: allow ` allows 1 rule on its line. A finding in a test path is labelled and 1 severity step lower. `--strict` exits 1 on a new finding and 2 on a broken config. A `.gitignore` entry written before this release gets `!.complex-md/exposure.json` once. Measured on a development set of 9 snapshots of 4 public repositories with hard-coded credential advisories: 61 distinct findings (2 exact, 59 heuristic), 46 credentials, 14 unclear, 1 not, labelled by the author; every value that left a file was reported with the commit that removed it. The full history of django (35,052 commits) took 99 s, of which `git log -p` took 41 s. `cli/test/exposure.test.js`, `cli/test/exposure-rules.test.js`, `cli/test/partial-clone.test.js` and `cli/test/gitignore.test.js` cover it with fake keys built from fragments. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 899a7e8..35a7c26 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -52,8 +52,10 @@ patch, a new signal or wiring target is a minor, a breaking flag or output change is a major. A test fails if the spec version disagrees between the engine, the prompt and the spec page. -To release: add the dated entry to `CHANGELOG.md`, bump `cli/package.json`, -commit, then tag `vX.Y.Z` and push the tag. The release workflow verifies -the tag matches the package, runs the tests and the build, and publishes to -npm with provenance through trusted publishing. Create the GitHub release -from the changelog entry afterward. +To release: add the dated entry to `CHANGELOG.md` under the heading +`## YYYY-MM-DD X.Y.Z: summary`, bump `cli/package.json`, commit, then tag +`vX.Y.Z` and push the tag. The release workflow verifies the tag matches +the package and the changelog has that heading, runs the tests and the +build, and publishes to npm with provenance through trusted publishing. +After the publish, it creates the GitHub release with that changelog +section as its notes (`scripts/release-notes.mjs`). diff --git a/cli/test/release-notes.test.js b/cli/test/release-notes.test.js new file mode 100644 index 0000000..a1422e9 --- /dev/null +++ b/cli/test/release-notes.test.js @@ -0,0 +1,83 @@ +// The GitHub release notes come from CHANGELOG.md (scripts/release-notes.mjs). +// release.yml refuses to publish a version that has no section there. Runs +// only inside the repository checkout; the published CLI package has no +// scripts/ folder. +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { existsSync, readFileSync } from 'node:fs'; +import { join, dirname } from 'node:path'; +import { fileURLToPath, pathToFileURL } from 'node:url'; +import { spawnSync } from 'node:child_process'; + +const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..', '..'); +const SCRIPT = join(ROOT, 'scripts/release-notes.mjs'); +const inCheckout = existsSync(SCRIPT); +const load = () => import(pathToFileURL(SCRIPT).href); + +const CHANGELOG = `# Changelog + +## Unreleased + +**Change:** not released yet. + +## 2026-10-02 0.9.10: the tenth patch + +**Change:** ten. + +## 2026-10-01 0.9.1: the CLI reads its prompts from the repository + +**Intent:** a run failed when the +packaged copy was absent. + +**Change:** the CLI reads +\`prompts/\` first. + +### Also in 0.9.1 + +- A list item that wraps + onto a second line. +- A second item. + +## 2026-09-30 Credential shaped paths are never named + +**Change:** a section with no version. +`; + +test('the notes are the section of the version, its lines joined per paragraph', async (t) => { + if (!inCheckout) return t.skip('not a repository checkout'); + const { releaseNotes } = await load(); + assert.equal(releaseNotes(CHANGELOG, '0.9.1'), [ + '**0.9.1, 2026-10-01:** the CLI reads its prompts from the repository', + '', + '**Intent:** a run failed when the packaged copy was absent.', + '', + '**Change:** the CLI reads `prompts/` first.', + '', + '### Also in 0.9.1', + '', + '- A list item that wraps onto a second line.', + '- A second item.', + '', + ].join('\n')); +}); + +test('a version matches only its own heading, with or without the v', async (t) => { + if (!inCheckout) return t.skip('not a repository checkout'); + const { releaseNotes } = await load(); + assert.match(releaseNotes(CHANGELOG, 'v0.9.10'), /^\*\*0\.9\.10, 2026-10-02:\*\* the tenth patch\n\n\*\*Change:\*\* ten\.\n$/); + assert.ok(!releaseNotes(CHANGELOG, '0.9.1').includes('ten.'), '0.9.1 does not take the 0.9.10 section'); + assert.equal(releaseNotes(CHANGELOG, '0.9'), null); + assert.equal(releaseNotes(CHANGELOG, '1.0.0'), null); + assert.equal(releaseNotes(CHANGELOG.replace(/\n/g, '\r\n'), '0.9.10'), releaseNotes(CHANGELOG, '0.9.10'), 'CRLF reads the same'); +}); + +test('CHANGELOG.md has a release section for the version in cli/package.json', (t) => { + if (!inCheckout) return t.skip('not a repository checkout'); + const { version } = JSON.parse(readFileSync(join(ROOT, 'cli/package.json'), 'utf8')); + const r = spawnSync(process.execPath, [SCRIPT, version], { encoding: 'utf8' }); + assert.equal(r.status, 0, r.stderr); + assert.ok(r.stdout.startsWith(`**${version}, `), r.stdout.slice(0, 80)); + const missing = spawnSync(process.execPath, [SCRIPT, '99.0.0'], { encoding: 'utf8' }); + assert.equal(missing.status, 1); + assert.match(missing.stderr, /no section "## YYYY-MM-DD {2}99\.0\.0: \.\.\."/); +}); diff --git a/scripts/release-notes.mjs b/scripts/release-notes.mjs new file mode 100644 index 0000000..1ba88d2 --- /dev/null +++ b/scripts/release-notes.mjs @@ -0,0 +1,55 @@ +#!/usr/bin/env node +// The notes of a GitHub release: the CHANGELOG.md section of that version. +// A release section has the heading `## YYYY-MM-DD X.Y.Z: summary`, and +// runs to the next `## ` heading. release.yml checks that the section exists +// before it publishes, and creates the release from it after. +// +// node scripts/release-notes.mjs 0.11.0 prints the notes, or exits 1 +import { readFileSync } from 'node:fs'; +import { join, dirname } from 'node:path'; +import { fileURLToPath, pathToFileURL } from 'node:url'; + +const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..'); + +/** The notes for `version` from the text of CHANGELOG.md, or null. */ +export function releaseNotes(changelog, version) { + const lines = changelog.replace(/\r\n/g, '\n').split('\n'); + const v = version.replace(/^v/, '').replace(/\./g, '\\.'); + const head = new RegExp(`^## (\\d{4}-\\d{2}-\\d{2})\\s+${v}:\\s*(.*)$`); + const start = lines.findIndex((l) => head.test(l)); + if (start < 0) return null; + const [, date, summary] = head.exec(lines[start]); + const rest = lines.slice(start + 1); + const end = rest.findIndex((l) => l.startsWith('## ')); + const body = unwrap((end < 0 ? rest : rest.slice(0, end)).join('\n').trim()); + return `**${version.replace(/^v/, '')}, ${date}:** ${summary}\n\n${body}\n`; +} + +/* CHANGELOG.md wraps its paragraphs at about 76 characters. A release page + shows each line break, so the notes join the lines of a paragraph and + of a list item. A blank line, a heading or a new list item starts a new + line, and no line joins a heading. */ +export function unwrap(text) { + const out = []; + for (const line of text.split('\n')) { + const prev = out.length ? out[out.length - 1] : ''; + const starts = line.trim() === '' || /^\s*([-*]|\d+\.) /.test(line) || line.startsWith('#'); + if (starts || prev.trim() === '' || prev.startsWith('#')) out.push(starts ? line.trimEnd() : line.trim()); + else out[out.length - 1] = `${prev} ${line.trim()}`; + } + return out.join('\n'); +} + +if (import.meta.url === pathToFileURL(process.argv[1]).href) { + const version = process.argv[2]; + if (!version) { + console.error('usage: node scripts/release-notes.mjs '); + process.exit(2); + } + const notes = releaseNotes(readFileSync(join(ROOT, 'CHANGELOG.md'), 'utf8'), version); + if (!notes) { + console.error(`CHANGELOG.md has no section "## YYYY-MM-DD ${version.replace(/^v/, '')}: ..."`); + process.exit(1); + } + process.stdout.write(notes); +}