Skip to content

Commit 2586f10

Browse files
committed
feat: support npm trusted publisher
close #14
1 parent 84dbcd9 commit 2586f10

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

.github/workflows/npm-release.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: NPM Trusted Publisher
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
checkTest:
7+
type: boolean
8+
description: whether run test before release
9+
default: false
10+
11+
dryRun:
12+
type: boolean
13+
description: pass dry-run to semantic-release
14+
default: false
15+
16+
install:
17+
type: string
18+
description: 'Install dependencies script'
19+
default: 'npm i --no-package-lock --no-fund --force && rm -rf package-lock.json'
20+
21+
action_ref:
22+
type: string
23+
description: 'Branch name for node-modules/github-actions, for test purpose'
24+
default: master
25+
26+
jobs:
27+
Release:
28+
permissions:
29+
contents: write
30+
id-token: write # Required for OIDC
31+
deployments: write
32+
runs-on: ubuntu-latest
33+
defaults:
34+
run:
35+
working-directory: main_repo
36+
37+
concurrency:
38+
group: ${{ github.workflow }}-${{ github.ref }}
39+
cancel-in-progress: true
40+
41+
steps:
42+
# Checkout action repository
43+
- name: Checkout action repository
44+
uses: actions/checkout@v4
45+
with:
46+
repository: node-modules/github-actions
47+
path: action_repo
48+
ref: ${{ inputs.action_ref }}
49+
50+
# Checkout project repository
51+
- name: Checkout project repository
52+
uses: actions/checkout@v4
53+
with:
54+
path: main_repo
55+
token: ${{ secrets.GIT_TOKEN }}
56+
57+
# Setup Node.js environment
58+
- name: Setup Node.js
59+
uses: actions/setup-node@v4
60+
with:
61+
node-version: lts/*
62+
63+
# Ensure npm 11.5.1 or later is installed
64+
- name: Update npm
65+
run: npm install -g npm@latest
66+
67+
# Install action dependencies
68+
- name: Install action dependencies
69+
run: npm i --no-package-lock --no-fund --omit=dev
70+
working-directory: action_repo/scripts/release
71+
72+
# Install dependencies
73+
- name: Install dependencies
74+
run: ${{ inputs.install }}
75+
76+
# Run Test Only
77+
- name: Run Test
78+
run: npm test
79+
if: inputs.checkTest
80+
81+
- name: Semantic Release
82+
id: release
83+
run: node ../action_repo/scripts/release/index.js
84+
env:
85+
DRYRUN: ${{ inputs.dryRun }}
86+
87+
- name: Publish ${{ steps.release.outputs.name }}@${{ steps.release.outputs.release_version }}
88+
if: steps.release.outputs.release_version && !inputs.dryRun
89+
run: |
90+
echo ${{ steps.release.outputs.name }}
91+
echo ${{ steps.release.outputs.release_version }}
92+
echo ${{ steps.release.outputs.registry }}
93+
echo ${{ steps.release.outputs.cnpm_sync_url }}

0 commit comments

Comments
 (0)