Skip to content

Commit e5500ef

Browse files
authored
ci(release): publish to npm via trusted publishing, idempotent loop (#105)
* ci(release): publish to npm via trusted publishing (OIDC) The publish job failed with npm E404 because it published unauthenticated (no NODE_AUTH_TOKEN; setup-node's placeholder token). Switch to npm Trusted Publishing instead of a long-lived token: - upgrade npm to >= 11.5.1 (OIDC support) after setup-node - drop NODE_AUTH_TOKEN and the --provenance flag; with the GitHub Actions OIDC environment (id-token: write) npm authenticates via the per-package Trusted Publisher on npmjs.com and generates provenance automatically Requires a Trusted Publisher configured on npmjs.com for each @pleaseai/code* package (repo pleaseai/code-intelligence, workflow file release-please.yml). * ci(release): make npm publish idempotent (skip already-published versions) A partial publish left @pleaseai/code-darwin-arm64@0.1.14 on npm while the other 7 packages stayed at 0.1.13. Re-running aborted on the first package with 'cannot publish over previous version', never reaching the missing ones. Check npm view per package and publish only versions not yet present.
1 parent 44b1b40 commit e5500ef

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

.github/workflows/release-please.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,29 @@ jobs:
7979
- name: Build npm packages
8080
run: bun run build:npm
8181

82+
# Trusted publishing (OIDC) needs npm >= 11.5.1; setup-node's bundled npm may be older.
83+
- name: Upgrade npm for trusted publishing
84+
run: npm install -g npm@latest
85+
86+
# No NODE_AUTH_TOKEN: npm detects the GitHub Actions OIDC environment (id-token: write)
87+
# and authenticates via the per-package Trusted Publisher configured on npmjs.com.
88+
# Provenance is generated automatically for trusted publishing.
89+
# Idempotent: skip versions already on npm so a re-run (e.g. after a
90+
# partial publish) only pushes the packages still missing, instead of
91+
# aborting on the first "cannot publish over previous version".
8292
- name: Publish to npm
8393
run: |
84-
for dir in npm/code-*; do
85-
(cd "$dir" && npm publish --provenance --access public)
86-
done
87-
cd npm/code && npm publish --provenance --access public
94+
set -euo pipefail
95+
publish_if_new() {
96+
local dir="$1" name ver
97+
name=$(cd "$dir" && node -p "require('./package.json').name")
98+
ver=$(cd "$dir" && node -p "require('./package.json').version")
99+
if npm view "$name@$ver" version >/dev/null 2>&1; then
100+
echo "== skip $name@$ver (already published)"
101+
else
102+
echo "== publish $name@$ver"
103+
(cd "$dir" && npm publish --access public)
104+
fi
105+
}
106+
for dir in npm/code-*; do publish_if_new "$dir"; done
107+
publish_if_new npm/code

0 commit comments

Comments
 (0)