优化字体文件,以及自动化优化字体工作流

This commit is contained in:
Vaica committed 2026-06-03 13:17:56 +08:00
1 parent d035a2179e
commit d6098a94e7
3 files changed
+302 -3

No files matched your search

+3 -3
View File
@@ -51,7 +51,7 @@ jobs:
uses: actions/setup-python@v5 uses: actions/setup-python@v5
with: with:
python-version: '3.11' python-version: '3.11'
cache: 'pip' cache: 'pip' # 使用requirements.txt进行缓存
# 3. 安装Python依赖 # 3. 安装Python依赖
- name: Install dependencies - name: Install dependencies
@@ -135,8 +135,8 @@ jobs:
git add themes/Ying/static/font/zql-v2-subset.* git add themes/Ying/static/font/zql-v2-subset.*
git add themes/Ying/static/font/used_chars.txt git add themes/Ying/static/font/used_chars.txt
# 提交 # 提交(添加[skip ci]避免触发deploy.yml)
git commit -m "chore: update font subset (automated) git commit -m "chore: update font subset (automated) [skip ci]
- Updated font subset based on latest content - Updated font subset based on latest content
- Subset characters: $(wc -c < themes/Ying/static/font/used_chars.txt) chars - Subset characters: $(wc -c < themes/Ying/static/font/used_chars.txt) chars
+2
View File
@@ -0,0 +1,2 @@
fonttools
brotli
+297
View File
@@ -0,0 +1,297 @@
# 🔧 GitHub Actions修复 + 避免冲突指南
## ✅ 问题已修复
### 问题1:Python依赖安装失败
**原因:** 缺少requirements.txt文件,导致cache功能失败
**解决方案:**
- ✅ 创建了 `requirements.txt` 文件
- ✅ 包含 `fonttools` 和 `brotli` 依赖
- ✅ 恢复了cache功能(更快的后续运行)
---
## 🎯 立即修复并提交
### 快速命令(复制粘贴)
```bash
cd E:\GitHub\blog
# 1. 提交requirements.txt
git add requirements.txt
git commit -m "ci: add requirements.txt for GitHub Actions cache"
# 2. 提交所有优化文件
git add themes/Ying/assets/css/main.css themes/Ying/static/font/zql-v2-subset.* themes/Ying/static/font/used_chars.txt .github/workflows/subset-fonts.yml
git commit -m "perf: 完整性能优化 - JS按需加载 + 字体子集化 + 自动化"
# 3. 推送
git push origin main
```
---
## ⚠️ 避免与deploy.yml冲突
### 潜在问题
如果你的deploy.yml也是这样触发的:
```yaml
on:
push:
branches:
- main
```
那么:
1. subset-fonts.yml push → 触发deploy.yml
2. deploy.yml部署完成 → 可能又push
3. 再次触发subset-fonts.yml → **无限循环!**
### 解决方案
#### 方案1:修改deploy.yml(推荐)
**找到你的deploy.yml文件,修改触发条件:**
**原始:**
```yaml
on:
push:
branches:
- main
```
**修改为(排除字体文件):**
```yaml
on:
push:
branches:
- main
paths:
- 'content/**'
- 'layouts/**'
- 'themes/**'
- '!.github/**' # 排除工作流变更
- '!themes/Ying/static/font/zql-v2-subset.*' # 排除字体子集
- '!themes/Ying/static/font/used_chars.txt' # 排除字符列表
- '!requirements.txt' # 排除依赖文件
```
#### 方案2:在subset-fonts.yml中标记自动化提交
我已经在commit消息中添加了标记:
```yaml
git commit -m "chore: update font subset (automated)"
```
**在deploy.yml中添加条件检查:**
```yaml
jobs:
deploy:
# 只在非自动化提交时部署
if: "!contains(github.event.head_commit.message, '(automated)')"
runs-on: ubuntu-latest
steps:
# ... 部署步骤
```
#### 方案3:让subset-fonts.yml不push,只commit
修改subset-fonts.yml,注释掉push步骤:
```yaml
# 9. 推送更改
# - name: Push changes
# if: steps.check.outputs.needs_update == 'true' || github.event.inputs.force_rebuild == 'true'
# run: |
# git push origin main
```
**效果:** 只commit不push,你手动push或通过其他方式触发部署
---
## 🔍 我需要你的帮助
为了给你最准确的避免冲突方案,请告诉我:
### 你的deploy.yml在哪里?
```bash
# 查看所有工作流文件
dir .github\workflows\
# 查看deploy.yml内容
type .github\workflows\deploy.yml
```
### 常见的部署工作流文件名
- `deploy.yml`
- `pages.yml`
- `ci.yml`
- `build.yml`
- `hugo.yml`
**请告诉我:**
1. deploy.yml的文件名
2. 它的触发条件(on: push: 部分)
3. 它是否会push回main分支
---
## 🚀 临时安全方案
在你确认deploy.yml内容之前,先用这个最安全的方案:
### 方案:subset-fonts.yml只commit不push
这样就不会触发deploy.yml:
```yaml
# 9. 推送更改(禁用,避免冲突)
# - name: Push changes
# if: steps.check.outputs.needs_update == 'true' || github.event.inputs.force_rebuild == 'true'
# run: |
# git push origin main
```
**使用方式:**
1. subset-fonts.yml自动commit到main
2. 你手动push,或者通过其他方式触发部署
3. 完全避免循环触发
---
## 📋 推荐的完整工作流
### 日常开发流程
```bash
# 1. 本地开发
git add content/posts/new-article.md
git commit -m "feat: add new article"
# 2. 推送到GitHub
git push origin main
# 3. GitHub Actions自动触发:
# - deploy.yml(部署)
# - subset-fonts.yml(字体优化)
# 4. subset-fonts.yml自动:
# - 构建Hugo
# - 运行字体子集化
# - commit优化后的字体
# - (不push,避免触发deploy)
# 5. 你手动push字体优化
git pull origin main
git push origin main
```
### 如果你想要全自动
需要修改deploy.yml,让它忽略字体优化提交:
```yaml
on:
push:
branches:
- main
paths:
- 'content/**'
- 'layouts/**'
- 'themes/**'
- '!themes/Ying/static/font/**' # 忽略字体目录
```
---
## 🎯 现在该怎么做?
### 立即行动(5分钟)
```bash
# 1. 提交requirements.txt和所有优化
cd E:\GitHub\blog
git add requirements.txt
git commit -m "ci: add requirements.txt"
git add themes/Ying/assets/css/main.css themes/Ying/static/font/zql-v2-subset.* themes/Ying/static/font/used_chars.txt .github/workflows/subset-fonts.yml
git commit -m "perf: 完整性能优化"
# 2. 推送(会触发deploy和subset-fonts)
git push origin main
# 3. 监控Actions
# https://github.com/zqlit/blog/actions
# 4. 如果发现循环触发,立即:
# - 修改deploy.yml(参考上面的方案)
# - 或者禁用subset-fonts.yml的push步骤
```
### 安全起见(推荐)
```bash
# 先只push一次,观察Actions行为
git push origin main
# 如果看到循环触发:
# 1. 立即修改deploy.yml
# 2. 或者禁用subset-fonts.yml
```
---
## 💡 最佳实践
### 避免循环触发的原则
1. **明确触发条件**
- 使用 `paths` 精确控制
- 排除自动化文件
2. **标记自动化提交**
- 在commit消息中添加 `(automated)`
- 在工作流中检查这个标记
3. **使用不同的触发条件**
- deploy:特定路径变更
- subset-fonts:内容目录变更
4. **监控Actions运行**
- 定期检查Actions页面
- 设置失败通知
---
## 📚 相关文档
- **COMMIT_GUIDE.md** - 提交指南
- **GITHUB_ACTIONS_GUIDE.md** - Actions详细说明
- **FINAL_FONT_TEST.md** - 测试指南
---
## ❓ 需要你的帮助
请告诉我:
1. **你的deploy.yml文件名是什么?**
2. **它的触发条件是什么?**
3. **它会push回main吗?**
这样我可以给你最准确的避免冲突方案!
---
**文档版本:** v1.0
**创建时间:** 2026-06-03
**适用场景:** 修复GitHub Actions错误 + 避免工作流冲突