Skip to content

Commit 7be1637

Browse files
committed
ci: 添加可复用的 npm 发布工作流
1 parent a2ea36e commit 7be1637

1 file changed

Lines changed: 136 additions & 0 deletions

File tree

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
name: reusable-publish-npm
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
node-version:
7+
required: false
8+
type: string
9+
default: '22'
10+
11+
node-version-file:
12+
required: false
13+
type: string
14+
default: ''
15+
16+
package-manager:
17+
required: false
18+
type: string
19+
default: npm
20+
21+
surge-token:
22+
required: false
23+
type: string
24+
25+
token:
26+
required: false
27+
type: string
28+
default: ${{ github.token }}
29+
30+
skip-publish-npm:
31+
required: false
32+
type: boolean
33+
default: false
34+
35+
skip-publish-tag-website:
36+
required: false
37+
type: boolean
38+
default: false
39+
40+
skip-publish-official-website:
41+
required: false
42+
type: boolean
43+
default: false
44+
45+
jobs:
46+
publish-npm:
47+
runs-on: ubuntu-latest
48+
if: github.event.ref_type == 'tag' && !inputs.publish-npm
49+
steps:
50+
- uses: actions/checkout@v6.0.2
51+
with:
52+
submodules: recursive
53+
54+
- uses: actions/setup-node@v6.3.0
55+
with:
56+
node-version: ${{ inputs.node-version-file == '' && inputs.node-version || null }}
57+
node-version-file: ${{ inputs.node-version-file != '' && inputs.node-version-file || null }}
58+
59+
- run: ${{ inputs.package-manager }} install
60+
61+
- run: ${{ inputs.package-manager }} run build
62+
63+
- uses: actions/setup-node@v6.3.0
64+
with:
65+
node-version: 24
66+
67+
- id: tag
68+
shell: bash
69+
run: |
70+
tag=${{ contains(github.ref_name, 'beta') && 'beta' || 'latest' }}
71+
echo "tag=$tag" >> $GITHUB_OUTPUT
72+
73+
- name: npm publish
74+
if: ${{ inputs.package-manager == 'npm'}}
75+
uses: JS-DevTools/npm-publish@v4
76+
with:
77+
tag: ${{ steps.tag.outputs.tag }}
78+
79+
- name: pnpm publish
80+
if: ${{ inputs.package-manager == 'pnpm'}}
81+
run: pnpm publish --access public --no-git-checks --tag ${{ steps.tag.outputs.tag }}
82+
83+
publish-tag-website:
84+
runs-on: ubuntu-latest
85+
if: github.event.ref_type == 'tag' && !inputs.publish-tag-website
86+
steps:
87+
- uses: actions/checkout@v6.0.2
88+
with:
89+
submodules: recursive
90+
91+
- uses: pnpm/action-setup@v4.2.0
92+
if: ${{ inputs.package-manager == 'pnpm' }}
93+
94+
- uses: actions/setup-node@v6.3.0
95+
with:
96+
node-version: ${{ inputs.node-version-file == '' && inputs.node-version || null }}
97+
node-version-file: ${{ inputs.node-version-file != '' && inputs.node-version-file || null }}
98+
99+
- run: ${{ inputs.package-manager }} install
100+
101+
- run: ${{ inputs.package-manager }} run site:preview
102+
103+
- id: domain
104+
shell: bash
105+
run: |
106+
repository=${{github.repository}}
107+
project_name=${repository#*/}
108+
ref_name=${{ github.ref_name }}
109+
tag_name=${ref_name//./_}
110+
echo "domain=https://$tag_name-$project_name.surge.sh" >> $GITHUB_OUTPUT
111+
112+
- uses: TDesignOteam/workflows/actions/setup-surge@main
113+
with:
114+
project: _site
115+
domain: ${{ steps.domain.outputs.domain }}
116+
token: ${{ inputs.surge-token }}
117+
118+
publish-official-website:
119+
runs-on: ubuntu-latest
120+
if: github.event.ref_type == 'tag' && !inputs.publish-official-website
121+
steps:
122+
- uses: actions/checkout@v6.0.2
123+
with:
124+
ref: main
125+
fetch-depth: 0
126+
token: ${{ inputs.token }}
127+
submodules: recursive
128+
129+
- name: update official website
130+
run: |
131+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
132+
git config --local user.name "github-actions[bot]"
133+
git status
134+
git fetch origin
135+
git merge origin/develop
136+
git push origin main

0 commit comments

Comments
 (0)