-
Notifications
You must be signed in to change notification settings - Fork 497
243 lines (210 loc) · 7.13 KB
/
pull-request.yml
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
name: MAIN_PULL_REQUEST
on:
pull_request:
branches: [develop, main, compositionAPI]
# opened:当 PR 创建时触发
# synchronize:当 PR 的源分支有新的提交时触发
# reopened:当关闭的 PR 重新打开时触发
types: [opened, synchronize, reopened]
# workflow_dispatch:允许手动触发工作流
workflow_dispatch:
# todo: paopao
# jobs:
# call-test-build:
# uses: Tencent/tdesign/.github/workflows/test-build.yml@main
jobs:
check:
# 在最新版本的 Ubuntu 环境中运行
runs-on: ubuntu-latest
steps:
# 检出代码仓库
- uses: actions/checkout@v4
# 检查 GitHub 提交记录中的邮箱
- name: check_github_primary_email
run: |
# 获取最新提交的作者邮箱和提交者邮箱
log_emails=$(git log --pretty=format:"%ae %ce" -1)
# 如果邮箱包含 'tdesign@tencent.com',跳过验证
if [[ ${log_emails} =~ 'tdesign@tencent.com' ]];then
echo "$log_emails 跳过验证"
exit 0
fi
# 如果邮箱包含 '@tencent.com',校验失败,提示用户更改邮箱
if [[ ${log_emails} =~ '@tencent.com' ]];then
echo "默认邮箱 $log_emails 校验非法,可以去 https://github.com/settings/emails 更改"
exit 2;
else
# 否则,校验通过
echo "邮箱 $log_emails 校验通过";
fi
# 再次检出代码仓库,这次使用 PR 的源分支的 SHA
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
# 检查本地提交记录中的邮箱
- name: check_local_email
run: |
# 获取最新提交的作者邮箱和提交者邮箱
log_emails=$(git log --pretty=format:"%ae %ce" -1)
# 如果邮箱包含 'tdesign@tencent.com',跳过验证
if [[ ${log_emails} =~ 'tdesign@tencent.com' ]];then
echo "$log_emails 跳过验证"
exit 0
fi
# 如果邮箱包含 '@tencent.com',校验失败,提示用户更改本地邮箱
if [[ ${log_emails} =~ '@tencent.com' ]];then
echo "本地提交邮箱 $log_emails 校验非法,需要本地更改重新提交"
exit 2;
else
# 否则,校验通过
echo "邮箱 $log_emails 校验通过";
fi
test:
# 如果需要依赖 check 任务,可以取消注释
# needs: check
# 在最新版本的 Ubuntu 环境中运行
runs-on: ubuntu-latest
steps:
# 检出代码仓库,并递归初始化子模块
- uses: actions/checkout@v4
with:
submodules: recursive
# 设置 pnpm
- name: Setup pnpm
uses: pnpm/action-setup@v4
# 设置 Node.js 环境,版本为 18
- uses: actions/setup-node@v4
with:
node-version: 18
# 获取 pnpm 的存储目录路径
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
# 设置 pnpm 缓存
- uses: actions/cache@v4
name: Setup pnpm cache
with:
# 缓存路径
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
# 缓存键
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
# 恢复缓存的备用键
restore-keys: |
${{ runner.os }}-pnpm-store-
# 安装依赖
- run: pnpm i
# 运行代码 lint 检查
- run: pnpm run lint
# 运行测试
- run: pnpm run test
# upload report to codecov
# 将测试报告上传到 Codecov
- uses: codecov/codecov-action@v2
with:
# 使用 GitHub Secrets 中的 Codecov Token
token: ${{ secrets.CODECOV_TOKEN }}
site:
# 在最新版本的 Ubuntu 环境中运行
runs-on: ubuntu-latest
# 如果需要依赖 test 任务,可以取消注释
# needs: test
steps:
# 检出代码仓库,并递归初始化子模块
- uses: actions/checkout@v4
with:
submodules: recursive
# 设置 pnpm
- name: Setup pnpm
uses: pnpm/action-setup@v4
# 设置 Node.js 环境,版本为 18
- uses: actions/setup-node@v4
with:
node-version: 18
# 获取 pnpm 的存储目录路径
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
# 设置 pnpm 缓存
- uses: actions/cache@v4
name: Setup pnpm cache
with:
# 缓存路径
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
# 缓存键
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
# 恢复缓存的备用键
restore-keys: |
${{ runner.os }}-pnpm-store-
# 安装依赖
- run: pnpm i
# 构建站点
- name: Build site
run: pnpm run site:preview
# 将构建的站点文件压缩为 zip
- run: |
zip -r _site.zip _site
# 上传站点文件作为构建产物
- name: upload _site artifact
uses: actions/upload-artifact@v4
with:
# 产物名称
name: _site
# 产物路径
path: _site.zip
# 产物保留天数
retention-days: 5
# 保存 PR 编号到文件
- name: Save PR number
# 无论任务成功或失败都执行
if: ${{ always() }}
run: echo ${{ github.event.number }} > ./pr-id.txt
# 上传 PR 编号文件作为构建产物
- name: Upload PR number
# 无论任务成功或失败都执行
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
# 产物名称
name: pr
# 产物路径
path: ./pr-id.txt
build:
# 在最新版本的 Ubuntu 环境中运行
runs-on: ubuntu-latest
# 如果需要依赖自身任务,可以取消注释(通常不需要)
# needs: build
steps:
# 检出代码仓库,并递归初始化子模块
- uses: actions/checkout@v4
with:
submodules: recursive
# 设置 pnpm
- name: Setup pnpm
uses: pnpm/action-setup@v4
# 设置 Node.js 环境,版本为 18
- uses: actions/setup-node@v4
with:
node-version: 18
# 获取 pnpm 的存储目录路径
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
# 设置 pnpm 缓存
- uses: actions/cache@v4
name: Setup pnpm cache
with:
# 缓存路径
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
# 缓存键
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
# 恢复缓存的备用键
restore-keys: |
${{ runner.os }}-pnpm-store-
# 安装依赖
- run: pnpm i
# 运行构建任务
- name: Build
run: pnpm run build