Skip to content

Commit 3bbfa08

Browse files
authored
ci: dispatch publish as a top-level run for trusted publishing (#7)
* ci: dispatch publish as a top-level run for trusted publishing The auto-publish called publish.yml as a reusable workflow, so the run's entry workflow was release-please.yml. npm trusted publishing matches the top-level (entry) workflow, which is configured as publish.yml, so the reusable call was rejected (404) while a manual workflow_dispatch worked. release-please now dispatches publish.yml via 'gh workflow run' once a release is cut, so the publish runs as its own top-level run with publish.yml as the entry. The GITHUB_TOKEN can trigger workflow_dispatch (the documented exception to the no-recursive-runs rule), so no PAT is needed. publish.yml drops the now-unused workflow_call trigger. * chore: drop the release-as bootstrap now that 2.0.0 is published release-as forced the first release to 2.0.0; with 2.0.0 out, leaving it would make every later release PR keep proposing 2.0.0. Versions are now computed from Conventional Commits as usual.
1 parent cc1c123 commit 3bbfa08

3 files changed

Lines changed: 19 additions & 25 deletions

File tree

.github/workflows/publish.yml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
name: Publish to npm
22

33
on:
4-
# Manual publish, with a choice of dist-tag (for prereleases etc.).
4+
# The only trigger. Used both for a manual publish (with a dist-tag choice) and
5+
# for the automatic publish, which release-please.yml fires via
6+
# `gh workflow run` after it cuts a release. Either way this workflow is the
7+
# run's entry point, which is what npm trusted publishing matches against.
58
workflow_dispatch:
69
inputs:
710
dist_tag:
@@ -14,18 +17,6 @@ on:
1417
- beta
1518
- next
1619

17-
# Called by release-please.yml right after it cuts a release, so merging the
18-
# `chore(main): release X.Y.Z` PR publishes automatically. A reusable-workflow
19-
# call (rather than `on: release`) is used because a Release created with the
20-
# default GITHUB_TOKEN does not trigger event-based workflows.
21-
workflow_call:
22-
inputs:
23-
dist_tag:
24-
description: 'npm dist-tag to publish under'
25-
type: string
26-
default: latest
27-
required: false
28-
2920
jobs:
3021
publish:
3122
runs-on: ubuntu-latest

.github/workflows/release-please.yml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ name: Release Please
22

33
# Maintains a "release PR" that bumps the version and updates CHANGELOG.md from
44
# Conventional Commits as they land on master. Merging that PR creates the git
5-
# tag (vX.Y.Z) and the GitHub Release, and then publishes to npm via the publish
6-
# workflow (called below only when a release was actually created).
5+
# tag (vX.Y.Z) and the GitHub Release, then triggers the publish workflow.
76
on:
87
push:
98
branches:
@@ -26,15 +25,20 @@ jobs:
2625
# from the repo root.
2726
token: ${{ secrets.GITHUB_TOKEN }}
2827

29-
# Runs only when the previous job just cut a release (i.e. the release PR was
30-
# merged). Calls the publish workflow as a reusable workflow so npm publishing
31-
# stays defined in one place (publish.yml) and keeps OIDC trusted publishing.
32-
publish:
28+
# Runs only when the previous job just cut a release. It dispatches publish.yml
29+
# rather than calling it as a reusable workflow, so the publish run's *entry*
30+
# workflow is publish.yml itself: npm trusted publishing matches the top-level
31+
# workflow, so it must be the entry, not a called sub-workflow. A GITHUB_TOKEN
32+
# cannot trigger release/push events, but workflow_dispatch is the documented
33+
# exception, so no PAT is needed.
34+
trigger-publish:
3335
needs: release-please
3436
if: ${{ needs.release-please.outputs.release_created == 'true' }}
37+
runs-on: ubuntu-latest
3538
permissions:
36-
id-token: write
37-
contents: read
38-
uses: ./.github/workflows/publish.yml
39-
with:
40-
dist_tag: latest
39+
actions: write
40+
steps:
41+
- name: Dispatch the publish workflow
42+
env:
43+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
run: gh workflow run publish.yml --repo "${{ github.repository }}" --ref "${{ github.ref_name }}" -f dist_tag=latest

release-please-config.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"changelog-path": "CHANGELOG.md",
77
"include-component-in-tag": false,
88
"include-v-in-tag": true,
9-
"release-as": "2.0.0",
109
"changelog-sections": [
1110
{ "type": "feat", "section": "Added" },
1211
{ "type": "fix", "section": "Fixed" },

0 commit comments

Comments
 (0)