11name : Publish to NPM
22
33on :
4- workflow_call :
4+ # Manual trigger
5+ workflow_dispatch :
56 inputs :
67 snapshot :
78 description : " Publish as snapshot with dev tag"
89 required : false
910 default : false
1011 type : boolean
12+ # Triggered after other workflows complete on main
13+ # - "Release and Publish" -> publish release
14+ # - "Build and test" -> publish snapshot
15+ # We use workflow_run instead of workflow_call because npm trusted publishing
16+ # validates the calling workflow, and we want this to be the single trusted publisher.
17+ workflow_run :
18+ workflows : ["Release and Publish", "Build and test"]
19+ types : [completed]
20+ branches : [main]
1121
1222jobs :
1323 publish :
1424 runs-on : ubuntu-latest
25+ # Only run if:
26+ # - workflow_dispatch (always publish)
27+ # - workflow_run completed successfully
28+ if : >
29+ github.event_name == 'workflow_dispatch' ||
30+ (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success')
1531 permissions :
1632 contents : read
1733 id-token : write
1834 steps :
1935 - uses : actions/checkout@v4
36+ with :
37+ # For workflow_run, checkout the exact commit that triggered the workflow
38+ ref : ${{ github.event.workflow_run.head_sha || github.sha }}
2039
2140 - name : Setup Node.js
2241 uses : actions/setup-node@v4
4564 run : pnpm build
4665
4766 - name : Set snapshot version
48- if : ${{ inputs.snapshot }}
67+ if : ${{ (github.event_name == 'workflow_run' && github.event.workflow_run.name == 'Build and test') || (github.event_name == 'workflow_dispatch' && inputs.snapshot) }}
4968 run : |
5069 # We're using 0.0.0 to avoid this version to be higher than released versions.
5170 # To use it:
@@ -59,11 +78,11 @@ jobs:
5978 pnpm install --no-frozen-lockfile
6079
6180 - name : Publish to npm
62- if : ${{ !inputs.snapshot }}
81+ if : ${{ (github.event_name == 'workflow_run' && github.event.workflow_run.name == 'Release and Publish') || (github.event_name == 'workflow_dispatch' && !inputs.snapshot) }}
6382 run : pnpm -r --filter='./packages/libs/**' publish --access public --no-git-checks --provenance
6483
6584 - name : Publish snapshot to npm
66- if : ${{ inputs.snapshot }}
85+ if : ${{ (github.event_name == 'workflow_run' && github.event.workflow_run.name == 'Build and test') || (github.event_name == 'workflow_dispatch' && inputs.snapshot) }}
6786 # We use dist-tag dev for the snapshot releases, see https://docs.npmjs.com/cli/v9/commands/npm-dist-tag for more info
6887 # A snapshot MUST not be published with latest tag (omitting --tag defaults to latest) to avoid users to install snapshot releases
6988 # when using pnpm install
0 commit comments