Skip to content

Commit 3014fe5

Browse files
ci: publish to npm when Release Please ships a GitHub Release (#639)
* ci: publish to npm when Release Please ships a GitHub Release Run npm test then npm publish on release: published, checkout the release tag, and document NPM_TOKEN plus manual fallback in CONTRIBUTING.md. Co-authored-by: Cursor <cursoragent@cursor.com> * ci: use RELEASE_PLEASE_TOKEN so publish workflow is triggered GitHub does not start downstream workflows from events created with GITHUB_TOKEN; Release Please needs a PAT for npm-publish to run. Co-authored-by: Cursor <cursoragent@cursor.com> * ci: keep GITHUB_TOKEN for Release Please Drop RELEASE_PLEASE_TOKEN requirement; document manual npm publish when the default token does not trigger downstream workflows. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent ca59b2c commit 3014fe5

3 files changed

Lines changed: 44 additions & 5 deletions

File tree

.github/workflows/npm-publish.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,37 @@ name: npm publish
33
# Runs when Release Please creates a GitHub Release (see release-please.yml and ADR 0004).
44
on:
55
release:
6-
types: [created]
6+
types: [published]
77

88
jobs:
99
build:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v6
13+
with:
14+
ref: ${{ github.event.release.tag_name }}
1315
- uses: actions/setup-node@v6
1416
with:
1517
node-version: 24.x
1618
cache: npm
1719
- run: npm ci
1820
- run: npm test
21+
22+
publish-npm:
23+
needs: build
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: read
27+
steps:
28+
- uses: actions/checkout@v6
29+
with:
30+
ref: ${{ github.event.release.tag_name }}
31+
- uses: actions/setup-node@v6
32+
with:
33+
node-version: 24.x
34+
registry-url: https://registry.npmjs.org/
35+
cache: npm
36+
- run: npm ci
37+
- run: npm publish --access public
38+
env:
39+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

CONTRIBUTING.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,29 @@ Versioning is automated with [Release Please](https://github.com/googleapis/rele
156156

157157
1. Merge changes to `master` using [Conventional Commits](https://www.conventionalcommits.org/) (`feat:`, `fix:`, `docs:`, `ci:`, etc.).
158158
2. Release Please opens or updates a **Release PR** with the next version, `CHANGELOG.md`, and `package.json` updates.
159-
3. Review and merge the Release PR to create the git tag and GitHub Release.
160-
4. The `npm-publish` workflow runs when a GitHub Release is created.
159+
3. Review and merge the Release PR to create the git tag and GitHub Release on GitHub.
160+
4. Publish to npm (see **npm publishing** below). The [`npm-publish`](.github/workflows/npm-publish.yml) workflow listens for `release: published`, but releases created with the default `GITHUB_TOKEN` usually **do not** trigger downstream workflows — use manual publish or re-run the workflow from the Actions tab if needed.
161161

162162
Do not run local `npm version` or push version tags manually unless coordinating an emergency release with maintainers.
163163

164+
#### npm publishing
165+
166+
Configure this repository secret under **Settings → Secrets and variables → Actions**:
167+
168+
- **`NPM_TOKEN`** — npm access token with publish permission for the `webfont` package (Automation or Granular Access Token).
169+
170+
After merging the Release PR, publish from the release tag (recommended):
171+
172+
```shell
173+
git fetch origin --tags
174+
git checkout v12.0.0 # use the tag created by Release Please
175+
npm ci
176+
npm test
177+
npm publish --access public
178+
```
179+
180+
Automated publishing does **not** retroactively upload versions that already exist as git tags only (for example `11.5.x` never published to npm).
181+
164182
## Resources
165183

166184
- [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)

docs/adr/0004-release-please-instead-of-standard-version.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ The project already uses [Conventional Commits](https://www.conventionalcommits.
8282
### Negative / trade-offs
8383

8484
- **Release PR cadence:** Version bumps no longer land instantly on every `master` push; they accumulate in a Release PR until merged.
85-
- **`GITHUB_TOKEN` limitation:** Releases and Release PRs created by the default token do not trigger other workflows that listen to `pull_request` from those events. If CI must run on Release PRs with full permissions, configure a PAT secret (see [Release Please Action docs](https://github.com/googleapis/release-please-action#github-credentials)).
85+
- **`GITHUB_TOKEN` limitation:** Releases created with the default token do **not** trigger other workflows (including `npm-publish.yml`). Publish manually from the release tag, or configure a PAT for Release Please later if fully automated publish is required (see [Release Please Action docs](https://github.com/googleapis/release-please-action#github-credentials)).
8686
- **Prereleases:** The old `npm run release-alpha` script is removed; use Conventional Commit prerelease notation or Release Please `release-as` / manifest options when needed.
8787

8888
### Follow-up
8989

90-
- If npm registry publish should run automatically, extend `npm-publish.yml` with `npm publish` and `NPM_TOKEN` (today it only runs `npm test` on `release: created`).
90+
- ~~If npm registry publish should run automatically, extend `npm-publish.yml` with `npm publish` and `NPM_TOKEN` (today it only runs `npm test` on `release: created`).~~ Done in PR [#639](https://github.com/itgalaxy/webfont/pull/639): publish on `release: published` with `NPM_TOKEN`.
9191

9292
## References
9393

0 commit comments

Comments
 (0)