Skip to content

Publishing to npm

Publishing to npm #589

Workflow file for this run

name: Publish packages
run-name: Publishing to npm
on:
push:
branches:
- main
- 'backport/**'
workflow_dispatch:
permissions:
contents: read
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: read
actions: write
# Only publish on actual release merges (the release script opens PRs titled "chore(release): ...",
# and squash merges typically preserve that as the HEAD commit message on the base branch).
# `workflow_dispatch` remains available for maintainers to run publishing manually if needed.
if: |
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'push' && contains(github.event.head_commit.message, 'chore(release):'))
steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v7.0.0
with:
fetch-depth: 0
fetch-tags: true
- name: Install pnpm and Node.js
uses: pnpm/setup@c9883cc79df532ad1a7b81bf9ab944ceb090d65c # v2.0.0
with:
runtime: node@24
cache: true
- name: Generate
run: pnpm run generate:all
- name: Build
run: pnpm run build:all
- name: Publish
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN_DA }}" > .npmrc
branch=$(git rev-parse --abbrev-ref HEAD)
# Export so the inner bash script can read it
export NPM_TAG="bugfix"
if [[ "$branch" == "main" ]]; then
export NPM_TAG="latest"
fi
# Use pnpm exec to evaluate each filtered package directory
pnpm -r \
--filter "core/**" \
--filter "sdk/**" \
--filter "wallet-gateway/**" \
--filter "examples/**" \
exec bash -c '
PKG_NAME=$(node -p "require(\"./package.json\").name")
PKG_VER=$(node -p "require(\"./package.json\").version")
PKG_PRIVATE=$(node -p "require(\"./package.json\").private ? \"true\" : \"false\"")
if [ "$PKG_PRIVATE" = "true" ]; then
echo "⏭️ ${PKG_NAME} is private. Skipping."
exit 0
fi
# Ask the registry if this exact version exists
PUBLISHED_VER=$(npm view "${PKG_NAME}@${PKG_VER}" version 2>/dev/null || echo "")
if [ "$PUBLISHED_VER" == "$PKG_VER" ]; then
echo "⏭️ ${PKG_NAME}@${PKG_VER} already published. Skipping."
else
echo "🚀 Publishing ${PKG_NAME}@${PKG_VER}..."
# We execute pnpm publish locally inside the package directory
pnpm publish --tag $NPM_TAG --no-git-checks
fi
'
- name: Trigger Release announce
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
PUBLISH_RUN_URL: ${{ format('{0}/{1}/actions/runs/{2}', github.server_url, github.repository, github.run_id) }}
REF_NAME: ${{ github.ref_name }}
with:
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'release-announce.yml',
ref: context.ref,
inputs: {
publish_run_id: String(context.runId),
publish_run_url: process.env.PUBLISH_RUN_URL,
ref_name: process.env.REF_NAME,
sha: context.sha,
},
})