Skip to content

Commit 2d167ba

Browse files
authored
ci: manual OIDC release, drop semantic-release (#7)
Replace the token-based release with a manually-triggered workflow that publishes through npm OIDC trusted publishing (no NPM_TOKEN, no semantic-release, no long-lived PAT). - 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; the built-in GITHUB_TOKEN (contents: write) pushes the bump commit/tag and creates 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 2d167ba

1 file changed

Lines changed: 74 additions & 12 deletions

File tree

.github/workflows/release.yml

Lines changed: 74 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,81 @@
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+
36+
- name: Setup Node.js
37+
uses: actions/setup-node@v4
38+
with:
39+
node-version: 20
40+
registry-url: 'https://registry.npmjs.org'
41+
42+
# OIDC trusted publishing requires npm >= 11.5.1
43+
- name: Upgrade npm
44+
run: npm install -g npm@latest
45+
46+
- name: Install dependencies
47+
run: npm i --no-package-lock --no-fund
48+
49+
- name: Test
50+
run: npm test
51+
52+
- name: Configure Git
53+
run: |
54+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
55+
git config --local user.name "github-actions[bot]"
56+
57+
- name: Version bump
58+
id: bump
59+
run: |
60+
npm version ${{ github.event.inputs.version_type }} -m "Release v%s"
61+
echo "tag=v$(node -p "require('./package.json').version")" >> "$GITHUB_OUTPUT"
62+
63+
- name: Publish (dry run)
64+
if: ${{ github.event.inputs.dry_run == 'true' }}
65+
run: npm publish --provenance --dry-run
66+
67+
# Publish before pushing: if publish fails, nothing is pushed and the
68+
# run can be retried cleanly without a double version bump.
69+
- name: Publish
70+
if: ${{ github.event.inputs.dry_run != 'true' }}
71+
run: npm publish --provenance
72+
73+
- name: Push commit and tag
74+
if: ${{ github.event.inputs.dry_run != 'true' }}
75+
run: git push origin HEAD --follow-tags
76+
77+
- name: Create GitHub Release
78+
if: ${{ github.event.inputs.dry_run != 'true' }}
79+
run: gh release create "${{ steps.bump.outputs.tag }}" --verify-tag --generate-notes
80+
env:
81+
GITHUB_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)