Skip to content
Open
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
35 changes: 34 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 the publish job succeeds, 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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
Expand All @@ -27,6 +31,10 @@ 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
Expand All @@ -43,3 +51,28 @@ jobs:
else
echo "complex.md is not on npm yet; skipped"
fi
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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 the publish job succeeds, `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:** `bunx complex-md` runs the CLI on Bun, and no test ran on Bun. Under Bun 1.3.14, 827 of 830 tests passed, 2 are todo and 1 failed. The failure matched the error text of Node's engine only.

**Change:** CI has a `bun` job that runs the CLI suite under Bun 1.3.14 on Ubuntu. The hosted pages test also accepts Bun's error text for a malformed map ("No default value"); the behavior it checks is unchanged.
Expand Down
12 changes: 7 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,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`).
83 changes: 83 additions & 0 deletions cli/test/release-notes.test.js
Original file line number Diff line number Diff line change
@@ -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: \.\.\."/);
});
55 changes: 55 additions & 0 deletions scripts/release-notes.mjs
Original file line number Diff line number Diff line change
@@ -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 <version>');
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);
}
Loading