Publishing to npm #231
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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@v6 | |
| with: | |
| fetch-depth: 0 | |
| fetch-tags: true | |
| - name: Enable Corepack | |
| run: corepack enable | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 'v22.16.0' | |
| cache: 'yarn' | |
| - name: Install dependencies | |
| run: yarn install --immutable | |
| - name: Generate | |
| run: yarn generate:all | |
| - name: Build | |
| run: yarn build:all | |
| # NX does not currently support publishing through yarn: https://github.com/nrwl/nx/issues/29242 | |
| # So we publish all workspaces through yarn directly | |
| - name: Publish | |
| run: | | |
| yarn config set npmAuthToken ${{ secrets.NPM_TOKEN_DA }} | |
| branch=$(git rev-parse --abbrev-ref HEAD) | |
| # For backports, we want to publish under a separate tag to avoid overriding latest | |
| npmTag="bugfix" | |
| if [[ "$branch" == "main" ]]; then | |
| npmTag="latest" | |
| fi | |
| yarn workspaces foreach --no-private -t -A --include 'core/*' --include 'sdk/*' --include 'sdk-support/*' --include 'wallet-gateway/*' --include 'examples/*' npm publish --tolerate-republish --tag $npmTag | |
| - name: Trigger Release announce | |
| uses: actions/github-script@v7 | |
| 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, | |
| }, | |
| }) |