Skip to content

Commit cf31fb4

Browse files
committed
fix: npm publish via OIDC when NPM_TOKEN is unset
Empty NODE_AUTH_TOKEN blocked trusted publishing; use --provenance without a token and keep NPM_TOKEN as fallback.
1 parent 2bfee70 commit cf31fb4

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,24 @@ jobs:
6868
node-version: "22.14"
6969
registry-url: https://registry.npmjs.org
7070

71-
- name: Publish npm package
71+
- name: Publish npm package (trusted publisher OIDC)
72+
if: ${{ secrets.NPM_TOKEN == '' }}
73+
env:
74+
VER: ${{ inputs.tag || github.ref_name }}
75+
run: |
76+
set -euo pipefail
77+
VER="${VER#v}"
78+
if ! [[ "$VER" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
79+
echo "Refusing to publish with version '$VER' (expected semver from tag)." >&2
80+
exit 1
81+
fi
82+
node -e "const fs=require('fs'); const p=JSON.parse(fs.readFileSync('package.json','utf8')); p.version=process.env.VER; fs.writeFileSync('package.json', JSON.stringify(p,null,2)+'\n')"
83+
npm install -g npm@^11.5.1
84+
npm publish --provenance --access public
85+
npm view "@devrecated/autodevelop@${VER}" version
86+
87+
- name: Publish npm package (NPM_TOKEN fallback)
88+
if: ${{ secrets.NPM_TOKEN != '' }}
7289
env:
7390
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
7491
VER: ${{ inputs.tag || github.ref_name }}
@@ -81,5 +98,5 @@ jobs:
8198
fi
8299
node -e "const fs=require('fs'); const p=JSON.parse(fs.readFileSync('package.json','utf8')); p.version=process.env.VER; fs.writeFileSync('package.json', JSON.stringify(p,null,2)+'\n')"
83100
npm install -g npm@^11.5.1
84-
npm publish --access public
101+
npm publish --provenance --access public
85102
npm view "@devrecated/autodevelop@${VER}" version

0 commit comments

Comments
 (0)