GitHub 自动化部署
# GitHub Actions 自动化部署指南
本文介绍如何使用 GitHub Actions 实现博客的自动化部署。
# 一、创建 Workflow 文件
在项目根目录创建 .github/workflows/deploy.yml:
name: Deploy VuePress Blog
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build
run: pnpm build
- name: Deploy
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/.vuepress/dist
cname: guqzhou.eu.org
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
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
# 二、配置 GitHub Pages
- 访问仓库 Settings → Pages
- Source 选择
Deploy from a branch - Branch 选择
gh-pages,目录选择/ (root) - 点击 Save
# 三、配置自定义域名
- 在 Custom domain 输入:
guqzhou.eu.org - 点击 Save
- 勾选 Enforce HTTPS
# 四、配置 DNS
在域名提供商添加 CNAME 记录:
| 类型 | 主机记录 | 值 |
|---|---|---|
| CNAME | @ | guqzhou.github.io |
验证 DNS:
nslookup guqzhou.eu.org
1
# 五、推送代码
git add .
git commit -m "feat: 添加自动部署"
git push origin main
1
2
3
2
3
访问 Actions 页面查看部署状态,等待 2-3 分钟后访问 https://guqzhou.eu.org
# 六、常见问题
构建失败:查看 Actions 日志排查错误
页面 404:检查 config.js 中 base: '/' 配置
DNS 失败:等待 DNS 生效(5-30 分钟)
更新无效:清除浏览器缓存(Cmd/Ctrl + Shift + R)
上次更新: 2026/02/04, 2:02:00