Skip to content

合并拉取请求 #29 #133

合并拉取请求 #29

合并拉取请求 #29 #133

Workflow file for this run

name: Build & Deploy Docs
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch: # 允许手动触发
inputs:
skip_checks:
description: '跳过变更检测,强制构建和部署'
required: false
default: false
type: boolean
permissions:
contents: write
jobs:
build:
# needs: check_changes
# if: needs.check_changes.outputs.should_build == 'true'
runs-on: ubuntu-latest
outputs:
commit_hash: ${{ steps.build-info.outputs.commit_hash }}
commit_hash_long: ${{ steps.build-info.outputs.commit_hash_long }}
commit_message: ${{ steps.build-info.outputs.commit_message }}
python_version: ${{ steps.build-info.outputs.python_version }}
build_date: ${{ steps.build-info.outputs.build_date }}
branch_name: ${{ steps.build-info.outputs.branch_name }}
is_manual_trigger: ${{ github.event_name == 'workflow_dispatch' }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python Environment
uses: actions/setup-python@v5
with:
python-version: 3.12
cache: pip
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
# 确保安装 zensical 和项目依赖
if [ -f requirements.txt ]; then
pip install -r requirements.txt
fi
# 确保 zensical 可用
pip install zensical
- name: Get build information
id: build-info
run: |
echo "commit_hash=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "commit_hash_long=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
echo "commit_message=$(git log -1 --pretty=%B | head -n 1 | tr -d '\n')" >> $GITHUB_OUTPUT
echo "python_version=$(python --version | cut -d' ' -f2)" >> $GITHUB_OUTPUT
echo "build_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> $GITHUB_OUTPUT
echo "branch_name=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
echo "is_manual_trigger=${{ github.event_name == 'workflow_dispatch' }}" >> $GITHUB_OUTPUT
- name: Build Document
run: zensical build
- name: Upload Site Artifact
uses: actions/upload-artifact@v4
with:
name: site
path: site
retention-days: 1
deploy_build:
# needs: [check_changes, build]
needs: [build]
# if: needs.check_changes.outputs.should_build == 'true' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/download-artifact@v4
with:
name: site
path: ./site
- name: Deploy to build branch
# if: steps.check_build_changes.outputs.no_changes == 'false'
run: |
# 修复:使用更简单直接的方法部署到 build 分支
cd $GITHUB_WORKSPACE
# 删除现有的 build 分支(如果存在)并重新创建
git branch -D build 2>/dev/null || true
git checkout --orphan build
# 清空当前分支内容
git rm -rf . || true
# 复制新构建的文件
cp -r ./site/* ./
# 添加所有文件
git add .
# 配置 Git 用户
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
# 提交更改
git commit -m "Build: ${{ needs.build.outputs.commit_hash }} from ${{ needs.build.outputs.branch_name }}
Python: ${{ needs.build.outputs.python_version }}
Message: ${{ needs.build.outputs.commit_message }}
Date: ${{ needs.build.outputs.build_date }}
Manual Trigger: ${{ needs.build.outputs.is_manual_trigger }}"
# 推送到 build 分支
git push -f origin build
echo "✅ Successfully deployed to build branch"
deploy_pages:
needs: [build]
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/download-artifact@v4
with:
name: site
path: ./site
- name: Deploy to gh-pages branch
# if: steps.check_pages_changes.outputs.no_changes == 'false'
run: |
# 修复:使用更简单直接的方法部署到 gh-pages 分支
cd $GITHUB_WORKSPACE
# 删除现有的 gh-pages 分支(如果存在)并重新创建
git branch -D gh-pages 2>/dev/null || true
git checkout --orphan gh-pages
# 清空当前分支内容
git rm -rf . || true
# 复制新构建的文件
cp -r ./site/* ./
# 添加 CNAME 文件(如果域名配置需要)
echo "docs.master-gui.cn" > CNAME
# 添加所有文件
git add .
# 配置 Git 用户
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
# 提交更改
git commit -m "gh-pages: ${{ needs.build.outputs.commit_hash }} from ${{ needs.build.outputs.branch_name }}
Python: ${{ needs.build.outputs.python_version }}
Message: ${{ needs.build.outputs.commit_message }}
Date: ${{ needs.build.outputs.build_date }}
Manual Trigger: ${{ needs.build.outputs.is_manual_trigger }}"
# 推送到 gh-pages 分支
git push -f origin gh-pages
echo "✅ Successfully deployed to gh-pages branch"