Skip to content
Closed
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
41 changes: 16 additions & 25 deletions .cursor/skills/release/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,40 @@
---
name: release
description: >-
Bumps package.json and jsr.json, pushes branch release/VERSION, opens a PR to
main with auto-merge, and relies on CI to publish a GitHub release after merge.
Use when the user invokes /release or /release VERSION, asks for a release PR,
or wants to ship a new semver version.
Opens a release/X.Y.Z pull request with Prepare release. Merge is manual.
After merge, CI publishes to npm and JSR and tags vX.Y.Z. Use when the user
invokes /release or /release VERSION, asks for a release PR, or wants to ship
a new semver version.
---

# Release (`/release` [VERSION])

In chat, users may type **`/release`** (patch bump) or **`/release 1.2.3`** (explicit semver). Treat that as this workflow.

## Goal

Cut a **release PR** from `release/<VERSION>` → `main` with version bumps in `package.json` and `jsr.json`. Optional **VERSION** defaults to **patch bump** from the current `package.json` version.
In chat, users may type **`/release`** (patch bump), **`/release minor`**, **`/release major`**, or **`/release 1.2.3`**. See `RELEASING.md`. Do not publish, tag, or merge unless the user asks.

## Preconditions

- Clean git working tree (no uncommitted changes).
- `git` and [`gh`](https://cli.github.com/) installed and authenticated (`gh auth login`).
- Repo default branch is `main`.
- Remote branch `release/<VERSION>` must not already exist.
- Notes are under `## Unreleased` in `CHANGELOG.md`.
- `gh` is authenticated.
- The workflow runs from `main`.

## Steps

1. **Resolve VERSION** (if the user did not pass one): read `package.json` `version`, bump **patch** (e.g. `0.2.1` → `0.2.2`).
2. **Run the automation script** from the repo root (preferred):
1. Resolve VERSION: explicit `X.Y.Z`, or `patch` / `minor` / `major`. Omitted means patch.
2. From the repo root:

```bash
npm run release:pr -- [VERSION]
gh workflow run "Prepare release" --ref main -f version=VERSION
```

Or: `node scripts/create-release-pr.mjs [VERSION]`. Omit `[VERSION]` for patch bump.

3. If the script cannot enable auto-merge, tell the user to merge the PR manually once CI passes.
3. Tell the user to merge the pull request after they have looked at the diff. Prepare release runs the version, changelog, and `npm pack` checks before it pushes, because a pull request it opens does not start `pull_request` workflows. To run pull request checks on it, close and reopen the pull request.

## After merge

Merging into `main` triggers `.github/workflows/release-on-merge.yml`, which creates GitHub release tag `v-<VERSION>` and release notes. That **published** release runs `publish.yml` (npm + JSR).

## Tag convention
`.github/workflows/publish.yml` publishes to npm and JSR with OIDC, then creates tag `vVERSION` (for example `0.4.1` → `v0.4.1`) and a GitHub Release from the changelog section.

GitHub release tag: `v-${VERSION}` (e.g. `0.2.2` → tag `v-0.2.2`), matching `publish.yml` expectations.
Tags through `v-0.4.0` keep the `v-` prefix. Leave those tags in place.

## Do not

- Commit unrelated files (e.g. stray `site/` or local-only dirs) on the release branch.
- Bump only one of `package.json` / `jsr.json`; both must match for publish.
- Enable auto-merge on the release pull request.
- Publish or tag from a workstation.
87 changes: 87 additions & 0 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Prepare release

on:
workflow_dispatch:
inputs:
version:
description: "X.Y.Z, or patch, minor, or major"
required: true
type: string

concurrency:
group: prepare-release
cancel-in-progress: false

permissions: {}

jobs:
prepare:
runs-on: ubuntu-24.04
timeout-minutes: 15
permissions:
contents: write
pull-requests: write
steps:
- name: Require main
run: test "$GITHUB_REF" = "refs/heads/main"

- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: main
persist-credentials: true

- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
package-manager-cache: false

- id: version
env:
RELEASE_VERSION: ${{ inputs.version }}
run: echo "version=$(node scripts/release.mjs plan)" >> "$GITHUB_OUTPUT"

- name: Bump package version
env:
RELEASE_VERSION: ${{ steps.version.outputs.version }}
run: npm version "$RELEASE_VERSION" --no-git-tag-version

- name: Set jsr.json version
run: node scripts/release.mjs bump

- name: Move changelog section
run: node scripts/release.mjs changelog

- name: Create release branch
env:
RELEASE_VERSION: ${{ steps.version.outputs.version }}
run: git checkout -b "release/${RELEASE_VERSION}"

- name: Check release
run: node scripts/release.mjs check

- name: Build package
run: npm pack --ignore-scripts --pack-destination "$RUNNER_TEMP"

- name: Commit and push
env:
RELEASE_VERSION: ${{ steps.version.outputs.version }}
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add package.json jsr.json package-lock.json CHANGELOG.md
git commit -m "chore(release): bump version to ${RELEASE_VERSION}"
git push --set-upstream origin "release/${RELEASE_VERSION}"

- name: Open pull request
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_VERSION: ${{ steps.version.outputs.version }}
run: |
set -euo pipefail
node scripts/release.mjs notes > "${RUNNER_TEMP}/notes.md"
gh pr create \
--base main \
--head "release/${RELEASE_VERSION}" \
--title "Release ${RELEASE_VERSION}" \
--body-file "${RUNNER_TEMP}/notes.md"
164 changes: 75 additions & 89 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,113 +1,99 @@
name: Publish

on:
release:
types: [published]
workflow_dispatch:
# GitHub does not start new workflow runs for events caused by the default
# GITHUB_TOKEN (e.g. gh release create in another workflow). After
# "Release on merge" creates a release, trigger publish here instead.
workflow_run:
workflows: [Release on merge]
types: [completed]
push:
branches: [main]

concurrency:
group: publish-${{ github.ref }}
cancel-in-progress: false

permissions: {}

jobs:
publish:
if: >-
github.event_name != 'workflow_run' ||
github.event.workflow_run.conclusion == 'success'
lookup:
runs-on: ubuntu-24.04
# Explicit job permissions: org default token scopes must not block OIDC.
# actions: write is required for setup-node's npm cache save (contents: read alone
# can restore but not reserve/write caches → "token has no writable scopes").
timeout-minutes: 15
outputs:
version: ${{ steps.pr.outputs.version }}
permissions:
contents: read
actions: write
id-token: write
pull-requests: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event_name == 'workflow_run' && 'main' || github.event_name == 'release' && github.ref || 'main' }}

- name: Decide whether to publish
id: gate
- id: pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
if [[ "${{ github.event_name }}" != "workflow_run" ]]; then
echo "publish=true" >> "${GITHUB_OUTPUT}"
exit 0
fi
VERSION="$(node -p "require('./package.json').version")"
TAG="v-${VERSION}"
if gh release view "${TAG}" --repo "${{ github.repository }}" >/dev/null 2>&1; then
echo "publish=true" >> "${GITHUB_OUTPUT}"
else
echo "No GitHub release ${TAG} yet (or release job was skipped); skipping publish."
echo "publish=false" >> "${GITHUB_OUTPUT}"
fi
ref="$(gh api "repos/${GITHUB_REPOSITORY}/commits/${GITHUB_SHA}/pulls" --jq '
[
.[]
| select(.merged_at != null and .base.ref == "main" and .head.repo.full_name == env.GITHUB_REPOSITORY)
| .head.ref
| select(test("^release/(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"))
| sub("^release/"; "")
]
| if length > 1 then error("multiple release pull requests") else (.[0] // "") end
')"
printf 'version=%s\n' "$ref" >> "$GITHUB_OUTPUT"

# Omit registry-url: setup-node otherwise sets NODE_AUTH_TOKEN to a placeholder and npm publish uses that instead of OIDC.
# Node 24 ships npm 11.x (≥11.5.1 in current LTS line). Node 22’s npm is 10.x; Corepack `prepare npm@11` does not replace
# the toolcache `npm` binary on GitHub-hosted runners, so `npm publish` stayed on 10.x and OIDC trusted publishing never ran.
- name: Setup Node
if: steps.gate.outputs.publish == 'true'
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
publish:
needs: lookup
if: success() && needs.lookup.outputs.version != ''
runs-on: ubuntu-24.04
timeout-minutes: 15
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
node-version: 24
cache: npm
persist-credentials: false

- name: Assert npm supports trusted publishing (OIDC)
if: steps.gate.outputs.publish == 'true'
run: |
set -euo pipefail
ver="$(npm --version)"
echo "npm ${ver}"
node -e "
const v = process.argv[1].split('.').map(Number);
const ok = v[0] > 11 || (v[0] === 11 && (v[1] > 5 || (v[1] === 5 && (v[2] || 0) >= 1)));
if (!ok) { console.error('npm ' + process.argv[1] + ' < 11.5.1; trusted publishing OIDC requires npm >= 11.5.1'); process.exit(1); }
" "$ver"

- name: Ensure versions match
if: steps.gate.outputs.publish == 'true'
shell: bash
run: |
set -euo pipefail
PKG_VERSION="$(node -p "require('./package.json').version")"
JSR_VERSION="$(node -p "require('./jsr.json').version")"
TAG_NAME="${{ github.event.release.tag_name }}"
if [[ -z "$TAG_NAME" ]]; then
TAG_NAME="v-${PKG_VERSION}"
fi
if [[ "$PKG_VERSION" != "$JSR_VERSION" ]]; then
echo "Version mismatch: package.json=$PKG_VERSION, jsr.json=$JSR_VERSION"
exit 1
fi
if [[ "$TAG_NAME" != "v$PKG_VERSION" && "$TAG_NAME" != "$PKG_VERSION" && "$TAG_NAME" != "v-${PKG_VERSION}" ]]; then
echo "Release tag '$TAG_NAME' does not match version '$PKG_VERSION' (expected '$PKG_VERSION', 'v$PKG_VERSION', or 'v-${PKG_VERSION}')."
exit 1
fi
# Omit registry-url. setup-node would set NODE_AUTH_TOKEN and npm would skip OIDC.
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
package-manager-cache: false

- name: Install dependencies
if: steps.gate.outputs.publish == 'true'
run: npm install --ignore-scripts --no-package-lock
- name: Check release
env:
RELEASE_HEAD_REF: release/${{ needs.lookup.outputs.version }}
run: node scripts/release.mjs check

# If NODE_AUTH_TOKEN / NPM_TOKEN are set to empty or a placeholder (repo/org Variables,
# or setup-node + registry-url), npm prefers them over OIDC and fails with ENEEDAUTH.
- name: Publish to npm
if: steps.gate.outputs.publish == 'true'
run: |
set -euo pipefail
if [[ -z "${ACTIONS_ID_TOKEN_REQUEST_URL:-}" || -z "${ACTIONS_ID_TOKEN_REQUEST_TOKEN:-}" ]]; then
echo "::error::GitHub OIDC is unavailable (missing ACTIONS_ID_TOKEN_*). Check job permissions id-token: write and repo Settings → Actions → Workflow permissions."
exit 1
fi
unset NODE_AUTH_TOKEN NPM_TOKEN
npm publish --access public --provenance
npm publish --provenance --access public

- name: Publish to JSR
if: steps.gate.outputs.publish == 'true'
run: npx jsr publish
run: npx --yes jsr@0.14.3 publish

github-release:
needs: [lookup, publish]
if: needs.lookup.outputs.version != '' && needs.publish.result == 'success'
runs-on: ubuntu-24.04
timeout-minutes: 15
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: 24
package-manager-cache: false

- name: Create GitHub release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ needs.lookup.outputs.version }}
run: |
set -euo pipefail
node scripts/release.mjs notes > "${RUNNER_TEMP}/notes.md"
gh release view "v${VERSION}" || gh release create "v${VERSION}" \
--target "$GITHUB_SHA" \
--title "v${VERSION}" \
--notes-file "${RUNNER_TEMP}/notes.md"
35 changes: 35 additions & 0 deletions .github/workflows/release-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Release check

on:
pull_request:
branches: [main]

permissions: {}

jobs:
check:
name: Release check
runs-on: ubuntu-24.04
timeout-minutes: 15
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
package-manager-cache: false

- name: Check version and changelog
env:
RELEASE_HEAD_REF: ${{ github.head_ref }}
run: node scripts/release.mjs check

- name: Test the release helper
run: node --test scripts/release.test.mjs

- name: Build package
run: npm pack --ignore-scripts --pack-destination "$RUNNER_TEMP"
Loading