diff --git a/.github/actions/opendrs-release/action.yml b/.github/actions/opendrs-release/action.yml new file mode 100644 index 0000000..2a874fb --- /dev/null +++ b/.github/actions/opendrs-release/action.yml @@ -0,0 +1,38 @@ +name: opendrs (pinned release) +description: Runs a released opendrs on this repository's own PRs. Used only by .github/workflows/opendrs.yml. + +# The pin lives here, not in the workflow, so the "Finish a release" workflow can bump it: a +# workflow's token may not change files under .github/workflows/. opendrs.yml restores this file +# from the PR's base commit before using it, so a PR's edit to it never runs with the bot token. +inputs: + github-token: + description: Token opendrs comments, labels and approves with. + required: true + sample-salt: + description: Salt for the sampled-review hash. + required: false + default: "" +outputs: + score: + description: The PR's risk score. + value: ${{ steps.opendrs.outputs.score }} + tier: + description: The risk tier. + value: ${{ steps.opendrs.outputs.tier }} + decision: + description: The policy verdict, before the safety rails. + value: ${{ steps.opendrs.outputs.decision }} + captain: + description: The captain priority. + value: ${{ steps.opendrs.outputs.captain }} + approved: + description: true only when opendrs approved the head commit in this run. + value: ${{ steps.opendrs.outputs.approved }} +runs: + using: composite + steps: + - uses: error-path/opendrs@541a0cf40f50de3b6b7d25ddf280bc05f6e7dd81 # v0.7.1 + id: opendrs + with: + github-token: ${{ inputs.github-token }} + sample-salt: ${{ inputs.sample-salt }} diff --git a/.github/dependabot.yml b/.github/dependabot.yml index acb9c8d..f6a289a 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -12,6 +12,10 @@ updates: - package-ecosystem: docker directory: / schedule: { interval: weekly } + # Digest and patch bumps only: a new Node major is chosen by hand, and only an LTS (even) one. + ignore: + - dependency-name: node + update-types: ["version-update:semver-major"] - package-ecosystem: bundler directory: /docs schedule: { interval: weekly } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d36ee6f..a9f202e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,13 +10,13 @@ permissions: jobs: # The job id `check` gives the check names `check (22)` and `check (24)`, which the main - # ruleset requires: renaming it blocks every merge. + # ruleset requires: renaming it blocks every merge. `check (26)`, the newest LTS, is not required. check: runs-on: ubuntu-latest strategy: fail-fast: false matrix: - node: [22, 24] + node: [22, 24, 26] steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 diff --git a/.github/workflows/opendrs.yml b/.github/workflows/opendrs.yml index 5f2c4ca..f0dfa46 100644 --- a/.github/workflows/opendrs.yml +++ b/.github/workflows/opendrs.yml @@ -1,7 +1,8 @@ # Dogfood: score this repository's own PRs and approve the low-risk ones (.opendrs.yml), and # auto-merge only those that are also a captain "quick confirm", once the required checks pass. -# Runs a RELEASED action, pinned to a release commit that Dependabot bumps, never the PR's own -# copy: a PR must not be able to edit the code that decides whether to approve it. +# Runs a RELEASED action, pinned to a release commit in .github/actions/opendrs-release (bumped by +# "Finish a release"), never the PR's own copy: a PR must not be able to edit the code that +# decides whether to approve it. name: OpenDRS on: @@ -30,6 +31,12 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 # required: the score reads past commits, authors and the merge-base + # Run the pinned release from the base branch, never the PR's copy: changing a file under + # .github/actions/ needs only contents write, not the workflows permission a workflow edit needs. + - name: Use the base branch's opendrs pin + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + run: git checkout "$BASE_SHA" -- .github/actions/opendrs-release # opendrs comments, labels, approves and merges as the opendrs-bot GitHub App, not as # github-actions. The token lasts one hour, covers this repository only and is revoked when # the job ends. Fork PRs get no secrets: they fall back to GITHUB_TOKEN and are never approved. @@ -40,7 +47,9 @@ jobs: with: client-id: ${{ vars.OPENDRS_APP_CLIENT_ID }} private-key: ${{ secrets.OPENDRS_APP_PRIVATE_KEY }} - - uses: error-path/opendrs@541a0cf40f50de3b6b7d25ddf280bc05f6e7dd81 # v0.7.1 + # The release pin is in this composite action, so "Finish a release" can bump it. A pins PR + # therefore still runs the previous release; the new pin applies from the next PR. + - uses: ./.github/actions/opendrs-release id: opendrs with: github-token: ${{ steps.app-token.outputs.token || github.token }} diff --git a/.github/workflows/release-finish.yml b/.github/workflows/release-finish.yml index d134711..cb6fb6d 100644 --- a/.github/workflows/release-finish.yml +++ b/.github/workflows/release-finish.yml @@ -1,16 +1,21 @@ name: Finish a release # Run by hand after you approve a staged npm version: publishes server.json to the MCP registry, -# then pushes a branch that pins the Claude Code plugin to the version, for you to open as a PR -# (a PR opened by this workflow's token would not start CI). Only the repository owner can run it, -# and it signs in to the registry with the run's OIDC token, so no secret is stored. See -# docs/maintaining.md, "Releasing". +# moves the major tag (v0) to the release so `@v0` users get it, and opens one PR, as opendrs-bot +# so CI runs on it, that pins the Claude Code plugin and this repository's own opendrs step to the +# release. Only the repository owner can run it. The registry login uses the run's OIDC token; the +# only stored secret is the opendrs-bot key, used in the pins job alone. See docs/maintaining.md, +# "Releasing". on: workflow_dispatch: inputs: tag: description: "Release tag that npm already serves, such as v0.6.0" required: true + move-major-tag: + description: "Move the major tag (v0) to this release. Untick for a release with a breaking change: release v1 instead." + type: boolean + default: true permissions: {} @@ -112,36 +117,76 @@ jobs: "$RUNNER_TEMP/mcp-publisher" publish echo "### Published $VERSION to the MCP registry" >> "$GITHUB_STEP_SUMMARY" - plugin-pin: - name: Push the plugin pin branch + major-tag: + name: Move the major tag needs: [check, registry] + # A prerelease never moves it; untick the input for a breaking change. + if: inputs.move-major-tag && !contains(inputs.tag, '-') runs-on: ubuntu-latest permissions: - contents: write # to push the branch; the PR is opened by the owner, so CI runs on it + contents: write # to force-push the major tag env: + TAG: ${{ inputs.tag }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: refs/tags/${{ env.TAG }} + - name: Move the major tag to the release commit + run: | + MAJOR="${TAG%%.*}" # v0.7.1 -> v0 + git tag -f "$MAJOR" "$(git rev-parse "refs/tags/$TAG^{commit}")" + git push -f origin "refs/tags/$MAJOR" + echo "### Moved $MAJOR to $TAG" >> "$GITHUB_STEP_SUMMARY" + + pins: + name: Open the release pins PR + needs: [check, registry] + runs-on: ubuntu-latest + permissions: + contents: read # the push and the PR use the opendrs-bot token, so CI runs on the PR + env: + TAG: ${{ inputs.tag }} VERSION: ${{ needs.check.outputs.version }} - BRANCH: chore/plugin-pin-${{ needs.check.outputs.version }} + BRANCH: chore/release-pins-${{ needs.check.outputs.version }} REPOSITORY: ${{ github.repository }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: ref: main + fetch-depth: 0 # to read the tag's commit + persist-credentials: false - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: 24 - - name: Pin the plugin and push the branch + # release.mjs imports only Node's own modules, and nothing is installed in this job. + - name: Pin the plugin and the dogfood action + id: pin run: | node scripts/release.mjs pin-plugin "$VERSION" + node scripts/release.mjs pin-dogfood "$VERSION" "$(git rev-parse "refs/tags/$TAG^{commit}")" if git diff --quiet; then - echo "main already pins $VERSION; no branch to push." | tee -a "$GITHUB_STEP_SUMMARY" - exit 0 + echo "main already pins $VERSION; no PR to open." | tee -a "$GITHUB_STEP_SUMMARY" + echo "skip=true" >> "$GITHUB_OUTPUT" fi + - name: Mint an opendrs-bot token + id: app-token + if: steps.pin.outputs.skip != 'true' + uses: actions/create-github-app-token@f418cff399f7aef4c2f0ad47e25ca7a6abbdd6fc # v3.4.0 + with: + client-id: ${{ vars.OPENDRS_APP_CLIENT_ID }} + private-key: ${{ secrets.OPENDRS_APP_PRIVATE_KEY }} + permission-contents: write + permission-pull-requests: write + - name: Push the branch and open the PR + if: steps.pin.outputs.skip != 'true' + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + run: | git switch -c "$BRANCH" - git -c user.name="github-actions[bot]" -c user.email="41898282+github-actions[bot]@users.noreply.github.com" \ - commit -am "chore(plugin): pin @error-path/opendrs $VERSION" - git push origin "HEAD:refs/heads/$BRANCH" - { - echo "### Plugin pin branch pushed" - echo - echo "Open the PR: https://github.com/$REPOSITORY/compare/main...$BRANCH?expand=1" - } >> "$GITHUB_STEP_SUMMARY" + git -c user.name="opendrs-bot[bot]" -c user.email="344752653+opendrs-bot[bot]@users.noreply.github.com" \ + commit -am "chore(release): pin the plugin and this repository's opendrs to $VERSION" + git push "https://x-access-token:$GH_TOKEN@github.com/$REPOSITORY.git" "HEAD:refs/heads/$BRANCH" + URL=$(gh pr create --repo "$REPOSITORY" --base main --head "$BRANCH" \ + --title "chore(release): pin the plugin and this repository's opendrs to $VERSION" \ + --body "Opened by **Finish a release** for $TAG: npm serves $VERSION and the MCP registry lists it. Pins the Claude Code plugin's npx calls and the dogfood action (.github/actions/opendrs-release) to the release. Merge when CI passes.") + echo "### Pins PR opened: $URL" >> "$GITHUB_STEP_SUMMARY" diff --git a/.github/workflows/release-prepare.yml b/.github/workflows/release-prepare.yml new file mode 100644 index 0000000..abdc363 --- /dev/null +++ b/.github/workflows/release-prepare.yml @@ -0,0 +1,121 @@ +name: Prepare a release + +# Run by hand with the version to release: runs `npm run release:prepare` on main and opens the +# release PR as opendrs-bot, so CI runs on it. Read the changelog section in the PR, then merge it; +# "Tag a release" takes over from there. Only the repository owner can run it. The build job has no +# secret; the bot token is minted in a job that installs and runs no dependency. See +# docs/maintaining.md, "Releasing". +on: + workflow_dispatch: + inputs: + version: + description: "Version to release, without the v, such as 0.7.2" + required: true + +permissions: {} + +concurrency: + group: release-prepare + cancel-in-progress: false + +jobs: + build: + name: Set the version and rebuild the action + runs-on: ubuntu-latest + permissions: + contents: read + env: + VERSION: ${{ inputs.version }} + steps: + - name: Check who started the run + env: + TRIGGERING_ACTOR: ${{ github.triggering_actor }} + OWNER: ${{ github.repository_owner }} + run: | + test "$TRIGGERING_ACTOR" = "$OWNER" \ + || { echo "::error::Only $OWNER can prepare a release, not $TRIGGERING_ACTOR"; exit 1; } + - name: Check that the run is on main + env: + REF: ${{ github.ref }} + run: | + test "$REF" = "refs/heads/main" || { echo "::error::Run this from main, not $REF"; exit 1; } + - name: Check the version + run: | + # The release tag's pattern without the v; [[ =~ ]] matches the whole value. + if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then + echo "::error::'$VERSION' is not a release version like 1.2.3" + exit 1 + fi + # Both jobs check out the commit the run started on, never one the build job names. + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ github.sha }} + persist-credentials: false + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: 24 + - run: npm ci + - name: Prepare the release + run: | + node scripts/release.mjs prepare "$VERSION" + git diff --binary > "$RUNNER_TEMP/release.patch" + test -s "$RUNNER_TEMP/release.patch" || { echo "::error::release:prepare changed nothing"; exit 1; } + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: release-patch + path: ${{ runner.temp }}/release.patch + retention-days: 1 + + pull-request: + name: Open the release PR + needs: build + runs-on: ubuntu-latest + permissions: + contents: read + env: + VERSION: ${{ inputs.version }} + BRANCH: release/${{ inputs.version }} + steps: + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: release-patch + path: ${{ runner.temp }}/release + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ github.sha }} + persist-credentials: false + # Only contents and pull-requests: the patch is limited to release:prepare's files below. + - name: Mint an opendrs-bot token + id: app-token + uses: actions/create-github-app-token@f418cff399f7aef4c2f0ad47e25ca7a6abbdd6fc # v3.4.0 + with: + client-id: ${{ vars.OPENDRS_APP_CLIENT_ID }} + private-key: ${{ secrets.OPENDRS_APP_PRIVATE_KEY }} + permission-contents: write + permission-pull-requests: write + - name: Push the branch and open the PR + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + REPOSITORY: ${{ github.repository }} + run: | + git apply --index "$RUNNER_TEMP/release/release.patch" + # The build job ran npm dependencies, so accept only the files release:prepare writes. + UNEXPECTED=$(git diff --cached --name-only | grep -vxE 'package\.json|package-lock\.json|src/version\.ts|server\.json|tests/fixtures/golden-full-score\.json|CHANGELOG\.md|action/dist/.+' || true) + if [ -n "$UNEXPECTED" ]; then + echo "::error::the release patch changes files release:prepare never writes: $UNEXPECTED"; exit 1 + fi + git switch -c "$BRANCH" + git -c user.name="opendrs-bot[bot]" -c user.email="344752653+opendrs-bot[bot]@users.noreply.github.com" \ + commit -m "chore(release): $VERSION" + git push "https://x-access-token:$GH_TOKEN@github.com/$REPOSITORY.git" "HEAD:refs/heads/$BRANCH" + node scripts/release.mjs notes "$VERSION" > "$RUNNER_TEMP/notes.md" + { + echo "Prepared by the **Prepare a release** workflow (\`npm run release:prepare -- $VERSION\`)." + echo "Read the changelog section below, then merge: **Tag a release** tags the merge commit and drafts the GitHub release." + echo + echo "## Changelog" + echo + cat "$RUNNER_TEMP/notes.md" + } > "$RUNNER_TEMP/body.md" + URL=$(gh pr create --repo "$REPOSITORY" --base main --head "$BRANCH" --title "chore(release): $VERSION" --body-file "$RUNNER_TEMP/body.md") + echo "### Release PR opened: $URL" >> "$GITHUB_STEP_SUMMARY" diff --git a/.github/workflows/release-tag.yml b/.github/workflows/release-tag.yml new file mode 100644 index 0000000..43d040e --- /dev/null +++ b/.github/workflows/release-tag.yml @@ -0,0 +1,65 @@ +name: Tag a release + +# When a release PR (from "Prepare a release") lands on main, tags the merge commit vX.Y.Z and +# drafts the GitHub release with the changelog section as notes. It does not publish: the +# maintainer publishes the draft with "Publish this Action to the GitHub Marketplace" ticked (a +# form only the web page has, behind 2FA), which starts the npm publish. It never moves the major +# tag (v0): "Finish a release" does that, after npm serves the version. See docs/maintaining.md. +on: + push: + branches: [main] + paths: [package.json] + +permissions: {} + +concurrency: + group: release-tag + cancel-in-progress: false + +jobs: + tag: + name: Tag and draft the release + runs-on: ubuntu-latest + permissions: + contents: write # to push the tag and create the draft release + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 # to see existing tags + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: 24 + - name: Read the version and skip one that is already tagged + id: version + run: | + VERSION=$(node -p 'require("./package.json").version') + # Same pattern as the publish and finish workflows; [[ =~ ]] matches the whole value. + if ! [[ "v$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then + echo "::error::package.json version '$VERSION' is not a release version" + exit 1 + fi + if git rev-parse -q --verify "refs/tags/v$VERSION" > /dev/null; then + echo "v$VERSION is already tagged; nothing to do." | tee -a "$GITHUB_STEP_SUMMARY" + echo "skip=true" >> "$GITHUB_OUTPUT" + exit 0 + fi + test "$(node -p 'require("./server.json").version')" = "$VERSION" \ + || { echo "::error::server.json's version is not $VERSION"; exit 1; } + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + - name: Tag the commit and draft the release + if: steps.version.outputs.skip != 'true' + env: + VERSION: ${{ steps.version.outputs.version }} + GH_TOKEN: ${{ github.token }} + run: | + node scripts/release.mjs notes "$VERSION" > "$RUNNER_TEMP/notes.md" + git tag "v$VERSION" "$GITHUB_SHA" + git push origin "refs/tags/v$VERSION" + PRERELEASE=() + [[ "$VERSION" == *-* ]] && PRERELEASE=(--prerelease) + URL=$(gh release create "v$VERSION" --draft --verify-tag --title "v$VERSION" --notes-file "$RUNNER_TEMP/notes.md" "${PRERELEASE[@]}") + { + echo "### Tagged v$VERSION and drafted the release" + echo + echo "Publish it with **Publish this Action to the GitHub Marketplace** ticked: $URL" + } >> "$GITHUB_STEP_SUMMARY" diff --git a/CHANGELOG.md b/CHANGELOG.md index 525286b..a4e3f73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,17 @@ All notable changes to opendrs. Versions follow [Semantic Versioning](https://semver.org/). +## Unreleased + +### Changed + +- Releases run mostly in GitHub Actions: **Prepare a release** opens the release PR, **Tag a + release** tags the merge and drafts the GitHub release, and **Finish a release** also moves the + major tag and opens one PR that pins the plugin and this repository's own opendrs step. The + maintainer still reads and merges the PRs, publishes the draft (Marketplace) and approves npm. +- The Docker image is back on an LTS Node (`node:24-slim`; Node 25 reached end-of-life on 1 June + 2026), Dependabot no longer proposes new Node majors for it, and CI also runs on Node 26. + ## 0.7.1 - 2026-11-27 ### Added diff --git a/Dockerfile b/Dockerfile index b0074ec..2ae1841 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,14 @@ # The opendrs MCP server over stdio, for registries that build and introspect it (Glama) and for # running it in a container. Mount the repository to score at /repo: docker run -i -v "$PWD:/repo" ... -# Base images are pinned by digest (multi-arch index); Dependabot bumps them. -FROM node:25-slim@sha256:81db02c4b671288a03915da9534dbd54f96d0e7c24d80ccc54f5b36b2e684370 AS build +# Base images are pinned by digest (multi-arch index) to an LTS Node; Dependabot bumps the digest, +# not the major (see .github/dependabot.yml). +FROM node:24-slim@sha256:873f586f3794f52281bd039bf02c048a0be08fde619338f9941bad1eb6b34530 AS build WORKDIR /app COPY package.json package-lock.json tsconfig.json tsconfig.build.json ./ COPY src ./src RUN npm ci --ignore-scripts && npm run build -FROM node:25-slim@sha256:81db02c4b671288a03915da9534dbd54f96d0e7c24d80ccc54f5b36b2e684370 +FROM node:24-slim@sha256:873f586f3794f52281bd039bf02c048a0be08fde619338f9941bad1eb6b34530 # opendrs reads history and diffs with git. RUN apt-get update && apt-get install -y --no-install-recommends git ca-certificates && rm -rf /var/lib/apt/lists/* WORKDIR /app diff --git a/docs/maintaining.md b/docs/maintaining.md index a6133e5..bc296df 100644 --- a/docs/maintaining.md +++ b/docs/maintaining.md @@ -29,46 +29,55 @@ A short runbook for the maintainer. ## Releasing -1. On a branch from `main`, run `npm run release:prepare -- 0.7.0`. It sets the version in - `package.json`, `package-lock.json`, `src/version.ts`, both fields of `server.json` and the - golden score fixture, renames `## Unreleased` in `CHANGELOG.md` to the dated release, and - rebuilds `action/dist`. Read the changelog section, run `npm run check`, and open the PR. -2. Merge that PR. -3. Tag the release and move the major tag (from a network that allows pushes): - - ```sh - git checkout main && git pull - git tag v0.2.0 && git tag -f v0 - git push origin v0.2.0 && git push -f origin v0 - ``` - - This repository's own dogfood (`.github/workflows/opendrs.yml`) pins the action by commit, so - it does not follow `v0`: bump its SHA and `# vX.Y.Z` comment in a PR, or merge Dependabot's. - -4. Create a GitHub release from the tag with the changelog section as notes, with **Publish this - Action to the GitHub Marketplace** ticked: that is what updates the Marketplace listing from - `action.yml`. The form refuses a `description` of 125 characters or more (a test in - `tests/action/workflows.test.ts` checks this), and GitHub asks for your 2FA code to publish. - Publishing starts the **Publish to npm** workflow (`publish.yml`), which stages the package on - npm (see below). +Most of a release runs in GitHub Actions. You do only the steps that need your judgement or your +2FA code: starting it, reading and merging the release PR, publishing the draft release, approving +npm, and finishing. + +1. Under **Actions**, open **Prepare a release** (`release-prepare.yml`), choose **Run workflow** + and give the version, such as `0.7.2`. Only the repository owner can run it. Its first job runs + `npm run release:prepare` on `main` with no secret: that sets the version in `package.json`, + `package-lock.json`, `src/version.ts`, both fields of `server.json` and the golden score + fixture, renames `## Unreleased` in `CHANGELOG.md` to the dated release, and rebuilds + `action/dist`. Its second job installs nothing, refuses a patch that touches any other file, and + opens the release PR as opendrs-bot, so CI runs on it. Before you run it, make sure the + `## Unreleased` section says what the release ships. +2. Read the changelog section in the PR and merge it when CI passes. The self-modification guard + never auto-approves it (it changes `action/dist`), so you merge it. +3. **Tag a release** (`release-tag.yml`) runs on that merge: it tags the merge commit `vX.Y.Z` and + drafts the GitHub release with the changelog section as notes. A push to `main` whose + `package.json` version is already tagged does nothing. +4. Open the draft from the run's summary or the **Releases** page, tick **Publish this Action to + the GitHub Marketplace** (only the web form has it), and publish with your 2FA code. That + updates the Marketplace listing from `action.yml`; the form refuses a `description` of 125 + characters or more (a test in `tests/action/workflows.test.ts` checks this). Publishing starts + the **Publish to npm** workflow (`publish.yml`), which stages the package on npm (see below). 5. When that run passes, approve the staged version on npmjs.com, in the package's - **Staged Packages** tab, with your 2FA code. Then check that - `npm view @error-path/opendrs version` shows the release. -6. Under **Actions**, open **Finish a release**, choose **Run workflow** and give the tag, such as - `v0.7.0` (`release-finish.yml`; only the repository owner can run it). It checks that npm - serves the version, publishes `server.json` to the MCP registry with the run's OIDC token, and - pushes a `chore/plugin-pin-` branch made by `node scripts/release.mjs pin-plugin`. The - registry checks that the npm package's `mcpName` matches `server.json`'s `name`, so it must run - after npm has the version. A re-run skips a version the registry already lists. -7. Open the plugin pin PR from the link in the run's summary, and merge it when CI passes. You open - it, not the workflow, because a PR opened with the workflow's token would not start CI. The - plugin directory follows `main`, so a pin merged before npm has the version would point at a - version that does not exist yet. - - If the workflow cannot run, do steps 6 and 7 by hand: `mcp-publisher login github` and - `mcp-publisher publish` from the tag, then `node scripts/release.mjs pin-plugin 0.7.0` on a - branch and open the PR. To move to a newer mcp-publisher, update `PUBLISHER_VERSION` and - `PUBLISHER_SHA256` (the release's `mcp-publisher_linux_amd64.tar.gz` digest) together. + **Staged Packages** tab, with your 2FA code. +6. Under **Actions**, open **Finish a release** (`release-finish.yml`), choose **Run workflow** and + give the tag, such as `v0.7.2`. Only the repository owner can run it. It checks that npm serves + the version, publishes `server.json` to the MCP registry with the run's OIDC token (a re-run + skips a version the registry already lists), moves the major tag (`v0`) to the release, and + opens one PR as opendrs-bot that pins the Claude Code plugin (`pin-plugin`) and this + repository's own opendrs step (`pin-dogfood`, in `.github/actions/opendrs-release/action.yml`) + to the release. Untick **Move the major tag** for a release with a breaking change; a + prerelease never moves it. The registry checks that the npm package's `mcpName` matches + `server.json`'s `name`, so this must run after npm has the version. +7. Merge the pins PR when CI passes. The plugin directory follows `main`, so a pin merged before + npm has the version would point at a version that does not exist yet; that is why it comes + last. The dogfood pin is in a composite action rather than in `opendrs.yml` because a + workflow's token may not change files under `.github/workflows/`. + + If a workflow cannot run, every step still works by hand: `npm run release:prepare -- 0.7.2` on + a branch and a PR; `git tag v0.7.2 && git push origin v0.7.2` after the merge; + `git tag -f v0 v0.7.2 && git push -f origin v0`; `mcp-publisher login github` and + `mcp-publisher publish` from the tag; and `node scripts/release.mjs pin-plugin 0.7.2` plus + `node scripts/release.mjs pin-dogfood 0.7.2 ` on a branch and a PR. To move to a + newer mcp-publisher, update `PUBLISHER_VERSION` and `PUBLISHER_SHA256` (the release's + `mcp-publisher_linux_amd64.tar.gz` digest) together. + + **Prepare a release** and **Finish a release** push and open PRs with the opendrs-bot app + (`OPENDRS_APP_CLIENT_ID`, `OPENDRS_APP_PRIVATE_KEY`), with a token narrowed to contents and pull + requests, because a PR opened with the workflow's own token would not start CI. 8. Refresh the directory listings that are not driven by the registry: on [Glama](https://glama.ai/mcp/servers) (configured by `glama.json`) and on [mcp.so](https://mcp.so/servers/opendrs), sign in as a maintainer and check that the listing diff --git a/scripts/release.d.mts b/scripts/release.d.mts index f7cc99a..cc3269c 100644 --- a/scripts/release.d.mts +++ b/scripts/release.d.mts @@ -1,2 +1,4 @@ export function bumpVersion(rootDir: string, newVersion: string, releaseDate: string): string[]; export function pinPlugin(rootDir: string, version: string): string[]; +export function pinDogfood(rootDir: string, version: string, commit: string): string[]; +export function releaseNotes(rootDir: string, version: string): string; diff --git a/scripts/release.mjs b/scripts/release.mjs index fb23836..f44b23f 100644 --- a/scripts/release.mjs +++ b/scripts/release.mjs @@ -1,7 +1,7 @@ #!/usr/bin/env node -// Release edits, run by the maintainer (`npm run release:prepare -- 0.7.0`) and by the -// "Finish a release" workflow (`node scripts/release.mjs pin-plugin 0.7.0`). See -// docs/maintaining.md, "Releasing". +// Release edits, run by the "Prepare a release" workflow or the maintainer +// (`npm run release:prepare -- 0.7.0`), by "Tag a release" (`notes 0.7.0`) and by "Finish a +// release" (`pin-plugin 0.7.0`, `pin-dogfood 0.7.0 `). See docs/maintaining.md, "Releasing". import { spawnSync } from "node:child_process"; import { readFileSync, writeFileSync } from "node:fs"; import { join, resolve } from "node:path"; @@ -13,6 +13,12 @@ const VERSION_PATTERN = /^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$/; /** Files that pin the npm package for plugin installs. */ const PLUGIN_FILES = ["plugin/.claude-plugin/plugin.json", "plugin/commands/opendrs-review.md", "plugin/skills/opendrs/SKILL.md"]; +/** The composite action that runs a released opendrs on this repository's own PRs. */ +const DOGFOOD_FILE = ".github/actions/opendrs-release/action.yml"; + +/** The dogfood action's pin: a full commit SHA, then the release tag as a comment. */ +const DOGFOOD_PIN_PATTERN = /error-path\/opendrs@[0-9a-f]{40} # v[0-9A-Za-z.-]+/g; + /** * Throws unless `version` is a release version. * @@ -117,8 +123,47 @@ export function pinPlugin(rootDir, version) { ); } +/** + * Pins this repository's own opendrs step to a release commit. The pin lives in a composite action, + * not in a workflow, because a workflow's token may not change files under `.github/workflows/`. + * + * @param rootDir - The repository root. + * @param version - The released version, written as the `# vX.Y.Z` comment. + * @param commit - The full SHA of the release tag's commit. + * @returns The changed files, relative to the root; empty when the pin is already this commit. + * @throws {@link Error} If the version or commit is invalid, or the file pins no release commit. + */ +export function pinDogfood(rootDir, version, commit) { + assertVersion(version); + if (!/^[0-9a-f]{40}$/.test(commit)) throw new Error(`'${commit}' is not a full commit SHA`); + return applyEdits(rootDir, { + [DOGFOOD_FILE]: (text) => { + if (!text.match(DOGFOOD_PIN_PATTERN)) throw new Error(`${DOGFOOD_FILE} pins no opendrs release commit`); + return text.replace(DOGFOOD_PIN_PATTERN, `error-path/opendrs@${commit} # v${version}`); + }, + }); +} + +/** + * Reads a released version's changelog section, for the GitHub release's notes. + * + * @param rootDir - The repository root. + * @param version - The version whose `## X.Y.Z - date` section to read. + * @returns The section's text without its heading, trimmed. + * @throws {@link Error} If the version is invalid, or the changelog has no non-empty section for it. + */ +export function releaseNotes(rootDir, version) { + assertVersion(version); + const lines = readFileSync(join(rootDir, "CHANGELOG.md"), "utf8").split(/\r?\n/); + const start = lines.findIndex((line) => line === `## ${version}` || line.startsWith(`## ${version} `)); + const end = lines.findIndex((line, index) => index > start && line.startsWith("## ")); + const notes = start < 0 ? "" : lines.slice(start + 1, end < 0 ? undefined : end).join("\n").trim(); + if (!notes) throw new Error(`CHANGELOG.md has no section for ${version}`); + return notes; +} + if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) { - const [command, version] = process.argv.slice(2); + const [command, version, commit] = process.argv.slice(2); try { if (command === "prepare") { const changed = bumpVersion(process.cwd(), version ?? "", new Date().toISOString().slice(0, 10)); @@ -130,8 +175,13 @@ if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1] } else if (command === "pin-plugin") { const changed = pinPlugin(process.cwd(), version ?? ""); console.log(changed.length ? `Pinned ${version} in:\n ${changed.join("\n ")}` : `The plugin already pins ${version}.`); + } else if (command === "pin-dogfood") { + const changed = pinDogfood(process.cwd(), version ?? "", commit ?? ""); + console.log(changed.length ? `Pinned ${version} in:\n ${changed.join("\n ")}` : `The dogfood action already pins ${version}.`); + } else if (command === "notes") { + console.log(releaseNotes(process.cwd(), version ?? "")); } else { - console.error("Usage: node scripts/release.mjs prepare | pin-plugin "); + console.error("Usage: node scripts/release.mjs prepare | pin-plugin | pin-dogfood | notes "); process.exit(2); } } catch (error) { diff --git a/tests/action/release-finish-workflow.test.ts b/tests/action/release-finish-workflow.test.ts index 195e71b..476caf7 100644 --- a/tests/action/release-finish-workflow.test.ts +++ b/tests/action/release-finish-workflow.test.ts @@ -28,13 +28,36 @@ describe("finish-a-release workflow", () => { } }); - it("gives each job only the permissions it needs, and uses no stored secret", () => { + it("gives each job only the permissions it needs", () => { expect(workflow.permissions).toEqual({}); expect(jobs.check!.permissions).toEqual({ contents: "read" }); expect(jobs.registry!.permissions).toEqual({ contents: "read", "id-token": "write" }); - // Pushing a branch only: a PR opened with this token would not start CI. - expect(jobs["plugin-pin"]!.permissions).toEqual({ contents: "write" }); - expect(text).not.toMatch(/secrets\./); + expect(jobs["major-tag"]!.permissions).toEqual({ contents: "write" }); + // The pins PR is pushed and opened with the opendrs-bot token, so CI runs on it. + expect(jobs.pins!.permissions).toEqual({ contents: "read" }); + }); + + it("uses the opendrs-bot key only in the pins job, for a token narrowed to contents and pull requests", () => { + for (const [jobId, job] of Object.entries(jobs)) { + if (jobId !== "pins") expect(JSON.stringify(job)).not.toMatch(/secrets\./); + } + const mint = jobs.pins!.steps.find((step) => step.uses?.startsWith("actions/create-github-app-token@"))!; + expect(mint.with).toMatchObject({ "permission-contents": "write", "permission-pull-requests": "write" }); + // Nothing is installed next to the token: no npm ci or npm install in the job. + expect(jobs.pins!.steps.map((step) => step.run ?? "").join("\n")).not.toMatch(/npm (ci|install)/); + }); + + it("moves the major tag only when asked, never for a prerelease, after the registry publish", () => { + const majorTag = jobs["major-tag"] as Job & { if: string }; + expect(majorTag.if).toBe("inputs.move-major-tag && !contains(inputs.tag, '-')"); + expect(majorTag.needs).toEqual(["check", "registry"]); + expect(workflow.on.workflow_dispatch.inputs["move-major-tag"]).toMatchObject({ type: "boolean", default: true }); + }); + + it("pins the plugin and the dogfood action to the release tag's commit", () => { + const runs = jobs.pins!.steps.map((step) => step.run ?? "").join("\n"); + expect(runs).toContain('node scripts/release.mjs pin-plugin "$VERSION"'); + expect(runs).toContain('node scripts/release.mjs pin-dogfood "$VERSION" "$(git rev-parse "refs/tags/$TAG^{commit}")"'); }); it("never puts an expression inside a shell script, where a value could run as code", () => { diff --git a/tests/action/release-prepare-tag-workflows.test.ts b/tests/action/release-prepare-tag-workflows.test.ts new file mode 100644 index 0000000..407d0a9 --- /dev/null +++ b/tests/action/release-prepare-tag-workflows.test.ts @@ -0,0 +1,98 @@ +import { describe, expect, it } from "vitest"; +import { readFileSync } from "node:fs"; +import { parse } from "yaml"; + +type Step = { name?: string; uses?: string; run?: string; with?: Record }; +type Job = { needs?: string | string[]; permissions: Record; steps: Step[] }; + +/** Reads a file relative to the repository root. */ +const read = (path: string) => readFileSync(new URL(`../../${path}`, import.meta.url), "utf8"); +/** Every step of every job in a parsed workflow. */ +const stepsOf = (jobs: Record) => Object.values(jobs).flatMap((job) => job.steps); + +const prepare = parse(read(".github/workflows/release-prepare.yml")); +const prepareJobs: Record = prepare.jobs; +const tag = parse(read(".github/workflows/release-tag.yml")); +const tagJobs: Record = tag.jobs; + +describe("both release workflows", () => { + it.each([ + ["prepare", prepareJobs], + ["tag", tagJobs], + ])("%s pins every action to a full commit sha and puts no expression inside a shell script", (_name, jobs) => { + for (const step of stepsOf(jobs)) { + if (step.uses) expect(step.uses).toMatch(/^[\w.-]+\/[\w.-]+@[0-9a-f]{40}$/); + expect(step.run ?? "").not.toContain("${{"); + } + }); + + it("grant nothing at the top level", () => { + expect(prepare.permissions).toEqual({}); + expect(tag.permissions).toEqual({}); + }); +}); + +describe("prepare-a-release workflow", () => { + it("runs only by hand, and refuses anyone but the repository owner first", () => { + expect(Object.keys(prepare.on)).toEqual(["workflow_dispatch"]); + expect(prepareJobs.build!.steps[0]!.run).toMatch(/test "\$TRIGGERING_ACTOR" = "\$OWNER"/); + expect(prepareJobs["pull-request"]!.needs).toBe("build"); + }); + + it("builds with no secret and a read-only token, and mints the bot token only in a job that installs nothing", () => { + expect(prepareJobs.build!.permissions).toEqual({ contents: "read" }); + expect(JSON.stringify(prepareJobs.build)).not.toMatch(/secrets\./); + expect(prepareJobs["pull-request"]!.permissions).toEqual({ contents: "read" }); + const runs = prepareJobs["pull-request"]!.steps.map((step) => step.run ?? "").join("\n"); + expect(runs).not.toMatch(/npm (ci|install)/); + const mint = prepareJobs["pull-request"]!.steps.find((step) => step.uses?.startsWith("actions/create-github-app-token@"))!; + expect(mint.with).toMatchObject({ "permission-contents": "write", "permission-pull-requests": "write" }); + }); + + it("accepts only the files release:prepare writes from the build job's patch", () => { + const runs = prepareJobs["pull-request"]!.steps.map((step) => step.run ?? "").join("\n"); + expect(runs.indexOf("grep -vxE")).toBeGreaterThan(runs.indexOf("git apply")); + expect(runs.indexOf("grep -vxE")).toBeLessThan(runs.indexOf("git push")); + }); +}); + +describe("tag-a-release workflow", () => { + it("runs on pushes to main that change package.json, with only contents write", () => { + expect(tag.on).toEqual({ push: { branches: ["main"], paths: ["package.json"] } }); + expect(tagJobs.tag!.permissions).toEqual({ contents: "write" }); + expect(read(".github/workflows/release-tag.yml")).not.toMatch(/secrets\./); + }); + + it("drafts the release and never publishes it or moves the major tag", () => { + const runs = stepsOf(tagJobs).map((step) => step.run ?? "").join("\n"); + expect(runs).toMatch(/gh release create "v\$VERSION" --draft/); + expect(runs).not.toMatch(/git tag -f|push -f/); + }); +}); + +describe("prepare-a-release checkouts", () => { + it("runs only on main, and both jobs check out the run's own commit, never one the build job names", () => { + expect(prepareJobs.build!.steps[1]!.run).toContain('test "$REF" = "refs/heads/main"'); + for (const job of Object.values(prepareJobs)) { + const checkout = job.steps.find((step) => step.uses?.startsWith("actions/checkout@"))!; + expect(checkout.with).toMatchObject({ ref: "${{ github.sha }}", "persist-credentials": false }); + } + }); +}); + +describe("the dogfood workflow", () => { + const steps: Step[] = parse(read(".github/workflows/opendrs.yml")).jobs.opendrs.steps; + + it("restores the pinned composite action from the PR's base commit before it runs", () => { + const restore = steps.findIndex((step) => step.run === 'git checkout "$BASE_SHA" -- .github/actions/opendrs-release'); + const mint = steps.findIndex((step) => step.uses?.startsWith("actions/create-github-app-token@")); + const opendrs = steps.findIndex((step) => step.uses === "./.github/actions/opendrs-release"); + expect(restore).toBeGreaterThan(0); + expect(restore).toBeLessThan(mint); + expect(mint).toBeLessThan(opendrs); + }); + + it("pins the composite's opendrs step to a full release commit", () => { + expect(read(".github/actions/opendrs-release/action.yml")).toMatch(/uses: error-path\/opendrs@[0-9a-f]{40} # v\d+\.\d+\.\d+/); + }); +}); diff --git a/tests/action/workflows.test.ts b/tests/action/workflows.test.ts index 78ae166..ed0315d 100644 --- a/tests/action/workflows.test.ts +++ b/tests/action/workflows.test.ts @@ -60,12 +60,13 @@ describe("workflows that run the Action", () => { it("CI keeps the job id `check` that the main ruleset's required checks name", () => { const check = parse(read(".github/workflows/ci.yml")).jobs.check; - expect(check.strategy.matrix.node).toEqual([22, 24]); + // 22 and 24 are the required checks; 26, the newest LTS, runs too but is not required. + expect(check.strategy.matrix.node).toEqual([22, 24, 26]); // A job name would replace `check (22)` and `check (24)` as the check names. expect(check.name).toBeUndefined(); }); - it.each(["ci", "codeql", "opendrs", "pages", "publish", "scorecard"])("this repo's %s workflow and its jobs have descriptive names", (file) => { + it.each(["ci", "codeql", "opendrs", "pages", "publish", "release-finish", "release-prepare", "release-tag", "scorecard"])("this repo's %s workflow and its jobs have descriptive names", (file) => { const wf = parse(read(`.github/workflows/${file}.yml`)); // A set name, not GitHub's default (the bare file name), which says little in the Actions tab. expect(wf.name).toMatch(/[A-Z]/); diff --git a/tests/scripts/release.test.ts b/tests/scripts/release.test.ts index 9af43e7..954d04a 100644 --- a/tests/scripts/release.test.ts +++ b/tests/scripts/release.test.ts @@ -2,10 +2,17 @@ import { afterEach, beforeEach, describe, expect, it } from "vitest"; import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { dirname, join } from "node:path"; -import { bumpVersion, pinPlugin } from "../../scripts/release.mjs"; +import { bumpVersion, pinDogfood, pinPlugin, releaseNotes } from "../../scripts/release.mjs"; let rootDir: string; +/** The release commit the dogfood action pins before each test. */ +const OLD_COMMIT = "a".repeat(40); +/** A release commit to pin. */ +const NEW_COMMIT = "0123456789abcdef0123456789abcdef01234567"; +/** The dogfood action's path under the repository root. */ +const DOGFOOD_FILE = ".github/actions/opendrs-release/action.yml"; + /** Writes `content` to `relativePath` under the temporary repository root. */ const writeRepoFile = (relativePath: string, content: string) => { const path = join(rootDir, relativePath); @@ -31,6 +38,7 @@ beforeEach(() => { writeRepoFile("plugin/.claude-plugin/plugin.json", '{\n "version": "0.5.2",\n "args": ["-y", "@error-path/opendrs@0.5.2", "mcp"]\n}\n'); writeRepoFile("plugin/commands/opendrs-review.md", "Run !`npx @error-path/opendrs@0.5.2 brief`.\n"); writeRepoFile("plugin/skills/opendrs/SKILL.md", "npx @error-path/opendrs@0.5.2 score\nnpx @error-path/opendrs@0.5.2 brief\n"); + writeRepoFile(DOGFOOD_FILE, `runs:\n steps:\n - uses: error-path/opendrs@${OLD_COMMIT} # v0.5.2\n`); }); afterEach(() => rmSync(rootDir, { recursive: true, force: true })); @@ -103,3 +111,42 @@ describe("pinPlugin", () => { expect(() => pinPlugin(rootDir, "0.6.0 && id")).toThrow(/not a version/); }); }); + +describe("pinDogfood", () => { + it("pins this repository's own opendrs step to the release commit, with the tag as a comment", () => { + expect(pinDogfood(rootDir, "0.6.0", NEW_COMMIT)).toEqual([DOGFOOD_FILE]); + expect(readRepoFile(DOGFOOD_FILE)).toBe(`runs:\n steps:\n - uses: error-path/opendrs@${NEW_COMMIT} # v0.6.0\n`); + expect(pinDogfood(rootDir, "0.6.0", NEW_COMMIT)).toEqual([]); + }); + + it("refuses a commit that is not a full SHA, and a value that is not a version", () => { + expect(() => pinDogfood(rootDir, "0.6.0", "v0.6.0")).toThrow(/not a full commit SHA/); + expect(() => pinDogfood(rootDir, "0.6.0", NEW_COMMIT.slice(0, 7))).toThrow(/not a full commit SHA/); + expect(() => pinDogfood(rootDir, "0.6.0 && id", NEW_COMMIT)).toThrow(/not a version/); + }); + + it("refuses to run when the file pins no release commit, and changes nothing", () => { + writeRepoFile(DOGFOOD_FILE, "runs:\n steps: []\n"); + expect(() => pinDogfood(rootDir, "0.6.0", NEW_COMMIT)).toThrow(/pins no opendrs release commit/); + expect(readRepoFile(DOGFOOD_FILE)).toBe("runs:\n steps: []\n"); + }); +}); + +describe("releaseNotes", () => { + it("returns the version's changelog section without its heading", () => { + writeRepoFile("CHANGELOG.md", "# Changelog\n\n## 0.6.0 - 2026-11-20\n\n### Fixed\n\n- A bug.\n\n## 0.5.2 - 2026-11-12\n\n- Old.\n"); + expect(releaseNotes(rootDir, "0.6.0")).toBe("### Fixed\n\n- A bug."); + expect(releaseNotes(rootDir, "0.5.2")).toBe("- Old."); + }); + + it("does not match a longer version that starts the same way, and reads CRLF files", () => { + writeRepoFile("CHANGELOG.md", "## 0.6.10 - 2026-11-20\r\n\r\n- Ten.\r\n\r\n## 0.6.1 - 2026-11-19\r\n\r\n- One.\r\n"); + expect(releaseNotes(rootDir, "0.6.1")).toBe("- One."); + }); + + it("refuses a version with no section, or an empty one", () => { + expect(() => releaseNotes(rootDir, "9.9.9")).toThrow(/no section for 9\.9\.9/); + writeRepoFile("CHANGELOG.md", "## 0.6.0 - 2026-11-20\n\n## 0.5.2 - 2026-11-12\n"); + expect(() => releaseNotes(rootDir, "0.6.0")).toThrow(/no section for 0\.6\.0/); + }); +});