Skip to content

Commit e2dbe19

Browse files
author
strausr
committed
feat: use trusted publishing by disabling npm publish in semantic-release and publishing manually
1 parent 3d7700a commit e2dbe19

File tree

2 files changed

+26
-28
lines changed

2 files changed

+26
-28
lines changed

.github/workflows/release.yml

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -97,35 +97,34 @@ jobs:
9797
echo "=== Git tags ==="
9898
git tag
9999
100-
- name: Extract npm token for semantic-release
100+
- name: Release with semantic-release
101+
id: release
102+
env:
103+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
104+
run: npx semantic-release
105+
106+
- name: Publish to npm using trusted publishing
101107
run: |
102-
echo "=== Extracting npm token ==="
108+
echo "=== Publishing to npm with trusted publishing (OIDC) ==="
103109
104-
# Copy .npmrc created by setup-node
110+
# Ensure .npmrc is available (setup-node should have created it)
105111
if [ -f "$NPM_CONFIG_USERCONFIG" ]; then
106112
cp "$NPM_CONFIG_USERCONFIG" ~/.npmrc
107-
echo "✓ Copied .npmrc to ~/.npmrc"
108-
109-
# Extract token
110-
NPM_TOKEN=$(grep '_authToken' ~/.npmrc | sed 's/.*_authToken=//' | head -1 | tr -d '\n\r\t ' || echo "")
113+
echo "✓ Using .npmrc for authentication"
114+
fi
115+
116+
# Get version from package.json (updated by semantic-release)
117+
VERSION=$(node -p "require('./package.json').version")
118+
CURRENT_TAG=$(git describe --tags --exact-match 2>/dev/null || echo "")
119+
120+
# Only publish if semantic-release created a new version
121+
if [ -n "$CURRENT_TAG" ]; then
122+
echo "New release detected: $CURRENT_TAG"
123+
echo "Publishing version: $VERSION"
111124
112-
if [ -n "$NPM_TOKEN" ] && [ ${#NPM_TOKEN} -gt 10 ]; then
113-
echo "::add-mask::$NPM_TOKEN"
114-
echo "NPM_TOKEN=$NPM_TOKEN" >> $GITHUB_ENV
115-
echo "✓ NPM_TOKEN extracted (length: ${#NPM_TOKEN} chars)"
116-
echo ""
117-
echo "Note: Token may not work for 'npm whoami' but should work for 'npm publish'"
118-
echo "semantic-release will attempt to use it for publishing"
119-
else
120-
echo "✗ Could not extract valid token"
121-
exit 1
122-
fi
125+
# Publish using npm publish which supports OIDC/trusted publishing
126+
npm publish --provenance --access public
127+
echo "✓ Published $VERSION to npm"
123128
else
124-
echo "✗ .npmrc not found"
125-
exit 1
129+
echo "No new release created, skipping npm publish"
126130
fi
127-
128-
- name: Release
129-
env:
130-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
131-
run: npx semantic-release

.releaserc.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
[
1414
"@semantic-release/npm",
1515
{
16-
"npmPublish": true,
17-
"registry": "https://registry.npmjs.org/",
18-
"pkgRoot": "."
16+
"npmPublish": false,
17+
"tarballDir": "dist"
1918
}
2019
],
2120
[

0 commit comments

Comments
 (0)