Skip to content
Open
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: 41 additions & 0 deletions .github/scripts/publish-npm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash

# Publish the npm package for a release tag. Called by the publish-npm job of
# .github/workflows/release-on-tag.yml.
#
# Checks that the tag matches package.json, then publishes. Pre-releases
# (e.g. 2.7.0-rc.1) go to the `next` dist-tag so `npm install` keeps getting
# the stable version.
#
# Reads from the environment: RELEASE_TAG, NODE_AUTH_TOKEN (until trusted
# publishing is configured), DRY_RUN (set to 1 to run `npm publish --dry-run`).
#
# Run locally: RELEASE_TAG=2.6.0 DRY_RUN=1 .github/scripts/publish-npm.sh

set -euo pipefail

cd "$(dirname "$0")/../.."

package_version=$(jq -r '.version' package.json)
if [ "$RELEASE_TAG" != "$package_version" ]; then
echo "Tag $RELEASE_TAG does not match package.json version $package_version"
exit 1
fi

if [[ "$RELEASE_TAG" == *-* ]]; then
dist_tag=next
else
dist_tag=latest
fi

publish_flags=(--tag "$dist_tag")
# provenance can only be generated inside GitHub Actions
if [ -n "${GITHUB_ACTIONS:-}" ]; then
publish_flags+=(--provenance)
fi
Comment on lines +32 to +35

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be verified

if [ "${DRY_RUN:-}" = 1 ]; then
publish_flags+=(--dry-run)
fi

npm ci
npm publish "${publish_flags[@]}"
22 changes: 22 additions & 0 deletions .github/workflows/release-on-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,25 @@ jobs:
git commit -a -m "Set new development version: $NEW_VERSION"
git push --set-upstream origin bump-version-to-$NEW_VERSION
git gh pr create --title "Bump Version to $NEW_VERSION" --body "Bump Version to $NEW_VERSION" --label "bump-version-pr" --head "bump-version-to-$NEW_VERSION" --base main

publish-npm:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # lets npm verify this workflow (trusted publishing + provenance)

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 24 # ships npm 11.5.1 or newer, which trusted publishing needs
registry-url: https://registry.npmjs.org

- name: Publish to npm
env:
RELEASE_TAG: ${{ github.ref_name }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # only until trusted publishing is configured
run: .github/scripts/publish-npm.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ node_modules
samples/invalid-fablo-config.json
.DS_Store
dist
version.json
Loading
Loading