From f9f5f060073a7fe17c5fd234d7b2348fa4becc9e Mon Sep 17 00:00:00 2001 From: Andrew Wessels Date: Fri, 27 Nov 2026 11:51:47 -1000 Subject: [PATCH] ci(release): publish prereleases as next; add move-next dispatch Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 90 ++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c00ca25..13c3ea0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,10 +3,30 @@ name: Release # Publishes @diffbot/pi to npm via trusted publishing (OIDC; no NPM_TOKEN). # Triggered by pushing a version tag (e.g. v0.4.0). workflow_dispatch runs the # gates and `npm publish --dry-run` only; the publish job runs for tag pushes. +# A version containing "-" (e.g. 0.4.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. @@ -17,6 +37,8 @@ concurrency: jobs: verify: name: Verify and dry-run + # 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: @@ -51,7 +73,13 @@ jobs: # The package ships TypeScript sources (extensions/, skills/), so there # is no build step. - name: Publish dry run - run: npm publish --dry-run --access public + run: | + set -euo pipefail + version=$(node -p "require('./package.json').version") + # Prereleases (0.4.1-rc.0) go to the "next" dist-tag, never "latest". + dist_tag=latest + case "$version" in *-*) dist_tag=next ;; esac + npm publish --dry-run --access public --tag "$dist_tag" publish: name: Publish to npm and GitHub @@ -80,7 +108,14 @@ jobs: # No token: npm authenticates via the trusted publisher configured on # npmjs.com (org diffbot, repo diffbot-pi, workflow release.yml). - name: Publish to npm - run: npm publish --access public --provenance + run: | + set -euo pipefail + version=$(node -p "require('./package.json').version") + # Prereleases (0.4.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 --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 @@ -112,3 +147,54 @@ jobs: else gh release create "$GITHUB_REF_NAME" --title "$GITHUB_REF_NAME" --generate-notes --verify-tag 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 ')"