Skip to content

Commit d7871b2

Browse files
authored
Merge pull request #6 from sns45/ci/bun-publish-auth
ci(publish): authenticate bun publish via bunfig.toml
2 parents 3415865 + 21842f5 commit d7871b2

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

.github/workflows/publish.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,46 @@ jobs:
2929
- name: Build
3030
run: bun run build
3131

32-
- name: Configure npm auth
32+
- name: Configure registry auth
3333
env:
3434
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
3535
run: |
3636
if [ -z "$NPM_TOKEN" ]; then
3737
echo "::error::NPM_TOKEN secret is not set. Add it with: gh secret set NPM_TOKEN --repo ${{ github.repository }}"
3838
exit 1
3939
fi
40+
41+
# npm reads ~/.npmrc (used by the whoami preflight and `npm view`).
4042
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
4143
44+
# bun publish does NOT reliably read ~/.npmrc in this version; it
45+
# authenticates via bunfig.toml [install.registry]. Append it to the
46+
# project bunfig.toml so it is found when publishing from each package
47+
# dir. The literal "$NPM_TOKEN" is expanded by bun from the env at
48+
# publish time, so the token is never written to disk.
49+
{
50+
echo ""
51+
echo "[install.registry]"
52+
echo 'url = "https://registry.npmjs.org"'
53+
echo 'token = "$NPM_TOKEN"'
54+
} >> bunfig.toml
55+
4256
- name: Verify npm authentication
57+
env:
58+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
4359
run: |
44-
# Fail loudly here rather than letting each publish fail silently.
60+
# Early structural check on the token. Note: this validates the npm
61+
# auth path; bun's path is validated by the publish step itself, which
62+
# now fails the job loudly on any error.
4563
if ! npm whoami >/dev/null 2>&1; then
4664
echo "::error::npm authentication failed. The NPM_TOKEN secret is missing, expired, or lacks publish rights to the @anyq scope."
4765
exit 1
4866
fi
4967
echo "Authenticated to npm as: $(npm whoami)"
5068
5169
- name: Publish all packages
70+
env:
71+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
5272
run: |
5373
set -uo pipefail
5474

0 commit comments

Comments
 (0)