Skip to content

Commit f5fb276

Browse files
committed
fix npm publish bootstrap auth
1 parent 9b606e9 commit f5fb276

4 files changed

Lines changed: 21 additions & 6 deletions

File tree

.github/workflows/release.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,24 +258,33 @@ jobs:
258258
' packaging/npm/agoraio-cli/package.json > "$tmp"
259259
mv "$tmp" packaging/npm/agoraio-cli/package.json
260260
261-
- name: Prepare npm for trusted publishing
261+
- name: Prepare npm publish auth
262262
if: steps.mode.outputs.mode == 'publish'
263263
shell: bash
264+
env:
265+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
264266
run: |
265267
set -euo pipefail
266268
# Trusted publishing requires npm CLI 11.5.1+.
267269
npm install -g npm@latest
268270
npm --version
269271
# setup-node writes an empty _authToken placeholder when registry-url is set
270-
# without NODE_AUTH_TOKEN; remove it so npm uses OIDC trusted publishing.
271-
if [ -n "${NPM_CONFIG_USERCONFIG:-}" ] && [ -f "$NPM_CONFIG_USERCONFIG" ]; then
272+
# without NODE_AUTH_TOKEN; remove it in OIDC mode so npm uses trusted
273+
# publishing. When NPM_TOKEN is configured, keep the placeholder so
274+
# first-time package bootstraps can authenticate with the token.
275+
if [ -n "${NODE_AUTH_TOKEN:-}" ]; then
276+
echo "Using NPM_TOKEN for npm publish authentication."
277+
npm whoami >/dev/null
278+
elif [ -n "${NPM_CONFIG_USERCONFIG:-}" ] && [ -f "$NPM_CONFIG_USERCONFIG" ]; then
279+
echo "Using npm trusted publishing for npm publish authentication."
272280
sed -i '/^\/\/registry\.npmjs\.org\/:_authToken=/d' "$NPM_CONFIG_USERCONFIG"
273281
fi
274282
275283
- name: Publish platform packages
276284
shell: bash
277285
env:
278286
PUBLISH_ARGS: ${{ steps.mode.outputs.publish_args }}
287+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
279288
run: |
280289
set -euo pipefail
281290
for pkg in \
@@ -305,6 +314,7 @@ jobs:
305314
shell: bash
306315
env:
307316
PUBLISH_ARGS: ${{ steps.mode.outputs.publish_args }}
317+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
308318
run: |
309319
set -euo pipefail
310320
pkg="packaging/npm/agoraio-cli"

AGENTS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ packaging/npm/
258258
6. Smoke-tests the published wrapper with `npx --yes agoraio-cli@<tag> --version` (retry/backoff for registry propagation)
259259

260260
**Prerequisites:**
261-
- npm **Trusted Publisher** configured on each package (`agoraio-cli` and all `agoraio-cli-*`), pointing at repo `AgoraIO/cli` and workflow `release.yml`.
261+
- npm package names already exist on the registry before relying on trusted publishing. For first-time package creation, use a short-lived granular `NPM_TOKEN` repository secret for the bootstrap release, then remove it after trusted publishers are configured.
262+
- npm **Trusted Publisher** configured on each existing package (`agoraio-cli` and all `agoraio-cli-*`), pointing at repo `AgoraIO/cli` and workflow `release.yml`.
262263
- `id-token: write` workflow permission (already set in `release.yml`) — required for trusted publishing and provenance.
263264

264265
**Manual dry-run:** the workflow exposes `workflow_dispatch` with a `dry_run` input that runs `npm publish --dry-run` against a synthetic version, validating packaging without publishing.

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Earlier entries pre-date this convention and only carry their version's compare
1717

1818
### Fixed
1919

20+
- Allow the npm release job to use a short-lived `NPM_TOKEN` bootstrap secret when platform packages do not yet exist on npm, while keeping trusted publishing as the default tokenless path.
2021
- Update GoReleaser Cosign signing to emit `checksums.txt.sigstore.json` with `--bundle`, matching Cosign's current bundle-based signing flow.
2122

2223
## [0.2.2] - 2026-05-26

RELEASING.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ The release workflow (`.github/workflows/release.yml`) then:
2525
- Publishes the six per-platform packages with `npm publish --provenance`
2626
- Publishes the wrapper package (`agoraio-cli`) with `npm publish --provenance`
2727
- Runs a post-publish smoke test: `npx --yes agoraio-cli@<tag> --version` with retry/backoff to handle registry propagation
28-
- Authenticates via [npm trusted publishing](https://docs.npmjs.com/trusted-publishers/) (OIDC from GitHub Actions — no `NPM_TOKEN` secret)
28+
- Authenticates via [npm trusted publishing](https://docs.npmjs.com/trusted-publishers/) (OIDC from GitHub Actions) once packages exist and trust is configured
29+
- Can use `NPM_TOKEN` as a bootstrap fallback for first-time package publishes before trusted publishers can be configured
2930
- Requires `id-token: write` workflow permission (already set in `release.yml`)
3031

3132
3. **Apt repository** job (triggered by the published release):
@@ -63,7 +64,8 @@ The release workflow exposes a `workflow_dispatch` trigger that runs the npm pub
6364

6465
Before tagging the first real release that ships npm, confirm:
6566

66-
- [ ] Each npm package has a **Trusted Publisher** configured on [npmjs.com](https://www.npmjs.com) (Package → Settings → Trusted Publisher → GitHub Actions):
67+
- [ ] Each npm package already exists on npm. If a package does not exist yet, add a short-lived granular `NPM_TOKEN` repository secret with publish rights for the bootstrap release, then remove it after configuring trusted publishing.
68+
- [ ] Each existing npm package has a **Trusted Publisher** configured on [npmjs.com](https://www.npmjs.com) (Package → Settings → Trusted Publisher → GitHub Actions):
6769
- Repository: `AgoraIO/cli`
6870
- Workflow filename: `release.yml`
6971
- Configure for `agoraio-cli` and all six `agoraio-cli-{os}-{arch}` platform packages
@@ -78,6 +80,7 @@ Before tagging the first real release that ships npm, confirm:
7880
| -------------------- | -------- | ------------------------------- |
7981
| `APT_SIGNING_KEY` | secret | Signed apt repo on GitHub Pages |
8082
| `APT_SIGNING_KEY_ID` | variable | Signed apt repo on GitHub Pages |
83+
| `NPM_TOKEN` | secret | Bootstrap npm publish only, before trusted publishers are configured |
8184

8285
Homebrew and Scoop are not part of the current GoReleaser config. Add `brews:` / `scoops:` blocks before documenting them as automated channels.
8386

0 commit comments

Comments
 (0)