Skip to content

Commit 4f4674b

Browse files
committed
ci: 重写 CI/CD 工作流
- 简化工作流结构 - 分离 build 和 publish job - 使用 artifact 传递构建结果 - 移除复杂条件判断
1 parent 6952859 commit 4f4674b

File tree

1 file changed

+36
-38
lines changed

1 file changed

+36
-38
lines changed

.github/workflows/npm-publish.yml

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,66 @@
1-
name: Publish to npm
1+
name: Build and Publish
22

33
on:
44
push:
55
branches: [main]
6-
tags:
7-
- 'v*'
6+
tags: ['v*']
87
workflow_dispatch:
98

109
jobs:
11-
publish:
10+
build:
1211
runs-on: ubuntu-latest
13-
permissions:
14-
contents: read
15-
id-token: write
16-
1712
steps:
18-
- name: Checkout
19-
uses: actions/checkout@v4
20-
13+
- uses: actions/checkout@v4
14+
2115
- name: Setup Node.js
2216
uses: actions/setup-node@v4
2317
with:
2418
node-version: '20'
25-
registry-url: 'https://registry.npmjs.org'
2619

2720
- name: Install dependencies
2821
run: npm ci
2922

3023
- name: Build
3124
run: npm run build
32-
33-
- name: Extract version
34-
id: version
35-
run: |
36-
VERSION=$(node -p "require('./package.json').version")
37-
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
38-
echo "Found version: $VERSION"
39-
40-
- name: Check version tag
41-
id: check-tag
42-
run: |
43-
TAG_VERSION="v${{ steps.version.outputs.VERSION }}"
44-
echo "Checking for tag: $TAG_VERSION"
45-
if git rev-parse "refs/tags/$TAG_VERSION" > /dev/null 2>&1; then
46-
echo "tag_exists=true" >> $GITHUB_OUTPUT
47-
echo "Tag exists, will publish"
48-
else
49-
echo "tag_exists=false" >> $GITHUB_OUTPUT
50-
echo "Tag does not exist, skipping publish"
51-
fi
25+
env:
26+
CI: true
27+
28+
- name: Upload build artifact
29+
uses: actions/upload-artifact@v4
30+
with:
31+
name: dist
32+
path: dist/
33+
34+
publish:
35+
needs: build
36+
runs-on: ubuntu-latest
37+
if: startsWith(github.ref, 'refs/tags/v')
38+
steps:
39+
- uses: actions/checkout@v4
40+
41+
- name: Download artifact
42+
uses: actions/download-artifact@v4
43+
with:
44+
name: dist
45+
path: dist/
46+
47+
- name: Setup Node.js
48+
uses: actions/setup-node@v4
49+
with:
50+
node-version: '20'
51+
registry-url: 'https://registry.npmjs.org'
5252

53-
- name: Publish to npm (on tag)
54-
if: steps.check-tag.outputs.tag_exists == 'true'
53+
- name: Publish to npm
5554
run: npm publish --access public
5655
env:
5756
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
5857

59-
- name: Create Release (on tag)
60-
if: steps.check-tag.outputs.tag_exists == 'true'
58+
- name: Create GitHub Release
6159
uses: actions/create-release@v1
6260
env:
6361
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6462
with:
65-
tag_name: v${{ steps.version.outputs.VERSION }}
66-
release_name: TaskFlow AI v${{ steps.version.outputs.VERSION }}
63+
tag_name: ${{ github.ref }}
64+
release_name: TaskFlow AI ${{ github.ref }}
6765
draft: false
6866
prerelease: false

0 commit comments

Comments
 (0)