Skip to content

Commit 9f18d51

Browse files
author
strausr
committed
fix: improve token extraction and .npmrc formatting for npm authentication
1 parent 5df6779 commit 9f18d51

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

.github/workflows/release.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,23 @@ jobs:
144144
fi
145145
fi
146146
147-
if [ -n "$NPM_TOKEN" ] && [ "$NPM_TOKEN" != "\${NODE_AUTH_TOKEN}" ]; then
147+
# Clean up the token (remove any whitespace, newlines, etc.)
148+
NPM_TOKEN=$(echo "$NPM_TOKEN" | tr -d '\n\r\t ' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
149+
150+
if [ -n "$NPM_TOKEN" ] && [ "$NPM_TOKEN" != "\${NODE_AUTH_TOKEN}" ] && [ ${#NPM_TOKEN} -gt 10 ]; then
148151
echo "::add-mask::$NPM_TOKEN"
149152
echo "NPM_TOKEN=$NPM_TOKEN" >> $GITHUB_ENV
150153
echo "✓ NPM_TOKEN extracted and set (length: ${#NPM_TOKEN} chars)"
154+
155+
# Also ensure .npmrc is properly formatted for npm
156+
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
157+
echo "registry=https://registry.npmjs.org/" >> ~/.npmrc
158+
echo "always-auth=true" >> ~/.npmrc
159+
echo "✓ Recreated .npmrc with proper format"
151160
else
152161
echo "✗ Error: Could not extract valid token from .npmrc"
153-
echo "Token value: '$NPM_TOKEN'"
162+
echo "Token length: ${#NPM_TOKEN} chars"
163+
echo "Token preview (first 10 chars): ${NPM_TOKEN:0:10}..."
154164
echo ""
155165
echo "Full .npmrc content (first 10 lines, tokens masked):"
156166
head -10 ~/.npmrc | sed 's/=.*/=***/' || true

.releaserc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"@semantic-release/npm",
1515
{
1616
"npmPublish": true,
17-
"registry": "https://registry.npmjs.org/"
17+
"registry": "https://registry.npmjs.org/",
18+
"pkgRoot": "."
1819
}
1920
],
2021
[

0 commit comments

Comments
 (0)