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
32 changes: 32 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
34 changes: 34 additions & 0 deletions scripts/changelog-section.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { resolve } from 'node:path'

/**
* The body under `## <version>` 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 <version>')
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)
}
34 changes: 34 additions & 0 deletions test/changelog.test.ts
Original file line number Diff line number Diff line change
@@ -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('')
})
})
Loading