Skip to content

Commit b1237d5

Browse files
authored
Set publish.yml as the only non-reuseable publisher (#641)
1 parent b313994 commit b1237d5

File tree

4 files changed

+31
-37
lines changed

4 files changed

+31
-37
lines changed

.github/workflows/manual-publish.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

.github/workflows/publish.yml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,41 @@
11
name: Publish to NPM
22

33
on:
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

1222
jobs:
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
@@ -45,7 +64,7 @@ jobs:
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

.github/workflows/release.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,7 @@ jobs:
5858
gh release create "v${{ steps.check.outputs.version }}" \
5959
--title "Release v${{ steps.check.outputs.version }}" \
6060
--generate-notes
61-
62-
publish:
63-
needs: check-and-release
64-
if: needs.check-and-release.outputs.should_publish == 'true'
65-
permissions:
66-
contents: read
67-
id-token: write
68-
uses: ./.github/workflows/publish.yml
69-
secrets: inherit
61+
# Publishing is handled by publish.yml which uses workflow_run to trigger
62+
# after this workflow completes. We don't call it directly because npm trusted
63+
# publishing validates the calling workflow, and we want publish.yml to be the
64+
# single trusted publisher.

.github/workflows/test.yml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,7 @@ jobs:
5959
path: restatedev-restate-sdk-core.tgz
6060
retention-days: 1
6161
if-no-files-found: error
62-
63-
publish-snapshot:
64-
needs: build
65-
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
66-
permissions:
67-
contents: read
68-
id-token: write
69-
uses: ./.github/workflows/publish.yml
70-
with:
71-
snapshot: true
62+
# Snapshot publishing is handled by publish.yml which uses workflow_run to
63+
# trigger after this workflow passes on main. We don't call it directly because
64+
# npm trusted publishing validates the calling workflow, and we want publish.yml
65+
# to be the single trusted publisher.

0 commit comments

Comments
 (0)