Skip to content

Commit 3d07b5f

Browse files
fix: troubleshoot npm publish error after changing to trusted publishers (#48)
1 parent 774d2b8 commit 3d07b5f

2 files changed

Lines changed: 38 additions & 4 deletions

File tree

.github/workflows/manual-publish.yml

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ on:
1818

1919
permissions:
2020
contents: read
21+
id-token: write
2122

2223
jobs:
2324
publish-npm:
@@ -36,7 +37,7 @@ jobs:
3637
- name: Setup Node.js
3738
uses: actions/setup-node@v4
3839
with:
39-
node-version: '22'
40+
node-version: '20'
4041
registry-url: 'https://registry.npmjs.org'
4142

4243
- name: Install dependencies
@@ -45,12 +46,42 @@ jobs:
4546
- name: Build TypeScript package
4647
run: npm run build
4748

49+
- name: Preflight OIDC availability
50+
run: |
51+
if [ -z "${ACTIONS_ID_TOKEN_REQUEST_URL:-}" ]; then
52+
echo "OIDC token request URL is missing (check id-token: write permissions)."
53+
exit 1
54+
fi
55+
echo "OIDC environment is available."
56+
57+
- name: OIDC token check
58+
run: |
59+
if [ -z "${ACTIONS_ID_TOKEN_REQUEST_TOKEN:-}" ]; then
60+
echo "OIDC request token is missing (check id-token: write permissions)."
61+
exit 1
62+
fi
63+
curl -fsS -H "Authorization: bearer ${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" \
64+
"${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=npm:registry.npmjs.org" > /tmp/oidc.json
65+
echo "OIDC token fetch OK"
66+
4867
- name: Publish to npm
4968
id: npm_publish
5069
working-directory: packages/flarelette-jwt-ts
51-
env:
52-
NODE_AUTH_TOKEN: ''
53-
run: npm publish --provenance --access public
70+
run: |
71+
unset NODE_AUTH_TOKEN
72+
if [ -n "${NPM_CONFIG_USERCONFIG:-}" ] && [ -f "${NPM_CONFIG_USERCONFIG}" ]; then
73+
rm -f "${NPM_CONFIG_USERCONFIG}"
74+
fi
75+
npm publish --provenance --access public --registry=https://registry.npmjs.org
76+
77+
- name: Upload npm debug logs (on failure)
78+
if: failure() && steps.npm_publish.outcome == 'failure'
79+
uses: actions/upload-artifact@v4
80+
with:
81+
name: npm-debug-logs
82+
path: /home/runner/.npm/_logs/*
83+
if-no-files-found: warn
84+
retention-days: 14
5485

5586
- name: Upload npm debug logs (on failure)
5687
if: failure() && steps.npm_publish.outcome == 'failure'

packages/flarelette-jwt-ts/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
"README.md",
4545
"LICENSE"
4646
],
47+
"publishConfig": {
48+
"access": "public"
49+
},
4750
"bin": {
4851
"flarelette-jwt-secret": "dist/cli.js",
4952
"flarelette-jwt-keygen": "dist/keygen.js"

0 commit comments

Comments
 (0)