Updated workflow #23

Open
yuysh wants to merge 1 commits from Action_Debug into master
2 changed files with 99 additions and 60 deletions
Showing only changes of commit c6f664085e - Show all commits
+87 -49
View File
@@ -11,80 +11,118 @@ jobs:
runs-on: linux runs-on: linux
steps: steps:
# 第一步:更新主工作树 # 第一步: 设置主工作树和虚拟环境
- name: Update main worktree - name: Setup main worktree and virtual environment
run: | run: |
echo "=== Updating main worktree ===" echo "=== Setting up main worktree ==="
# 如果主目录不存在,克隆仓库
if [ ! -d "/home/ly0kos/work/test_env" ]; then
echo "Cloning repository to main worktree..."
git clone http://localhost:3000/yuysh/Manlink_Doc.git /home/ly0kos/work/test_env
cd /home/ly0kos/work/test_env cd /home/ly0kos/work/test_env
# 创建共享虚拟环境
python3 -m venv .venv-shared
source .venv-shared/bin/activate
pip install --upgrade pip
pip install sphinx sphinx-rtd-theme
# 记录初始依赖状态
if [ -f "requirements.txt" ]; then
pip install -r requirements.txt
stat -c %Y requirements.txt > .venv-shared/last_update.txt
fi
else
cd /home/ly0kos/work/test_env
git fetch --all --prune git fetch --all --prune
git checkout master git checkout master
git pull origin master git pull origin master
fi
echo "✓ Main worktree updated" echo "✓ Main worktree ready"
# 第二步:复用共享虚拟环境 # 第二步: 为PR分支创建工作树
- name: Create worktree for PR branch
run: |
echo "=== Creating worktree for PR branch: ${{ github.head_ref }} ==="
cd /home/ly0kos/work/test_env
# 清理可能存在的旧工作树
WORKTREE_DIR="/home/ly0kos/work/test_env/worktrees/${{ github.head_ref }}"
if [ -d "$WORKTREE_DIR" ]; then
echo "Removing existing worktree..."
git worktree remove "$WORKTREE_DIR" --force 2>/dev/null || true
rm -rf "$WORKTREE_DIR" 2>/dev/null || true
fi
# 创建新的工作树
mkdir -p "/home/ly0kos/work/test_env/worktrees"
git fetch origin ${{ github.head_ref }}:${{ github.head_ref }} --force
git worktree add "/home/ly0kos/work/test_env/worktrees/${{ github.head_ref }}" ${{ github.head_ref }} --force
echo "✓ Worktree created at: /home/ly0kos/work/test_env/worktrees/${{ github.head_ref }}"
# 第三步: 复用共享虚拟环境并检查依赖更新
- name: Reuse shared virtual environment - name: Reuse shared virtual environment
run: | run: |
echo "=== Using shared virtual environment ===" echo "=== Reusing shared virtual environment ==="
cd /home/ly0kos/work/test_env cd /home/ly0kos/work/test_env
WORKTREE_DIR="/home/ly0kos/work/test_env/worktrees/${{ github.head_ref }}"
# 使用主工作树的共享虚拟环境
source .venv-shared/bin/activate source .venv-shared/bin/activate
# 检查分支的requirements.txt是否有更新 # 检查PR分支的requirements.txt是否有更新
if [ -f "requirements.txt" ]; then if [ -f "$WORKTREE_DIR/requirements.txt" ]; then
REQ_MOD_TIME=$(stat -c %Y requirements.txt 2>/dev/null || echo 0) echo "Checking for dependency updates in PR branch..."
REQ_MOD_TIME=$(stat -c %Y "$WORKTREE_DIR/requirements.txt" 2>/dev/null || echo 0)
VENV_MOD_TIME=$(cat .venv-shared/last_update.txt 2>/dev/null || echo 0) VENV_MOD_TIME=$(cat .venv-shared/last_update.txt 2>/dev/null || echo 0)
if [ $REQ_MOD_TIME -gt $VENV_MOD_TIME ]; then if [ $REQ_MOD_TIME -gt $VENV_MOD_TIME ]; then
echo "Master branch requirements updated, installing new dependencies..." echo "PR branch requirements updated, installing new dependencies..."
pip install -r requirements.txt --no-cache-dir pip install -r "$WORKTREE_DIR/requirements.txt"
echo $REQ_MOD_TIME > .venv-shared/last_update.txt echo $REQ_MOD_TIME > .venv-shared/last_update.txt
echo "Dependencies updated from PR branch"
else
echo "No changes in requirements, using existing packages"
fi fi
fi fi
# 第三步:从主工作树构建文档 echo "python3: $(python3 --version)"
- name: Build documentation from master echo "Sphinx: $(sphinx-build --version 2>/dev/null || echo 'Not installed')"
# 第四步: 在工作树中构建文档
- name: Build documentation in worktree
run: | run: |
echo "=== Building production documentation ===" echo "=== Building documentation in worktree ==="
cd /home/ly0kos/work/test_env cd /home/ly0kos/work/test_env
WORKTREE_DIR="/home/ly0kos/work/test_env/worktrees/${{ github.head_ref }}"
source .venv-shared/bin/activate source .venv-shared/bin/activate
rm -rf build/ # 构建文档
sphinx-build -b html source build -v -j 4 cd "$WORKTREE_DIR"
echo "✓ Production build completed" sphinx-build -b html source "$WORKTREE_DIR/build" -v -j 4
# 第四步:部署到Web服务器 # 复制到预览位置
- name: Deploy to web server mkdir -p /home/ly0kos/work/test_env/pr-builds/
rm -rf /home/ly0kos/work/test_env/pr-builds/${{ github.head_ref }}
cp -r "$WORKTREE_DIR/build" /home/ly0kos/work/test_env/pr-builds/${{ github.head_ref }}
echo "✓ Build completed for PR branch: ${{ github.head_ref }}"
# 第五步: 验证构建结果
- name: Verify build
run: | run: |
echo "=== Deploying to production ===" echo "Build output for PR ${{ github.head_ref }}:"
cd /home/ly0kos/work/test_env ls -la /home/ly0kos/work/test_env/pr-builds/${{ github.head_ref }}/ | head -10
rm -rf /var/www/docs_dev/* # 第六步: 复制至测试目录
cp -r build/* /var/www/docs_dev/ - name: Copy to dev folder
echo "✓ Documentation deployed"
# 第五步:清理PR工作树
- name: Cleanup PR worktree
run: | run: |
echo "=== Cleaning up PR worktree ===" echo "Now clear dev folder"
cd /home/ly0kos/work/test_env rm -rf /var/www/docs/*
echo "Copy build to dev folder"
WORKTREE_DIR="/home/ly0kos/work/test_env/worktrees/${{ github.head_ref }}" cp -r /home/ly0kos/work/test_env/pr-builds/${{ github.head_ref }}/* /var/www/docs/
if [ -d "$WORKTREE_DIR" ]; then echo "✓ Documentation in Product folder now!"
git worktree remove "$WORKTREE_DIR" --force echo "Please check http://mkb.local to See Changes"
echo "✓ Removed worktree for ${{ github.head_ref }}"
fi
# 清理预览文件
PREVIEW_DIR="/home/ly0kos/work/test_env/pr-builds/${{ github.head_ref }}"
if [ -d "$PREVIEW_DIR" ]; then
rm -rf "$PREVIEW_DIR"
echo "✓ Removed preview for ${{ github.head_ref }}"
fi
# 第六步:验证部署
- name: Verify deployment
run: |
echo "Production deployment completed!"
ls -la /var/www/docs_dev/ | head -10
+7 -6
View File
@@ -11,7 +11,7 @@ jobs:
runs-on: linux runs-on: linux
steps: steps:
# 第一步设置主工作树和虚拟环境 # 第一步: 设置主工作树和虚拟环境
- name: Setup main worktree and virtual environment - name: Setup main worktree and virtual environment
run: | run: |
echo "=== Setting up main worktree ===" echo "=== Setting up main worktree ==="
@@ -42,7 +42,7 @@ jobs:
echo "✓ Main worktree ready" echo "✓ Main worktree ready"
# 第二步为PR分支创建工作树 # 第二步: 为PR分支创建工作树
- name: Create worktree for PR branch - name: Create worktree for PR branch
run: | run: |
echo "=== Creating worktree for PR branch: ${{ github.head_ref }} ===" echo "=== Creating worktree for PR branch: ${{ github.head_ref }} ==="
@@ -63,7 +63,7 @@ jobs:
echo "✓ Worktree created at: /home/ly0kos/work/test_env/worktrees/${{ github.head_ref }}" echo "✓ Worktree created at: /home/ly0kos/work/test_env/worktrees/${{ github.head_ref }}"
# 第三步复用共享虚拟环境并检查依赖更新 # 第三步: 复用共享虚拟环境并检查依赖更新
- name: Reuse shared virtual environment - name: Reuse shared virtual environment
run: | run: |
echo "=== Reusing shared virtual environment ===" echo "=== Reusing shared virtual environment ==="
@@ -92,7 +92,7 @@ jobs:
echo "python3: $(python3 --version)" echo "python3: $(python3 --version)"
echo "Sphinx: $(sphinx-build --version 2>/dev/null || echo 'Not installed')" echo "Sphinx: $(sphinx-build --version 2>/dev/null || echo 'Not installed')"
# 第四步在工作树中构建文档 # 第四步: 在工作树中构建文档
- name: Build documentation in worktree - name: Build documentation in worktree
run: | run: |
echo "=== Building documentation in worktree ===" echo "=== Building documentation in worktree ==="
@@ -111,13 +111,13 @@ jobs:
echo "✓ Build completed for PR branch: ${{ github.head_ref }}" echo "✓ Build completed for PR branch: ${{ github.head_ref }}"
# 第五步验证构建结果 # 第五步: 验证构建结果
- name: Verify build - name: Verify build
run: | run: |
echo "Build output for PR ${{ github.head_ref }}:" echo "Build output for PR ${{ github.head_ref }}:"
ls -la /home/ly0kos/work/test_env/pr-builds/${{ github.head_ref }}/ | head -10 ls -la /home/ly0kos/work/test_env/pr-builds/${{ github.head_ref }}/ | head -10
# 第六步复制至测试目录 # 第六步: 复制至测试目录
- name: Copy to dev folder - name: Copy to dev folder
run: | run: |
echo "Now clear dev folder" echo "Now clear dev folder"
@@ -126,3 +126,4 @@ jobs:
cp -r /home/ly0kos/work/test_env/pr-builds/${{ github.head_ref }}/* /var/www/docs_dev/ cp -r /home/ly0kos/work/test_env/pr-builds/${{ github.head_ref }}/* /var/www/docs_dev/
echo "✓ Documentation in DEV folder now!" echo "✓ Documentation in DEV folder now!"
echo "Please check http://mkb.local:880 to Verify Changes" echo "Please check http://mkb.local:880 to Verify Changes"