Skip to content

Commit bd211ce

Browse files
committed
fix(ci): upgrade npm + clear stale _authToken before OIDC publish
1 parent c24ac3a commit bd211ce

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

.github/workflows/release.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,22 +106,42 @@ jobs:
106106
with:
107107
name: build-artifacts
108108

109+
# ── 0. Upgrade npm so OIDC trusted publishing works reliably ────────────
110+
# actions/setup-node writes `_authToken=${NODE_AUTH_TOKEN}` to .npmrc.
111+
# When NODE_AUTH_TOKEN is unset, some npm versions treat the empty value
112+
# as an invalid token ("Access token expired") instead of falling through
113+
# to OIDC. Upgrading npm to latest (11.x) and clearing the stale auth
114+
# entry ensures the OIDC exchange is always used for publishing.
115+
- name: Upgrade npm and clear stale auth
116+
run: |
117+
npm install -g npm@latest
118+
npm --version
119+
# Remove the empty _authToken written by actions/setup-node so npm
120+
# finds no static credential and uses the OIDC token instead.
121+
npm config delete "//registry.npmjs.org/:_authToken" || true
122+
109123
# ── 1. Publish all @cfxdevkit/* library packages ───────────────────────
110124
# IMPORTANT: Use `npm publish` (not `pnpm publish`) so the npm CLI can
111125
# automatically exchange the GitHub OIDC token for a short-lived npm
112126
# credential. `pnpm publish` does NOT trigger the OIDC token exchange,
113127
# which causes "Access token expired" + E404 even when trusted publishing
114128
# is correctly configured on npmjs.com.
115-
#
116-
# Provenance attestation is generated automatically by npm when publishing
117-
# via OIDC trusted publishing — no --provenance flag needed.
118129
- name: Publish @cfxdevkit/* packages
119130
run: |
131+
set -e
132+
failed=''
120133
for pkg_dir in packages/*/; do
121134
pkg_name=$(node -p "require('./${pkg_dir}package.json').name")
122135
echo "\n--- Publishing ${pkg_name} ---"
123-
npm publish "${pkg_dir}" --access public
136+
if ! npm publish "${pkg_dir}" --access public; then
137+
echo "::error::Failed to publish ${pkg_name}"
138+
failed="${failed} ${pkg_name}"
139+
fi
124140
done
141+
if [ -n "$failed" ]; then
142+
echo "::error::The following packages failed to publish:${failed}"
143+
exit 1
144+
fi
125145
126146
# ── 2. Publish the conflux-devkit CLI ──────────────────────────────────
127147
# `pnpm pack` normalises workspace:* dependency versions in package.json

0 commit comments

Comments
 (0)