Skip to content

Commit 4251bb6

Browse files
committed
ops: 迁移到 GitHub Actions 自动部署
重大架构变更: - 新增 GitHub Actions 工作流 (.github/workflows/build-and-deploy.yml) - 自动检测并修复图片 alt 属性缺失 - 自动编译 Pelican 站点 - 自动部署到 GitHub Pages - 新增 fix_image_alt.py 脚本用于自动修复图片 alt 属性 - 修复多个 Markdown 文件问题: - 删除重复的 content/pyrecap/2024-44.md - 修复 content/pyrecap/2025-23.md slug 冲突 (pyrw-2522 -> pyrw-2523) - 为 15 个文件补充图片 alt 属性 - 更新 README.md 文档,说明新的部署流程 废弃: inv pub / fab deploy 本地部署方式 新流程: git push 后自动构建部署 Refs: #gh-actions-migration
1 parent ea1499c commit 4251bb6

21 files changed

Lines changed: 5559 additions & 5549 deletions

.github/workflows/README.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# GitHub Actions 自动化部署
2+
3+
## 概述
4+
5+
此 GitHub Actions 工作流替代了原有的 `inv pub` 命令,实现了自动化构建和部署。
6+
7+
## 触发条件
8+
9+
工作流在以下情况下触发:
10+
- 推送到 `master``main` 分支
11+
- 修改了 `content/` 目录下的文件
12+
- 修改了主题或配置文件
13+
- 手动触发(workflow_dispatch)
14+
15+
## 工作流程
16+
17+
```
18+
┌─────────────┐
19+
│ Push 代码 │
20+
└──────┬──────┘
21+
22+
┌─────────────┐
23+
│ 检出代码 │
24+
└──────┬──────┘
25+
26+
┌─────────────┐
27+
│ 安装依赖 │
28+
└──────┬──────┘
29+
30+
┌─────────────┐ 有警告 ┌─────────────┐
31+
│ 首次构建 │───────────────▶│ 修复图片alt │
32+
└──────┬──────┘ └──────┬──────┘
33+
│ 无警告 │
34+
▼ ▼
35+
┌─────────────┐ ┌─────────────┐
36+
│ 检查完成 │◀───────────────│ 提交修复 │
37+
└──────┬──────┘ └─────────────┘
38+
39+
┌─────────────┐
40+
│ 部署到Pages │
41+
└─────────────┘
42+
```
43+
44+
## 功能特点
45+
46+
1. **自动修复图片 alt 属性**
47+
- 检测缺少 alt 属性的图片
48+
- 根据图片文件名自动生成 alt 文本
49+
- 提交修复后重新构建
50+
51+
2. **零配置部署**
52+
- 使用 GitHub Pages 官方部署机制
53+
- 无需手动管理 `output` 分支
54+
55+
3. **并发控制**
56+
- 使用 concurrency 防止并发构建冲突
57+
58+
## 迁移说明
59+
60+
### 之前的工作流程 (inv pub)
61+
62+
```bash
63+
inv pub
64+
# 执行:
65+
# 1. git pull
66+
# 2. pelican build
67+
# 3. git commit content
68+
# 4. git commit output
69+
# 5. git push
70+
```
71+
72+
### 新的工作流程
73+
74+
1. 本地编辑 Markdown 文件
75+
2. 提交并推送: `git add . && git commit -m "..." && git push`
76+
3. GitHub Actions 自动完成构建和部署
77+
78+
## 本地测试
79+
80+
```bash
81+
# 安装依赖
82+
pip install pelican markdown beautifulsoup4
83+
84+
# 本地构建
85+
pelican content -o output -s pelicanconf.py
86+
87+
# 本地预览
88+
cd output && python -m http.server
89+
```
90+
91+
## 故障排查
92+
93+
### 构建失败
94+
95+
查看 GitHub Actions 日志:
96+
1. 进入仓库的 Actions 标签页
97+
2. 点击失败的 workflow run
98+
3. 查看具体步骤的日志
99+
100+
### 图片 alt 警告
101+
102+
如果收到图片 alt 警告,工作流会自动修复并重新提交。你可以在提交历史中看到这些自动修复。
103+
104+
### 手动触发
105+
106+
如果需要手动触发部署:
107+
1. 进入 Actions 标签页
108+
2. 选择 "Build and Deploy Weekly"
109+
3. 点击 "Run workflow"
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: Build and Deploy Weekly
2+
3+
on:
4+
push:
5+
branches: [master, main]
6+
paths:
7+
- 'content/**'
8+
- '_themes/**'
9+
- 'pelicanconf.py'
10+
- 'publishconf.py'
11+
- 'fix_image_alt.py'
12+
- '.github/workflows/**'
13+
workflow_dispatch:
14+
15+
permissions:
16+
contents: write
17+
pages: write
18+
id-token: write
19+
20+
concurrency:
21+
group: "pages"
22+
cancel-in-progress: false
23+
24+
jobs:
25+
build:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout source
29+
uses: actions/checkout@v4
30+
with:
31+
submodules: false
32+
fetch-depth: 0
33+
34+
- name: Setup Python
35+
uses: actions/setup-python@v5
36+
with:
37+
python-version: '3.11'
38+
cache: 'pip'
39+
40+
- name: Install dependencies
41+
run: |
42+
pip install pelican markdown beautifulsoup4 typogrify feedgenerator
43+
44+
- name: Build site (first pass)
45+
id: build1
46+
run: |
47+
pelican content -o output -s pelicanconf.py 2>&1 | tee build.log
48+
echo "build_status=${PIPESTATUS[0]}" >> $GITHUB_OUTPUT
49+
continue-on-error: true
50+
51+
- name: Check for image alt warnings
52+
id: check_alt
53+
run: |
54+
if grep -q "Empty alt attribute for image" build.log; then
55+
echo "has_alt_warnings=true" >> $GITHUB_OUTPUT
56+
echo "发现图片缺少 alt 属性,准备自动修复..."
57+
else
58+
echo "has_alt_warnings=false" >> $GITHUB_OUTPUT
59+
fi
60+
61+
- name: Fix image alt attributes
62+
if: steps.check_alt.outputs.has_alt_warnings == 'true'
63+
run: |
64+
python fix_image_alt.py content
65+
66+
- name: Commit fixes
67+
if: steps.check_alt.outputs.has_alt_warnings == 'true'
68+
run: |
69+
git config --local user.email "action@github.com"
70+
git config --local user.name "GitHub Action"
71+
git add -A
72+
git diff --cached --quiet || git commit -m "Auto-fix: 补充图片 alt 属性 [skip ci]"
73+
git push
74+
75+
- name: Rebuild site (after fix)
76+
if: steps.check_alt.outputs.has_alt_warnings == 'true'
77+
run: |
78+
pelican content -o output -s pelicanconf.py
79+
80+
- name: Build site (final)
81+
if: steps.check_alt.outputs.has_alt_warnings != 'true' && steps.build1.outputs.build_status == '0'
82+
run: |
83+
pelican content -o output -s pelicanconf.py
84+
85+
- name: Check build success
86+
run: |
87+
if [ ! -f output/index.html ]; then
88+
echo "构建失败:未找到 index.html"
89+
exit 1
90+
fi
91+
echo "构建成功!"
92+
93+
- name: Setup Pages
94+
uses: actions/configure-pages@v5
95+
96+
- name: Upload artifact
97+
uses: actions/upload-pages-artifact@v3
98+
with:
99+
path: './output'
100+
101+
deploy:
102+
environment:
103+
name: github-pages
104+
url: ${{ steps.deployment.outputs.page_url }}
105+
runs-on: ubuntu-latest
106+
needs: build
107+
steps:
108+
- name: Deploy to GitHub Pages
109+
id: deployment
110+
uses: actions/deploy-pages@v4

README.md

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,31 @@ main loop:
8181

8282
### deploy
8383

84-
支持本地调试! 使用 `fabric` 进行管理, 支持的命令:
84+
#### 新方式:GitHub Actions 自动部署(推荐)
8585

86-
fab
87-
Available commands:
86+
从 2025-02-14 起,本项目已迁移到 **GitHub Actions 自动部署**
8887

89-
build 编译所有页面
90-
deploy 向主机部署所有页面
91-
reserve 重编译所有页面再启动本地服务
92-
serve 启动本地服务 localhost:8000
88+
1. 编辑 `content/` 目录下的 Markdown 文件
89+
2. 提交并推送到 `master` 分支:`git push origin master`
90+
3. GitHub Actions 自动完成:
91+
- 检测并修复图片缺失的 alt 属性
92+
- 编译 Pelican 静态站点
93+
- 部署到 GitHub Pages
9394

95+
**触发条件**:修改 `content/``_themes/``pelicanconf.py` 等文件时自动触发
9496

95-
`注意!` 向主机部署,需要有相关权限,并在本地配置好对应 SSH 信息
97+
#### 旧方式:本地 fabric 部署(已废弃)
98+
99+
~支持本地调试! 使用 `fabric` 进行管理, 支持的命令:~(不再维护)
100+
101+
~fab~
102+
~Available commands:~
103+
~build 编译所有页面~
104+
~deploy 向主机部署所有页面~
105+
~reserve 重编译所有页面再启动本地服务~
106+
~serve 启动本地服务 localhost:8000~
107+
108+
~`注意!` 向主机部署,需要有相关权限,并在本地配置好对应 SSH 信息~
96109

97110
### design
98111

@@ -131,6 +144,12 @@ main loop:
131144

132145
## changelog
133146

147+
- **250214 ZQ 重大架构变更:迁移到 GitHub Actions 自动部署**
148+
- 修复多个 Markdown 元数据格式错误(Slug 冲突、Title 缺失)
149+
- 新增 `fix_image_alt.py` 脚本自动修复图片 alt 属性
150+
- 创建 `.github/workflows/build-and-deploy.yml` 自动化工作流
151+
- 废弃 `inv pub` / `fab deploy` 本地部署方式
152+
- 简化发布流程:推送代码即可自动构建部署
134153
- 191028 ZQ 提醒本地发布环境
135154
- 190818 ZQ ++ CNZZ WA support
136155
- 131219 base pelican build and through qiniu.com publish

content/Issue/issue-181.md

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)