Skip to content

Commit a408d4c

Browse files
author
strausr
committed
fix: extract npm token from .npmrc for semantic-release with trusted publishing
1 parent 1fb7968 commit a408d4c

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

.github/workflows/release.yml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,33 @@ jobs:
100100
- name: Configure npm authentication for semantic-release
101101
run: |
102102
# actions/setup-node creates .npmrc in a temp location
103-
# We need to copy it or create one that semantic-release can use
103+
# We need to ensure semantic-release can find it
104104
if [ -f "$NPM_CONFIG_USERCONFIG" ]; then
105-
echo "Found npmrc at $NPM_CONFIG_USERCONFIG"
105+
echo "=== Found npmrc at $NPM_CONFIG_USERCONFIG ==="
106106
cat "$NPM_CONFIG_USERCONFIG"
107107
# Copy to home directory for semantic-release
108-
cp "$NPM_CONFIG_USERCONFIG" ~/.npmrc || true
108+
mkdir -p ~/.npm
109+
cp "$NPM_CONFIG_USERCONFIG" ~/.npmrc
110+
echo "Copied .npmrc to ~/.npmrc"
111+
else
112+
echo "Warning: NPM_CONFIG_USERCONFIG not found at $NPM_CONFIG_USERCONFIG"
109113
fi
110114
111-
# Also set NPM_TOKEN from NODE_AUTH_TOKEN if available
112-
if [ -n "$NODE_AUTH_TOKEN" ]; then
113-
echo "NPM_TOKEN=$NODE_AUTH_TOKEN" >> $GITHUB_ENV
114-
echo "NPM_TOKEN set from NODE_AUTH_TOKEN"
115+
# Extract token from .npmrc and set as NPM_TOKEN for semantic-release
116+
if [ -f ~/.npmrc ]; then
117+
# Extract the token from the .npmrc file
118+
TOKEN=$(grep -oP '(?<=//registry\.npmjs\.org/:_authToken=).*' ~/.npmrc || echo "")
119+
if [ -n "$TOKEN" ]; then
120+
echo "NPM_TOKEN=$TOKEN" >> $GITHUB_ENV
121+
echo "NPM_TOKEN extracted from .npmrc and set"
122+
else
123+
echo "Warning: Could not extract token from .npmrc"
124+
fi
115125
fi
116126
117127
# Test npm auth
118128
echo "=== Testing npm authentication ==="
119-
npm whoami --registry=https://registry.npmjs.org || echo "npm whoami failed (this is OK if using OIDC)"
129+
npm whoami --registry=https://registry.npmjs.org || echo "npm whoami failed"
120130
121131
- name: Release
122132
env:

0 commit comments

Comments
 (0)