Skip to content

Commit 3ef355f

Browse files
committed
ci: manual OIDC release, drop semantic-release
Replace the token-based release with a manually-triggered workflow that publishes through npm OIDC trusted publishing (no NPM_TOKEN, no semantic-release). - workflow_dispatch with a version_type (patch/minor/major) + dry_run input - `npm version` bumps + tags, `npm publish --provenance` publishes via OIDC - `id-token: write` for trusted publishing; GIT_TOKEN only to push the bump commit/tag and create the GitHub release - publish before push so a failed publish retries cleanly Requires a trusted publisher configured for `diskstore` on npmjs.com (GitHub Actions -> node-modules/diskstore, workflow release.yml). Releases are now triggered manually from the Actions tab, not on merge.
1 parent f517258 commit 3ef355f

1 file changed

Lines changed: 75 additions & 12 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 75 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,82 @@
11
name: Release
22

3+
# 手动触发发布,通过 npm OIDC trusted publishing 发布(无需 NPM_TOKEN)
34
on:
4-
# 合并后自动发布
5-
push:
6-
branches: [ master ]
5+
workflow_dispatch:
6+
inputs:
7+
version_type:
8+
description: 'Version bump type'
9+
required: true
10+
default: 'patch'
11+
type: choice
12+
options:
13+
- patch
14+
- minor
15+
- major
16+
dry_run:
17+
description: 'Dry run (do not publish or push)'
18+
required: false
19+
default: false
20+
type: boolean
721

8-
# 手动发布
9-
workflow_dispatch: {}
22+
permissions:
23+
contents: write # push the version bump commit + tag, create the GitHub release
24+
id-token: write # npm OIDC trusted publishing
1025

1126
jobs:
1227
release:
13-
name: Node.js
14-
uses: artusjs/github-actions/.github/workflows/node-release.yml@v1
15-
secrets:
16-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
17-
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
18-
with:
19-
checkTest: false
28+
name: Release
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v4
33+
with:
34+
fetch-depth: 0
35+
token: ${{ secrets.GIT_TOKEN }}
36+
37+
- name: Setup Node.js
38+
uses: actions/setup-node@v4
39+
with:
40+
node-version: 20
41+
registry-url: 'https://registry.npmjs.org'
42+
43+
# OIDC trusted publishing requires npm >= 11.5.1
44+
- name: Upgrade npm
45+
run: npm install -g npm@latest
46+
47+
- name: Install dependencies
48+
run: npm i --no-package-lock --no-fund
49+
50+
- name: Test
51+
run: npm test
52+
53+
- name: Configure Git
54+
run: |
55+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
56+
git config --local user.name "github-actions[bot]"
57+
58+
- name: Version bump
59+
id: bump
60+
run: |
61+
npm version ${{ github.event.inputs.version_type }} -m "Release v%s"
62+
echo "tag=v$(node -p "require('./package.json').version")" >> "$GITHUB_OUTPUT"
63+
64+
- name: Publish (dry run)
65+
if: ${{ github.event.inputs.dry_run == 'true' }}
66+
run: npm publish --provenance --dry-run
67+
68+
# Publish before pushing: if publish fails, nothing is pushed and the
69+
# run can be retried cleanly without a double version bump.
70+
- name: Publish
71+
if: ${{ github.event.inputs.dry_run != 'true' }}
72+
run: npm publish --provenance
73+
74+
- name: Push commit and tag
75+
if: ${{ github.event.inputs.dry_run != 'true' }}
76+
run: git push origin HEAD --follow-tags
77+
78+
- name: Create GitHub Release
79+
if: ${{ github.event.inputs.dry_run != 'true' }}
80+
run: gh release create "${{ steps.bump.outputs.tag }}" --verify-tag --generate-notes
81+
env:
82+
GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }}

0 commit comments

Comments
 (0)