-
Notifications
You must be signed in to change notification settings - Fork 5
92 lines (77 loc) · 2.46 KB
/
deploy.yml
File metadata and controls
92 lines (77 loc) · 2.46 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
name: Deploy VitePress site to Pages
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: pages
cancel-in-progress: true
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# 1️⃣ Checkout 仓库
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
# 2️⃣ 安装 pnpm
- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 10.6.5
# 3️⃣ 安装 Node 并启用 pnpm 缓存
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
# 4️⃣ 确认 pnpm 可用
- name: Check pnpm version
run: pnpm -v
# 5️⃣ 安装依赖
- name: Install dependencies
run: pnpm install
# 6️⃣ 构建 VitePress
- name: Build VitePress
run: pnpm build:docs
# 7️⃣ 检查构建产物
- name: Check build output
run: |
echo "Checking VitePress build output..."
echo "Current working directory: $(pwd)"
echo "Contents of docs:"
ls -la docs/
echo "Contents of docs/.vitepress:"
ls -la docs/.vitepress/ || echo ".vitepress directory not found"
echo "Contents of docs/.vitepress/dist:"
ls -la docs/.vitepress/dist/ || echo "dist directory not found"
# 8️⃣ 添加 .nojekyll,防止 GitHub Pages 忽略 _ 文件夹
- name: Add .nojekyll
run: |
if [ -d "docs/.vitepress/dist" ]; then
touch docs/.vitepress/dist/.nojekyll
echo "Created .nojekyll file"
else
echo "Error: VitePress dist directory not found"
exit 1
fi
# 9️⃣ 配置 GitHub Pages
- name: Setup GitHub Pages
uses: actions/configure-pages@v4
# 🔟 上传构建产物(仅上传 dist,不包含 docs 源码,显著减小 artifact 体积、加快上传)
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/.vitepress/dist
# 🔟 部署到 GitHub Pages
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
# 1️⃣1️⃣ 打印访问 URL(可选)
- name: Show Pages URL
run: echo "Your site is published at ${{ steps.deployment.outputs.page_url }}"