forked from opentiny/tiny-robot
-
Notifications
You must be signed in to change notification settings - Fork 0
126 lines (110 loc) · 4.03 KB
/
Copy pathauto-publish.yml
File metadata and controls
126 lines (110 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# 工作流名称
name: Auto Publish
# 运行时显示的名称
run-name: Auto Publish
# 触发条件配置
on:
push:
tags:
- 'v*'
# 定义工作流中的作业
jobs:
build:
# 指定运行环境为最新版本的ubuntu
runs-on: ubuntu-latest
steps:
# 步骤1: 检出代码
- name: CheckOut Code
uses: actions/checkout@v5
with:
ref: ${{ github.ref_name }}
# 步骤2: 设置pnpm包管理器
- name: Setup pnpm
uses: pnpm/action-setup@v5
# 步骤3: 设置Node.js环境
- name: Setup Node
uses: actions/setup-node@v5
with:
node-version: 22 # 使用Node.js 22版本
package-manager-cache: false
registry-url: 'https://registry.npmjs.org' # 设置npm registry地址
# 步骤4: 获取pnpm缓存目录路径
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
# 步骤5: 配置pnpm缓存
- uses: actions/cache@v5
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
# 使用操作系统类型和依赖配置文件的哈希值作为缓存键
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/package.json', 'pnpm-workspace.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
# 步骤6: 安装项目依赖
- name: Install dependencies
run: pnpm i --no-frozen-lockfile
# 步骤7: 构建组件
- name: Run Build Components
run: pnpm build
- name: Parse Publish tag
id: parse_tag
run: |
tag_name="${GITHUB_REF#refs/tags/}"
if [[ "$tag_name" == *alpha* ]]; then
echo "dist_tag=alpha" >> "$GITHUB_OUTPUT"
elif [[ "$tag_name" == *beta* ]]; then
echo "dist_tag=beta" >> "$GITHUB_OUTPUT"
elif [[ "$tag_name" == *rc* ]]; then
echo "dist_tag=rc" >> "$GITHUB_OUTPUT"
else
echo "dist_tag=latest" >> "$GITHUB_OUTPUT"
fi
- name: Verify clean working directory
run: |
if [[ -n "$(git status --porcelain)" ]]; then
echo "Working directory is not clean"
exit 1
fi
- name: Verify package version match tag
run: |
tag_name="${GITHUB_REF#refs/tags/}"
package_version=$(pnpm lerna list --scope=@opentiny/tiny-robot --json | jq -r '.[0].version')
if [[ "$tag_name" != "v$package_version" ]]; then
echo "Tag name $tag_name does not match package version $package_version"
exit 1
fi
# 步骤8: 发布组件到NPM
- name: Publish components
run: pnpm lerna publish from-package --pre-dist-tag ${{steps.parse_tag.outputs.dist_tag}} --yes
env:
# 使用NPM令牌进行身份验证
NODE_AUTH_TOKEN: ${{ secrets.NPM_OPENTINY_ROBOT_TOKEN }}
# 步骤9: 发布组件到GitHub Release
- name: Release
if: ${{ steps.parse_tag.outputs.dist_tag == 'latest' }}
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref_name }}
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
# 步骤10: 构建文档
- name: Build VitePress
run: pnpm build:docs --nocomponents
env:
VITEPRESS_BASE: /tiny-robot/${{steps.parse_tag.outputs.dist_tag}}/
PLAYGROUND_BASE: /tiny-robot/${{steps.parse_tag.outputs.dist_tag}}/playground
- name: Verify build output
run: ls -la ./docs/dist
- name: Deploy docs
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/dist
destination_dir: ./${{steps.parse_tag.outputs.dist_tag}}/
keep_files: true
force_orphan: false
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'