Skip to content
Merged
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
83 changes: 81 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,30 @@ name: Release

# Builds the package and publishes it to npm. Triggered by pushing a version
# tag (e.g. v0.2.1); also runnable manually for dry runs (build-only — the
# publish job is gated on an actual tag push).
# publish job is gated on an actual tag push). A version containing "-" (e.g.
# 0.2.1-rc.0) is a prerelease: it publishes under the "next" dist-tag, so
# "latest" is untouched. A dispatch with action "move-next" only re-points
# `next` at an already-published version (see the move-next job).
on:
push:
tags: ["v*"]
workflow_dispatch:
inputs:
action:
description: >-
dry-run: run the release gates and a publish dry run (publishes nothing).
move-next: ONLY point the npm `next` dist-tag at an already-published
version; no build, no publish, no GitHub Release.
type: choice
options: [dry-run, move-next]
default: dry-run
version:
description: >-
move-next only: the already-published version `next` should point at
(e.g. 1.2.3 or 1.2.4-rc.0). Empty = the current `latest`.
type: string
required: false
default: ""

# Never cancel an in-flight run: cancelling a publish midway could leave npm
# and the GitHub Release out of sync. Runs for the same ref queue instead.
Expand All @@ -17,6 +36,8 @@ concurrency:
jobs:
build:
name: Build package
# A move-next dispatch runs only the move-next job below.
if: github.event_name != 'workflow_dispatch' || inputs.action != 'move-next'
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
Expand Down Expand Up @@ -100,7 +121,14 @@ jobs:
# package.json's prepublishOnly calls pnpm/tsup, absent in this job.
- name: Publish to npm
working-directory: package
run: npm publish --access public --provenance --ignore-scripts
run: |
set -euo pipefail
version=$(node -p 'require("./package.json").version')
# Prereleases (0.2.1-rc.0) go to the "next" dist-tag, never "latest".
dist_tag=latest
case "$version" in *-*) dist_tag=next ;; esac
echo "Publishing ${version} with dist-tag ${dist_tag} via npm trusted publishing."
npm publish --access public --provenance --ignore-scripts --tag "$dist_tag"

# A final release also moves `next`, so `next` is never behind `latest`.
# Uses npm trusted publishing (OIDC) for `npm dist-tag`, which needs npm
Expand Down Expand Up @@ -143,3 +171,54 @@ jobs:
--generate-notes \
package/dist/*
fi

# Manual only (action: move-next). Points `next` at a version that is already
# on npm, e.g. after a final release whose "Point next at final release" step
# warned, or to repair a `next` that fell behind `latest`. It never builds,
# publishes or touches GitHub Releases. It lives in release.yml because the
# package's npm trusted publisher is bound to this workflow file; `npm
# dist-tag` over OIDC needs npm >= 11.21.0 / 12.2.0 and "Allow npm dist-tag"
# enabled on that trusted publisher.
move-next:
name: Move npm next dist-tag
if: github.event_name == 'workflow_dispatch' && inputs.action == 'move-next'
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
id-token: write # npm trusted publishing (OIDC) for `npm dist-tag`
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-node@v4
with:
node-version: 22
registry-url: https://registry.npmjs.org
- name: Update npm
run: |
npm install -g npm@latest
npm --version
- name: Point next at an existing version
env:
INPUT_VERSION: ${{ inputs.version }}
run: |
set -euo pipefail
name=$(node -p 'require("./package.json").name')
echo "Before: $(npm view "$name" dist-tags --json | tr -d '\n ')"
version="${INPUT_VERSION}"
if [ -z "$version" ]; then
version=$(npm view "$name" dist-tags.latest)
echo "No version given; using the current latest: ${version}"
fi
if ! printf '%s' "$version" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$'; then
echo "::error::'${version}' is not a version like 1.2.3 or 1.2.3-rc.0."
exit 1
fi
if ! npm view "${name}@${version}" version >/dev/null 2>&1; then
echo "::error::${name}@${version} is not on npm; move-next only retags published versions."
exit 1
fi
# Trusted publishing (OIDC) only; no token is exported.
npm dist-tag add "${name}@${version}" next
echo "After: $(npm view "$name" dist-tags --json | tr -d '\n ')"
Loading