Skip to content

Commit 1b2b73a

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

File tree

2 files changed

+61
-12
lines changed

2 files changed

+61
-12
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 }}

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)