Skip to content

Commit c7b7b8d

Browse files
committed
fix(ci): improve npm authentication in GitHub Actions
- Skip npm whoami check in CI when NODE_AUTH_TOKEN is set - Add CI environment variable to workflow - Use bash shell explicitly and fix npmrc permissions - Remove ${} syntax to prevent shell expansion issues
1 parent af84d7d commit c7b7b8d

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

.github/workflows/build-binaries.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ jobs:
7070
if: startsWith(github.ref, 'refs/tags/v')
7171
env:
7272
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
73+
CI: true
74+
shell: bash
7375
run: |
74-
echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > ~/.npmrc
76+
echo "//registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN" > ~/.npmrc
77+
chmod 600 ~/.npmrc
7578
bun scripts/publish-platform.mjs --tag latest --access public

scripts/publish-platform.mjs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,20 @@ console.log(`${dim}Access:${reset} ${access}`);
8484
console.log(`${dim}Dry run:${reset} ${dryRun ? 'yes' : 'no'}\n`);
8585

8686
try {
87-
// Verify npm authentication
88-
console.log(`${cyan}${reset} Verifying npm authentication...`);
89-
try {
90-
execSync('npm whoami', { stdio: 'pipe' });
91-
console.log(`${green}${reset} ${dim}Authenticated${reset}\n`);
92-
} catch {
93-
console.error(`${red}${reset} Not logged in to npm. Run ${bold}npm login${reset} first.`);
94-
process.exit(1);
87+
// Verify npm authentication (skip in CI if NODE_AUTH_TOKEN is set)
88+
const isCI = process.env.CI === 'true' || process.env.NODE_AUTH_TOKEN;
89+
90+
if (!isCI) {
91+
console.log(`${cyan}${reset} Verifying npm authentication...`);
92+
try {
93+
execSync('npm whoami', { stdio: 'pipe' });
94+
console.log(`${green}${reset} ${dim}Authenticated${reset}\n`);
95+
} catch {
96+
console.error(`${red}${reset} Not logged in to npm. Run ${bold}npm login${reset} first.`);
97+
process.exit(1);
98+
}
99+
} else {
100+
console.log(`${cyan}${reset} Running in CI mode with NODE_AUTH_TOKEN\n`);
95101
}
96102

97103
// Build publish command

0 commit comments

Comments
 (0)