Skip to content

Commit 81070a5

Browse files
committed
ci: migrate npm release workflow to trusted publishing
1 parent bee536d commit 81070a5

File tree

2 files changed

+59
-79
lines changed

2 files changed

+59
-79
lines changed

.github/workflows/comment-release.yml

Lines changed: 0 additions & 72 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,38 @@ name: release
22

33
permissions:
44
contents: write
5+
id-token: write
6+
issues: write
57

68
on:
79
push:
810
tags:
911
- 'v*'
12+
issue_comment:
13+
types:
14+
- created
1015

1116
jobs:
1217
release:
18+
if: ${{ github.event_name == 'push' || (github.event.issue.pull_request && github.event.comment.body == 'npm publish') }}
1319
runs-on: ubuntu-latest
1420
steps:
15-
- uses: actions/checkout@v4
21+
- if: ${{ github.event_name == 'push' }}
22+
uses: actions/checkout@v4
1623
with:
1724
fetch-depth: 0
1825

26+
- if: ${{ github.event_name == 'issue_comment' }}
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0
30+
31+
- name: ⬇️ Checkout PR
32+
if: ${{ github.event_name == 'issue_comment' }}
33+
run: |
34+
git fetch origin pull/${{ github.event.issue.number }}/head:pr-find-commit
35+
git checkout pr-find-commit
36+
1937
- name: Install pnpm
2038
uses: pnpm/action-setup@v3
2139
with:
@@ -24,18 +42,52 @@ jobs:
2442
- name: Install Node.js
2543
uses: actions/setup-node@v4
2644
with:
27-
node-version: 20
45+
node-version: 24
2846
cache: "pnpm"
2947
registry-url: 'https://registry.npmjs.org'
3048

31-
- run: npx changelogithub
49+
- name: Create GitHub release notes
50+
if: ${{ github.event_name == 'push' }}
51+
run: npx changelogithub
3252
env:
3353
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
3454

55+
- name: Set prerelease package version
56+
if: ${{ github.event_name == 'issue_comment' }}
57+
run: npm version --no-git-tag-version 0.0.0-$(git rev-parse HEAD)
58+
3559
- name: Install dependencies
3660
run: pnpm install
3761

38-
- run: pnpm publish --no-git-checks
39-
env:
40-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
41-
62+
- name: Publish release
63+
if: ${{ github.event_name == 'push' }}
64+
run: pnpm publish --no-git-checks
65+
66+
- name: Publish prerelease
67+
if: ${{ github.event_name == 'issue_comment' }}
68+
run: pnpm publish --no-git-checks --tag pre
69+
70+
- name: Update comment
71+
if: ${{ github.event_name == 'issue_comment' }}
72+
uses: actions/github-script@v7
73+
with:
74+
github-token: ${{ secrets.GITHUB_TOKEN }}
75+
script: |
76+
const { issue: { number: issue_number }, repo: { owner, repo }, payload } = context;
77+
const fs = require('fs');
78+
const jsonString = fs.readFileSync(`${process.env.GITHUB_WORKSPACE}/package.json`);
79+
const packageJson = JSON.parse(jsonString);
80+
const { name: packageName, version } = packageJson;
81+
82+
const body = [
83+
'npm package published to pre tag.',
84+
`\`\`\`bash\nnpm install ${packageName}@pre\n\`\`\``,
85+
`\`\`\`bash\nnpm install ${packageName}@${version}\n\`\`\``,
86+
].join('\n\n');
87+
88+
await github.rest.issues.updateComment({
89+
owner,
90+
repo,
91+
comment_id: payload.comment.id,
92+
body,
93+
});

0 commit comments

Comments
 (0)