diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 7ffdc54..7d2fcfd 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -37,3 +37,35 @@ jobs: - run: bun run build - run: npm publish --access public + + github-release: + # After npm, never before: a release announcing a version that failed to + # publish points at nothing installable. Its own job so the publishing job + # keeps read-only contents, and outside the npm environment, which only + # exists to gate the trusted publisher. + needs: publish + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + + - uses: oven-sh/setup-bun@v2 + with: + bun-version: latest + + - name: Create the release from the changelog + # test/changelog.test.ts has already failed the run if the tag's section + # is missing, so this reads what that test proved is there. + env: + GH_TOKEN: ${{ github.token }} + TAG: ${{ github.ref_name }} + run: | + notes=$(bun run scripts/changelog-section.ts "${TAG#v}") + # Idempotent, so re-running the workflow after a flake is safe: a + # release that already exists is updated rather than failing the run. + if gh release view "$TAG" >/dev/null 2>&1; then + printf '%s\n' "$notes" | gh release edit "$TAG" --notes-file - + else + printf '%s\n' "$notes" | gh release create "$TAG" --title "$TAG" --notes-file - + fi diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..b61655f --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,18 @@ +# Changelog + +## 1.4.0 + +### Server instructions + +The server now sends instructions describing what it is for, so a client can +tell an agent how to use these tools without being told separately. + +### Idempotent hints + +Read-only tools are annotated as idempotent. A client that retries a failed +call can now tell which tools are safe to retry on their own. + +## Earlier versions + +Releases before 1.4.0 predate this file and have no entry here. The commit +history on GitHub is the record for those. diff --git a/scripts/changelog-section.ts b/scripts/changelog-section.ts new file mode 100644 index 0000000..62f57b7 --- /dev/null +++ b/scripts/changelog-section.ts @@ -0,0 +1,34 @@ +import { resolve } from 'node:path' + +/** + * The body under `## ` in a changelog, or null when that heading is + * absent. The release workflow feeds this to `gh release create`, and a test + * pins package.json's version to a section here, so a bump with no entry fails + * CI rather than publishing a release whose body is empty. + */ +export const section = (changelog: string, version: string): string | null => { + const escaped = version.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + const heading = new RegExp(`^## ${escaped}\\s*$`, 'm') + const start = heading.exec(changelog) + if (start === null) { + return null + } + const rest = changelog.slice(start.index + start[0].length) + const following = /^## /m.exec(rest) + return (following === null ? rest : rest.slice(0, following.index)).trim() +} + +if (import.meta.main) { + const version = Bun.argv[2] + if (version === undefined) { + console.error('usage: bun run scripts/changelog-section.ts ') + process.exit(2) + } + const ROOT = resolve(import.meta.dir, '..') + const body = section(await Bun.file(resolve(ROOT, 'CHANGELOG.md')).text(), version) + if (body === null || body === '') { + console.error(`CHANGELOG.md has no '## ${version}' section.`) + process.exit(1) + } + console.log(body) +} diff --git a/test/changelog.test.ts b/test/changelog.test.ts new file mode 100644 index 0000000..08e9fd1 --- /dev/null +++ b/test/changelog.test.ts @@ -0,0 +1,34 @@ +import { describe, it, expect } from 'bun:test' +import { resolve } from 'node:path' + +import { section } from '../scripts/changelog-section' + +const ROOT = resolve(import.meta.dir, '..') + +describe('section', () => { + it('returns null for a version the changelog does not carry', () => { + expect(section('# Changelog\n\n## 1.0.0\n\nfirst\n', '2.0.0')).toBeNull() + }) + + it('stops at the next version heading', () => { + const changelog = '# Changelog\n\n## 2.0.0\n\nsecond\n\n## 1.0.0\n\nfirst\n' + expect(section(changelog, '2.0.0')).toBe('second') + expect(section(changelog, '1.0.0')).toBe('first') + }) + + it('does not let a version read as a regex', () => { + expect(section('# Changelog\n\n## 1.0.0\n\nfirst\n', '1x0x0')).toBeNull() + }) +}) + +describe('the changelog', () => { + it('has an entry for the version being published', async () => { + // The release notes come from this section, so a bump without an entry has + // to fail here rather than publish a release with an empty body. + const pkg = JSON.parse(await Bun.file(resolve(ROOT, 'package.json')).text()) + const version = String(pkg.version) + const body = section(await Bun.file(resolve(ROOT, 'CHANGELOG.md')).text(), version) + expect(body, `CHANGELOG.md has no '## ${version}' section`).not.toBeNull() + expect(body).not.toBe('') + }) +})