Skip to content

Commit 668a2ee

Browse files
committed
ci(workflow): 增加自动发布文档脚本
1 parent 3b87a2a commit 668a2ee

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# GitHub Actions 工作流定义文件
2+
# 本文件定义了自动构建和部署VitePress站点到GitHub Pages的完整流程
3+
name: Deploy VitePress site to Pages
4+
5+
on:
6+
# 触发条件1: 当有代码推送到main分支时自动触发工作流
7+
push:
8+
branches: [main]
9+
10+
# 触发条件2: 允许从GitHub仓库的Actions选项卡手动触发工作流
11+
workflow_dispatch:
12+
13+
# 权限设置: 工作流需要的GitHub令牌权限配置
14+
permissions:
15+
contents: read # 允许读取仓库内容
16+
pages: write # 允许写入GitHub Pages
17+
id-token: write # 允许写入身份令牌,用于身份验证
18+
19+
# 并发控制: 确保多次触发时不会相互干扰
20+
concurrency:
21+
group: pages # 并发组名称,基于pages服务
22+
cancel-in-progress: false # 不取消正在进行的部署,确保部署过程不被中断
23+
24+
jobs:
25+
# 第一个任务: 构建站点
26+
build:
27+
runs-on: ubuntu-latest # 使用最新的Ubuntu运行环境
28+
steps:
29+
# 步骤1: 检出代码库
30+
- name: Checkout repository
31+
uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 0
34+
35+
# 步骤2: 设置pnpm包管理器(第一次)
36+
- name: Setup pnpm - initial
37+
uses: pnpm/action-setup@v3
38+
with:
39+
version: 9 # 使用pnpm 9版本
40+
41+
# 步骤3: 设置Node.js环境
42+
- name: Setup Node.js
43+
uses: actions/setup-node@v4
44+
with:
45+
node-version: 20 # 使用Node.js 20版本
46+
47+
# 步骤4: 再次设置pnpm (确保与Node.js配合正常)
48+
- name: Setup pnpm - final
49+
uses: pnpm/action-setup@v3
50+
with:
51+
version: 9
52+
run_install: false # 不自动安装依赖,后面单独安装
53+
54+
# 步骤5: 配置GitHub Pages环境
55+
- name: Setup GitHub Pages
56+
uses: actions/configure-pages@v4
57+
58+
# 步骤6: 安装项目依赖
59+
- name: Install project dependencies
60+
run: pnpm i # 使用pnpm安装所有依赖
61+
62+
# 步骤7: 构建站点
63+
- name: Build site
64+
run: pnpm run build # 执行构建命令,生成静态网站文件
65+
66+
# 步骤8: 上传构建产物
67+
- name: Upload build artifact
68+
uses: actions/upload-pages-artifact@v3
69+
with:
70+
path: dist # 上传dist目录作为部署内容
71+
72+
# 第二个任务: 部署到GitHub Pages
73+
deploy:
74+
environment:
75+
name: github-pages # 部署环境名称
76+
url: ${{ steps.deployment.outputs.page_url }} # 部署后的URL(动态获取)
77+
needs: build # 依赖build任务,即build完成后才会执行deploy
78+
runs-on: ubuntu-latest # 同样使用最新的Ubuntu环境
79+
name: Deploy to Pages
80+
steps:
81+
# 唯一步骤: 将构建产物部署到GitHub Pages
82+
- name: Deploy to GitHub Pages
83+
id: deployment # 步骤ID,用于获取输出变量
84+
uses: actions/deploy-pages@v4 # 使用官方部署Pages的Action

0 commit comments

Comments
 (0)