Skip to content

Commit de7ef11

Browse files
committed
CI: add npm Trusted Publisher workflows
- create-release-pr.yml: Creates release PRs with version bump and release notes - release.yml: Publishes to npm using Trusted Publisher (OIDC) when PR is merged - No npm tokens required - uses GitHub OIDC for authentication
1 parent 9076f6c commit de7ef11

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

.github/workflows/create-release-pr.yml

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ jobs:
2020
pull-requests: write
2121
steps:
2222
- name: Checkout
23-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
24-
with:
25-
persist-credentials: false
26-
27-
- name: Install pnpm
28-
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
23+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2924
with:
3025
persist-credentials: false
3126

@@ -34,16 +29,19 @@ jobs:
3429
git config user.name "github-actions[bot]"
3530
git config user.email "github-actions[bot]@users.noreply.github.com"
3631
32+
- name: Install pnpm
33+
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
34+
3735
- name: Setup Node.js
3836
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
3937
with:
4038
node-version: 'lts/*'
4139

42-
# No need to install dependencies - pnpm version works without them
40+
# No need to install dependencies - npm version works without them
4341
- name: Version bump
4442
id: version
4543
run: |
46-
pnpm version "$VERSION_TYPE" --no-git-tag-version
44+
npm version "$VERSION_TYPE" --no-git-tag-version
4745
VERSION=$(jq -r '.version' package.json)
4846
echo "version=$VERSION" >> $GITHUB_OUTPUT
4947
env:
@@ -67,7 +65,7 @@ jobs:
6765
6866
# Generate release notes with or without previous tag
6967
if [ -n "$LAST_TAG" ]; then
70-
NOTES=$(gh api \
68+
RELEASE_NOTES=$(gh api \
7169
--method POST \
7270
-H "Accept: application/vnd.github+json" \
7371
"/repos/$GITHUB_REPOSITORY/releases/generate-notes" \
@@ -76,7 +74,7 @@ jobs:
7674
-f "previous_tag_name=$LAST_TAG" \
7775
--jq '.body')
7876
else
79-
NOTES=$(gh api \
77+
RELEASE_NOTES=$(gh api \
8078
--method POST \
8179
-H "Accept: application/vnd.github+json" \
8280
"/repos/$GITHUB_REPOSITORY/releases/generate-notes" \
@@ -85,8 +83,10 @@ jobs:
8583
--jq '.body')
8684
fi
8785
88-
# Save to file to handle multiline content
89-
echo "$NOTES" > release-notes.md
86+
# Set release notes as environment variable for PR body
87+
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
88+
echo "$RELEASE_NOTES" >> $GITHUB_ENV
89+
echo "EOF" >> $GITHUB_ENV
9090
env:
9191
GH_TOKEN: ${{ github.token }}
9292
VERSION: ${{ steps.version.outputs.version }}
@@ -98,11 +98,9 @@ jobs:
9898
branch: release/v${{ steps.version.outputs.version }}
9999
delete-branch: true
100100
title: "Release v${{ steps.version.outputs.version }}"
101-
body-path: release-notes.md
101+
body: |
102+
${{ env.RELEASE_NOTES }}
102103
commit-message: "chore: release v${{ steps.version.outputs.version }}"
103-
add-paths: |
104-
package.json
105-
pnpm.lock
106104
labels: |
107105
Type: Release
108106
assignees: ${{ github.actor }}

.github/workflows/release.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@ jobs:
2828
pull-requests: write # PR comment
2929
steps:
3030
- name: Checkout
31-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
32-
with:
33-
persist-credentials: false
34-
35-
- name: Install pnpm
36-
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
31+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
3732
with:
3833
persist-credentials: false
3934

@@ -63,14 +58,27 @@ jobs:
6358
env:
6459
VERSION: ${{ steps.package.outputs.version }}
6560

61+
- name: Install pnpm
62+
if: steps.tag-check.outputs.exists == 'false'
63+
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
64+
6665
- name: Setup Node.js
6766
if: steps.tag-check.outputs.exists == 'false'
6867
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
6968
with:
7069
node-version: 'lts/*'
7170
registry-url: 'https://registry.npmjs.org'
7271

73-
# pnpm is already installed via pnpm/action-setup
72+
- name: Ensure npm 11.5.1 or later is installed
73+
if: steps.tag-check.outputs.exists == 'false'
74+
run: |
75+
NPM_VERSION=$(npm -v)
76+
echo "Current npm version: $NPM_VERSION"
77+
if ! npx semver -r ">=11.5.1" "$NPM_VERSION"; then
78+
echo "npm version $NPM_VERSION is too old. Installing latest npm..."
79+
npm install -g npm@latest
80+
echo "Updated npm version: $(npm -v)"
81+
fi
7482
7583
- name: Install dependencies
7684
if: steps.tag-check.outputs.exists == 'false'

0 commit comments

Comments
 (0)