Skip to content

Commit d78dc4b

Browse files
committed
ci(release): add automated npm publishing workflow
1 parent debbf9e commit d78dc4b

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

.github/workflows/release.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Release
2+
3+
on:
4+
workflow_run:
5+
workflows: ["CI"]
6+
types:
7+
- completed
8+
branches:
9+
- master
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: write
14+
id-token: write
15+
16+
jobs:
17+
release:
18+
name: Release to npm
19+
runs-on: ubuntu-latest
20+
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
21+
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
28+
- name: Setup Node.js
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: '18'
32+
cache: 'yarn'
33+
registry-url: 'https://registry.npmjs.org'
34+
35+
- name: Install dependencies
36+
run: yarn install --frozen-lockfile
37+
38+
- name: Build packages
39+
run: yarn build
40+
41+
- name: Check for changes
42+
id: check-changes
43+
run: |
44+
# 检查是否有待发布的变更
45+
if yarn lerna changed --json | jq -e 'length > 0' > /dev/null; then
46+
echo "has-changes=true" >> $GITHUB_OUTPUT
47+
echo "Found packages with changes to publish"
48+
else
49+
echo "has-changes=false" >> $GITHUB_OUTPUT
50+
echo "No packages have changes to publish"
51+
fi
52+
53+
- name: Publish to npm
54+
if: steps.check-changes.outputs.has-changes == 'true'
55+
env:
56+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
57+
run: |
58+
yarn lerna publish from-package --yes

lerna.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
"version": "independent",
55
"command": {
66
"version": {
7-
"allowBranch": "master"
7+
"allowBranch": "master",
8+
"conventionalCommits": true,
9+
"message": "chore(release): publish",
10+
"push": true,
11+
"createRelease": false
12+
},
13+
"publish": {
14+
"ignoreChanges": ["**/*.md", "**/test/**", "**/*.test.*"],
15+
"registry": "https://registry.npmjs.org/"
816
}
917
},
1018
"ignoreChanges": ["**/*.md", "**/test/**"]

0 commit comments

Comments
 (0)