1313# 设置时区
1414env :
1515 TZ : Asia/Shanghai
16+ # 添加节点版本环境变量方便引用
17+ NODE_VERSION : 20
18+ PNPM_VERSION : latest
1619
1720# 权限设置
1821permissions :
@@ -25,68 +28,75 @@ permissions:
2528
2629# 并发控制配置
2730concurrency :
28- group : pages
29- cancel-in-progress : false
31+ group : ${{ github.workflow }}-${{ github.ref }}
32+ cancel-in-progress : true # 取消正在进行的运行,节省资源
3033
3134# 定义执行任务
3235jobs :
3336 # 构建任务
3437 build :
3538 runs-on : ubuntu-latest
3639
37- # node v20 运行
38- strategy :
39- matrix :
40- node-version : [20]
41-
4240 steps :
4341 # 拉取代码
4442 - name : Checkout
45- uses : actions/checkout@v3
43+ uses : actions/checkout@v4
4644 with :
4745 # 保留 Git 信息
4846 fetch-depth : 0
4947
5048 # 设置使用 Node.js 版本
51- - name : Use Node.js ${{ matrix.node-version }}
52- uses : actions/setup-node@v3
49+ - name : Setup Node.js ${{ env.NODE_VERSION }}
50+ uses : actions/setup-node@v4
5351 with :
54- node-version : ${{ matrix.node-version }}
52+ node-version : ${{ env.NODE_VERSION }}
5553
5654 # 使用 最新的 PNPM
5755 # 你也可以指定为具体的版本
58- - uses : pnpm/action-setup@v2
59- name : Install pnpm
56+ - name : Setup PNPM
57+ uses : pnpm/action-setup@v2
6058 with :
61- version : latest
62- # version: 9
59+ version : ${{ env.PNPM_VERSION }}
6360 run_install : false
6461
65- # 安装依赖
66- - name : Install dependencies
62+ # 添加PNPM缓存以加速构建
63+ - name : Get PNPM store directory
64+ shell : bash
65+ run : |
66+ echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
67+
68+ - name : Setup PNPM cache
69+ uses : actions/cache@v3
70+ with :
71+ path : ${{ env.STORE_PATH }}
72+ key : ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
73+ restore-keys : |
74+ ${{ runner.os }}-pnpm-store-
75+
76+ # 安装依赖
77+ - name : Install Dependencies
6778 run : pnpm install --frozen-lockfile
6879
69- # 构建项目
70- # 需要先构建 @mylib/ui 等包后再构建docs
71- # 不能只 pnpm run build:docs 会报如:failed to resolve entry for package "@mylib/hooks"的错误
72- - name : Build docs project
73- run : |
74- echo ${{ github.workspace }}
75- pnpm run build
80+ # 构建项目
81+ # 需要先构建 @mylib/ui 等包后再构建docs
82+ # 不能只 pnpm run build:docs 会报如:failed to resolve entry for package "@mylib/hooks"的错误
83+ - name : Build Project
84+ run : pnpm run build
7685
77- # 资源拷贝
78- - name : Build with Jekyll
86+ # 资源拷贝
87+ - name : Prepare Static Files
7988 uses : actions/jekyll-build-pages@v1
8089 with :
8190 source : ./apps/docs/.vitepress/dist
8291 destination : ./_site
8392
84- # 上传 _site 的资源,用于后续部署
85- - name : Upload artifact
93+ # 上传 _site 的资源,用于后续部署
94+ - name : Upload Pages Artifact
8695 uses : actions/upload-pages-artifact@v3
8796
8897 # 部署任务
8998 deploy :
99+ if : github.event_name == 'push' && github.ref == 'refs/heads/main'
90100 environment :
91101 name : github-pages
92102 url : ${{ steps.deployment.outputs.page_url }}
0 commit comments