2025-06-04 16:00:07 +08:00

77 lines
3.0 KiB
YAML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: ci
on:
push:
branches:
- master
- main
# 禁止从 fork 仓库访问 secrets
pull_request:
types: [closed]
branches: [main, master]
permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
sparse-checkout: |
docs
includes
.ai_cache
- uses: actions/setup-python@v4
with:
python-version: 3.x
- name: Set cache ID
run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
- uses: actions/cache@v3
with:
key: mkdocs-material-${{ github.run_number }}
path: .cache
restore-keys: |
mkdocs-material-
- run: pip install mkdocs-git-revision-date-localized-plugin
- run: pip install mkdocs-git-authors-plugin
- run: pip install mkdocs-git-committers-plugin-2
- run: pip install markdown-callouts
- run: pip install mkdocs-rss-plugin
- run: pip install requests>=2.25.0
- run: pip install python-dateutil>=2.8.0
- run: pip install cachetools>=4.2.0
- run: pip install python-dotenv>=0.19.0
- run: pip install pymdown-extensions
- run: pip install mkdocs-material
- run: pip install --upgrade --force-reinstall mkdocs-material
- name: Deploy with AI Summary
env:
# AI摘要开关控制
AI_SUMMARY_CI_ENABLED: 'true' # CI部署环境启用AI摘要 (true=在CI中为文章生成AI摘要)
AI_SUMMARY_CI_ONLY_CACHE: 'true' # CI部署不生成新摘要 (true=使用本地部署过的摘要缓存不再重复调用API)
AI_SUMMARY_CI_FALLBACK: 'true' # CI部署启用备用摘要 (true=API失败时生成离线基础摘要)
# AI_SUMMARY_LOCAL_ENABLED: 'false' # 本地部署环境禁用AI摘要 (true=本地开发时也生成摘要)(不需要管这条)
# AI_SUMMARY_CACHE_ENABLED: 'true' # 本地启用缓存功能 (true=缓存摘要避免重复生成)(不需要管这条)
# API密钥配置
DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: mkdocs gh-deploy --force
# 自动提交新生成的AI缓存文件
- name: Auto-commit AI cache (if any new files)
run: |
if [ -d ".ai_cache" ] && [ "$(ls -A .ai_cache 2>/dev/null)" ]; then
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .ai_cache/
if ! git diff --cached --quiet; then
git commit -m "🤖 Auto-update AI summary cache [skip ci]"
git push
echo "✅ 自动提交了新的 AI 缓存文件"
else
echo " 没有新的缓存文件需要提交"
fi
else
echo " 没有找到缓存目录或缓存为空"
fi