New action test
Build Sphinx Documentation / Build Documentation from PR Branch (pull_request) Failing after 3m5s
Build Sphinx Documentation / Build Documentation from PR Branch (pull_request) Failing after 3m5s
This commit is contained in:
@@ -1,82 +1,55 @@
|
||||
#For test
|
||||
name: Build and Deploy Sphinx Docs
|
||||
name: Build Sphinx Documentation
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
types: [opened, synchronize, reopened, edited]
|
||||
branches: [master]
|
||||
|
||||
jobs:
|
||||
build-docs:
|
||||
name: Build Documentation
|
||||
name: Build Documentation from PR Branch
|
||||
runs-on: linux
|
||||
|
||||
steps:
|
||||
# 第一步:设置主工作目录和稳定的虚拟环境
|
||||
- name: Set up master worktree with stable environment
|
||||
run: |
|
||||
echo "=== Setting up master worktree ==="
|
||||
# 第一步:检出PR分支代码
|
||||
- name: Checkout PR branch
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.head_ref }} # 检出PR分支而不是主分支
|
||||
fetch-depth: 0
|
||||
|
||||
# 创建主工作目录并克隆仓库
|
||||
if [ ! -d /home/ly0kos/work/test_env ]; then
|
||||
echo "Cloning repository to master worktree..."
|
||||
git clone http://localhost:3000/yuysh/Manlink_Doc.git /home/ly0kos/work/test_env
|
||||
cd /home/ly0kos/work/test_env
|
||||
echo "Creating virtual environment..."
|
||||
python -m venv .venv
|
||||
source .venv/bin/activate
|
||||
echo "Installing dependencies..."
|
||||
pip install --upgrade pip
|
||||
# 第二步:设置Python虚拟环境
|
||||
- name: Set up Python virtual environment
|
||||
run: |
|
||||
echo "Setting up Python environment for PR branch"
|
||||
python -m venv /home/ly0kos/work/test_env/.venv-pr-${{ github.head_ref }}
|
||||
source /home/ly0kos/work/test_env/.venv-pr-${{ github.head_ref }}/bin/activate
|
||||
pip install --upgrade pip
|
||||
if [ -f requirements.txt ]; then
|
||||
pip install -r requirements.txt
|
||||
echo "✓ master worktree and virtual environment created"
|
||||
else
|
||||
echo "Updating existing master worktree..."
|
||||
cd /home/ly0kos/work/test_env
|
||||
git pull origin master
|
||||
source .venv/bin/activate
|
||||
echo "Updating dependencies if needed..."
|
||||
pip install -r requirements.txt
|
||||
echo "✓ master worktree updated"
|
||||
echo "No requirements.txt found, installing sphinx"
|
||||
pip install sphinx
|
||||
fi
|
||||
|
||||
# 验证环境
|
||||
echo "Environment verification:"
|
||||
source .venv/bin/activate
|
||||
echo "Python: $(python --version)"
|
||||
echo "Sphinx-build: $(sphinx-build --version 2>/dev/null || echo 'Not found')"
|
||||
|
||||
# 第二步:创建临时构建工作树
|
||||
- name: Create temporary build worktree
|
||||
# 第三步:构建文档(从PR分支)
|
||||
- name: Build documentation from PR branch
|
||||
run: |
|
||||
echo "=== Creating build worktree ==="
|
||||
cd /home/ly0kos/work/test_env
|
||||
echo "=== Building documentation from PR branch: ${{ github.head_ref }} ==="
|
||||
source /home/ly0kos/work/test_env/.venv-pr-${{ github.head_ref }}/bin/activate
|
||||
|
||||
# 清理可能存在的旧构建目录
|
||||
if [ -d /home/ly0kos/work/test_env/build ]; then
|
||||
echo "Removing old build worktree..."
|
||||
git worktree remove /home/ly0kos/work/test_env/build --force 2>/dev/null || true
|
||||
rm -rf /home/ly0kos/work/test_env/build 2>/dev/null || true
|
||||
fi
|
||||
# 在PR分支目录中构建
|
||||
sphinx-build -b html ./docs ./build -v -j 4
|
||||
|
||||
# 创建新的构建工作树
|
||||
echo "Creating new build worktree..."
|
||||
git worktree add /home/ly0kos/work/test_env/build
|
||||
echo "✓ Build worktree created at /home/ly0kos/work/test_env/build"
|
||||
# 将构建结果移动到共享位置,便于查看
|
||||
rm -rf /home/ly0kos/work/test_env/pr-builds/${{ github.head_ref }}
|
||||
mkdir -p /home/ly0kos/work/test_env/pr-builds/${{ github.head_ref }}
|
||||
cp -r ./build/* /home/ly0kos/work/test_env/pr-builds/${{ github.head_ref }}/
|
||||
|
||||
# 第三步:使用主目录的虚拟环境构建文档
|
||||
- name: Build documentation
|
||||
echo "✓ Build completed for PR branch: ${{ github.head_ref }}"
|
||||
|
||||
# 第四步:验证构建结果
|
||||
- name: Verify build
|
||||
run: |
|
||||
echo "=== Building documentation ==="
|
||||
cd /home/ly0kos/work/test_env
|
||||
source .venv/bin/activate
|
||||
|
||||
echo "Building from: /home/ly0kos/work/test_env/source"
|
||||
echo "Output to: /home/ly0kos/work/test_env/build/build"
|
||||
|
||||
# 使用主目录的虚拟环境来构建构建目录中的代码
|
||||
sphinx-build -b html /home/ly0kos/work/test_env/source /home/ly0kos/work/test_env/build/ -v -j 4
|
||||
echo "✓ Build completed successfully"
|
||||
|
||||
# 验证构建结果
|
||||
echo "Build output contents:"
|
||||
ls -la /home/ly0kos/work/test_env/build/
|
||||
echo "Build output for PR ${{ github.head_ref }}:"
|
||||
ls -la /home/ly0kos/work/test_env/pr-builds/${{ github.head_ref }}/ | head -10
|
||||
Reference in New Issue
Block a user