Skip to content

Commit 9533274

Browse files
committed
ci: auto publish
1 parent 254bed1 commit 9533274

File tree

3 files changed

+110
-18
lines changed

3 files changed

+110
-18
lines changed

.github/workflows/auto-publish.yml

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@ on:
66
- "v*"
77

88
workflow_dispatch:
9+
inputs:
10+
version:
11+
description: 输入您将要发布的版本号(默认使用 packages/fluent-editor/package.json 中的版本号),例如:`0.1.0`。
12+
required: false
13+
type: string
914

1015
jobs:
1116
build:
1217
runs-on: ubuntu-latest
18+
outputs:
19+
version: ${{ steps.ver.outputs.value }}
1320
steps:
1421
- name: CheckOut Code
1522
uses: actions/checkout@master
@@ -39,31 +46,72 @@ jobs:
3946
${{ runner.os }}-pnpm-store-
4047
- name: Install dependencies
4148
run: pnpm i --no-frozen-lockfile
49+
- name: Get version
50+
id: ver
51+
run: |
52+
# 优先用手动输入的版本号
53+
if [ -n "${{ inputs.version }}" ]; then
54+
VERSION="${{ inputs.version }}"
55+
else
56+
VERSION="$(node -p "require('./packages/fluent-editor/package.json').version")"
57+
fi
58+
echo "version: $VERSION"
59+
echo "value=$VERSION" >> $GITHUB_OUTPUT
4260
43-
- name: Run Build search-box
44-
run: pnpm build:lib
61+
- name: Build lib
62+
run: |
63+
pnpm build:lib
64+
cd packages/fluent-editor
65+
echo "version: ${{ steps.ver.outputs.value }}"
66+
pnpm pre-release -v ${{ steps.ver.outputs.value }}
67+
- name: Upload build artifact
68+
uses: actions/upload-artifact@v4
69+
with:
70+
name: dist-artifact
71+
path: packages/fluent-editor/dist/
72+
# Publish job
73+
publish:
74+
needs: build
75+
runs-on: ubuntu-latest
76+
steps:
77+
- name: Download build artifact
78+
uses: actions/download-artifact@v4
79+
with:
80+
name: dist-artifact
81+
path: packages/fluent-editor/dist/
4582

46-
- name: Parse Publish tag
47-
id: parse_tag
83+
- name: Parse Publish version
84+
id: parse_version
4885
run: |
49-
tag_name="${GITHUB_REF#refs/tags/}"
50-
if [[ "$tag_name" == *alpha* ]]; then
86+
version_name="${{ needs.build.outputs.version }}"
87+
if [[ "$version_name" == *alpha* ]]; then
5188
echo "dist_tag=alpha" >> "$GITHUB_OUTPUT"
52-
elif [[ "$tag_name" == *beta* ]]; then
89+
elif [[ "$version_name" == *beta* ]]; then
5390
echo "dist_tag=beta" >> "$GITHUB_OUTPUT"
54-
elif [[ "$tag_name" == *rc* ]]; then
91+
elif [[ "$version_name" == *rc* ]]; then
5592
echo "dist_tag=rc" >> "$GITHUB_OUTPUT"
5693
else
5794
echo "dist_tag=latest" >> "$GITHUB_OUTPUT"
5895
fi
59-
96+
- name: Show tag
97+
run: |
98+
echo "publish tag: ${{ steps.parse_version.outputs.dist_tag }}"
6099
- name: Publish @opentiny/fluent-editor
61-
run: pnpm pub
100+
run: |
101+
echo "ls"
102+
ls
103+
cd packages/fluent-editor/dist
104+
ls
105+
if [ ${{ steps.parse_version.outputs.dist_tag }} == 'latest' ]; then
106+
npm publish
107+
else
108+
npm publish --tag ${{ steps.parse_version.outputs.dist_tag }}
109+
fi
62110
env:
63111
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
64112

65113
- name: Release
66-
if: ${{ steps.parse_tag.outputs.dist_tag == 'latest' }}
114+
if: ${{ steps.parse_version.outputs.dist_tag == 'latest' }}
67115
uses: softprops/action-gh-release@v1
68116
with:
69117
tag_name: ${{ github.ref_name }}

.github/workflows/dispatch-publish.yml

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ run-name: Dispatch Publish
77
on:
88
workflow_dispatch:
99
inputs:
10+
version:
11+
description: 输入您将要发布的版本号(默认使用 packages/fluent-editor/package.json 中的版本号),例如:`0.1.0`。
12+
required: false
13+
type: string
1014
tag:
1115
description: "选择发布/部署版本tag (alpha/beta/rc/latest)"
1216
required: true
@@ -27,6 +31,8 @@ jobs:
2731
build:
2832
# 指定运行环境为最新版本的ubuntu
2933
runs-on: ubuntu-latest
34+
outputs:
35+
version: ${{ steps.ver.outputs.value }}
3036
steps:
3137
# 步骤1: 检出代码
3238
- name: CheckOut Code
@@ -64,14 +70,51 @@ jobs:
6470
# 步骤6: 安装项目依赖
6571
- name: Install dependencies
6672
run: pnpm i --no-frozen-lockfile
73+
- name: Get version
74+
id: ver
75+
run: |
76+
# 优先用手动输入的版本号
77+
if [ -n "${{ inputs.version }}" ]; then
78+
VERSION="${{ inputs.version }}"
79+
else
80+
VERSION="$(node -p "require('./packages/fluent-editor/package.json').version")"
81+
fi
82+
echo "version: $VERSION"
83+
echo "value=$VERSION" >> $GITHUB_OUTPUT
6784
68-
# 步骤7: 构建组件
69-
- name: Run Build Components
70-
run: pnpm build:lib
85+
- name: Build lib
86+
run: |
87+
pnpm build:lib
88+
cd packages/fluent-editor
89+
echo "version: ${{ steps.ver.outputs.value }}"
90+
pnpm pre-release -v ${{ steps.ver.outputs.value }}
91+
- name: Upload build artifact
92+
uses: actions/upload-artifact@v4
93+
with:
94+
name: dist-artifact
95+
path: packages/fluent-editor/dist/
96+
# Publish job
97+
publish:
98+
needs: build
99+
runs-on: ubuntu-latest
100+
steps:
101+
- name: Download build artifact
102+
uses: actions/download-artifact@v4
103+
with:
104+
name: dist-artifact
105+
path: packages/fluent-editor/dist/
106+
- name: Show version and tag
107+
run: |
108+
echo "publish version: ${{ needs.build.outputs.version }}"
109+
echo "publish tag: ${{ inputs.tag }}"
71110
72111
# 步骤8: 发布组件到NPM
73-
- name: Publish components
74-
run: pnpm pub --tag ${{ inputs.tag }}
112+
- name: Publish @opentiny/fluent-editor
113+
run: |
114+
echo "ls"
115+
ls
116+
cd packages/fluent-editor/dist
117+
ls
118+
npm publish --tag ${{ inputs.tag }}
75119
env:
76-
# 使用NPM令牌进行身份验证
77120
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

packages/fluent-editor/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"types": "dist/types/index.d.ts",
2929
"scripts": {
3030
"dev": "vite build --watch",
31-
"build": "vite build && node scripts/pre-release.cjs",
31+
"build": "vite build",
32+
"pre-release": "node scripts/pre-release.cjs",
3233
"test": "jest",
3334
"pub": "cd dist && npm publish"
3435
},

0 commit comments

Comments
 (0)