Skip to content

Commit b7f63b1

Browse files
committed
ci: 🤖 添加 GitHub Actions 工作流以部署测试覆盖率到 GitHub Pages
1 parent 464495a commit b7f63b1

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

.github/workflows/test.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Deploy Test Coverage to GitHub Pages
2+
3+
permissions:
4+
contents: write # 允许 GitHub Actions 写入仓库,其中包括创建分支、提交代码等
5+
6+
on:
7+
workflow_dispatch: # 允许手动触发
8+
push:
9+
branches:
10+
- main # 监听 main 分支
11+
12+
jobs:
13+
deploy:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
# region: 前端项目构建前置步骤:检出代码、依赖安装、构建(pnpm、nodejs)
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Setup pnpm
22+
uses: pnpm/action-setup@v4
23+
with:
24+
version: 9 # pnpm 版本,一些pnpm项目带有lockfile的时候,需要版本的匹配,否则可能会报错(pnpm版本不匹配时,会忽略锁文件)
25+
run_install: false
26+
27+
- name: Setup Node.js
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: 20 # Node.js 版本
31+
# node-version-file: ".nvmrc" # 从 .nvmrc 文件中读取 Node.js 版本,与 node-version 二选一
32+
cache: pnpm # 缓存 pnpm
33+
# endregion
34+
35+
# region: 前端项目构建,根据具体项目情况修改,此处以 <https://github.com/uni-ku/bundle-optimizer> 为例
36+
- name: Install dependencies
37+
run: pnpm install
38+
39+
- name: Run Test
40+
run: pnpm run test:coverage
41+
# endregion
42+
43+
# region: 部署到 GitHub Pages,此处采用 peaceiris/actions-gh-pages@v4
44+
# 该插件可以基于之前的构建流程,通过配置 publish_dir 来指定将要发布的目录
45+
# 之后会将 publish_dir 目录下的文件推送到 gh-pages 分支,当然分支名称也是可以配置的
46+
# 最后需要在 GitHub 仓库的 Settings -> Pages 中设置 gh-pages 分支作为 GitHub Pages 的源
47+
- name: Deploy to GitHub Pages
48+
uses: peaceiris/actions-gh-pages@v4
49+
with:
50+
github_token: ${{ secrets.GITHUB_TOKEN }}
51+
publish_dir: ./coverage # 构建输出目录
52+
publish_branch: coverage # 发布分支,可选,默认为 gh-pages
53+
# endregion

0 commit comments

Comments
 (0)