From d87300a3377c5c355086985cda9e5c2cf96ca84e Mon Sep 17 00:00:00 2001 From: YuYang Shen Date: Mon, 25 Aug 2025 12:05:59 +0800 Subject: [PATCH 01/10] For Testing --- .gitea/workflows/sphinx.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitea/workflows/sphinx.yml b/.gitea/workflows/sphinx.yml index a8851e4..77cdcc0 100644 --- a/.gitea/workflows/sphinx.yml +++ b/.gitea/workflows/sphinx.yml @@ -1,3 +1,4 @@ +#For test name: Build and Deploy Sphinx Docs on: From aa20b14dcd407f13d130998324d84fdbe3b4221f Mon Sep 17 00:00:00 2001 From: YuYang Shen Date: Mon, 25 Aug 2025 12:07:39 +0800 Subject: [PATCH 02/10] Change Actions --- .gitea/workflows/sphinx_deploy.yml | 42 +++++++++++++++++ .../workflows/{sphinx.yml => sphinx_test.yml} | 45 +------------------ 2 files changed, 43 insertions(+), 44 deletions(-) create mode 100644 .gitea/workflows/sphinx_deploy.yml rename .gitea/workflows/{sphinx.yml => sphinx_test.yml} (70%) diff --git a/.gitea/workflows/sphinx_deploy.yml b/.gitea/workflows/sphinx_deploy.yml new file mode 100644 index 0000000..63731fd --- /dev/null +++ b/.gitea/workflows/sphinx_deploy.yml @@ -0,0 +1,42 @@ +name: Deploy on Merge + +on: + pull_request: + types: [closed] + branches: [main] + +jobs: + deploy: + # 关键:只在PR被成功merge时运行 + if: github.event.pull_request.merged == true + runs-on: linux + steps: + # 第一步:部署到Web服务器 + - name: Deploy to web server + run: | + echo "=== Deploying to web server ===" + echo "[INFO] Removing Old file..." + rm -rf /var/www/docs_dev/* + echo "[INFO] Copying new file..." + cp -r /home/ly0kos/work/test_env/build/* /var/www/docs_dev/ + echo "✓ Documentation deployed to /var/www/docs_dev/" + + # 验证部署 + echo "Web server contents:" + ls -la /var/www/docs_dev/ | head -10 + + # 第二步:清理临时工作树 + - name: Cleanup temporary worktree + run: | + echo "=== Cleaning up ===" + cd /home/ly0kos/work/test_env + + # 移除工作树 + if [ -d /home/ly0kos/work/test_env/build ]; then + git worktree remove /home/ly0kos/work/test_env/build --force + echo "✓ Temporary worktree removed" + else + echo "Build worktree already removed" + fi + + echo "=== Process completed successfully ===" \ No newline at end of file diff --git a/.gitea/workflows/sphinx.yml b/.gitea/workflows/sphinx_test.yml similarity index 70% rename from .gitea/workflows/sphinx.yml rename to .gitea/workflows/sphinx_test.yml index 77cdcc0..821593b 100644 --- a/.gitea/workflows/sphinx.yml +++ b/.gitea/workflows/sphinx_test.yml @@ -80,47 +80,4 @@ jobs: # 验证构建结果 echo "Build output contents:" - ls -la /home/ly0kos/work/test_env/build/ - -name: Deploy on Merge - -on: - pull_request: - types: [closed] - branches: [main] - -jobs: - deploy: - # 关键:只在PR被成功merge时运行 - if: github.event.pull_request.merged == true - runs-on: linux - steps: - # 第一步:部署到Web服务器 - - name: Deploy to web server - run: | - echo "=== Deploying to web server ===" - echo "[INFO] Removing Old file..." - rm -rf /var/www/docs_dev/* - echo "[INFO] Copying new file..." - cp -r /home/ly0kos/work/test_env/build/* /var/www/docs_dev/ - echo "✓ Documentation deployed to /var/www/docs_dev/" - - # 验证部署 - echo "Web server contents:" - ls -la /var/www/docs_dev/ | head -10 - - # 第二步:清理临时工作树 - - name: Cleanup temporary worktree - run: | - echo "=== Cleaning up ===" - cd /home/ly0kos/work/test_env - - # 移除工作树 - if [ -d /home/ly0kos/work/test_env/build ]; then - git worktree remove /home/ly0kos/work/test_env/build --force - echo "✓ Temporary worktree removed" - else - echo "Build worktree already removed" - fi - - echo "=== Process completed successfully ===" \ No newline at end of file + ls -la /home/ly0kos/work/test_env/build/ \ No newline at end of file From 9b79ae0f31d4e3522122d0d162f2a59a144d1583 Mon Sep 17 00:00:00 2001 From: YuYang Shen Date: Mon, 25 Aug 2025 12:10:23 +0800 Subject: [PATCH 03/10] Fix action --- .gitea/workflows/sphinx_test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitea/workflows/sphinx_test.yml b/.gitea/workflows/sphinx_test.yml index 821593b..3182a2a 100644 --- a/.gitea/workflows/sphinx_test.yml +++ b/.gitea/workflows/sphinx_test.yml @@ -9,7 +9,6 @@ on: jobs: build-docs: name: Build Documentation - if: github.event.pull_request.merged == true runs-on: linux steps: From 62ee929b6e207c805607cc9657c3c7472176fc69 Mon Sep 17 00:00:00 2001 From: YuYang Shen Date: Mon, 25 Aug 2025 12:15:10 +0800 Subject: [PATCH 04/10] Fix requirements --- requirements.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/requirements.txt b/requirements.txt index 708abe6..cc7bf0e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -126,6 +126,8 @@ sphinxcontrib-jsmath==1.0.1 # via sphinx sphinxcontrib-qthelp==2.0.0 # via sphinx +sphinxcontrib-mermaid + # via sphinx sphinxcontrib-serializinghtml==2.0.0 # via sphinx sphinxcontrib-video==0.4.1 From 63e0da579fd6da070a77bc7548310b84c769751f Mon Sep 17 00:00:00 2001 From: YuYang Shen Date: Mon, 25 Aug 2025 12:17:32 +0800 Subject: [PATCH 05/10] Fix Action(main->master) --- .gitea/workflows/sphinx_test.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.gitea/workflows/sphinx_test.yml b/.gitea/workflows/sphinx_test.yml index 3182a2a..21aa204 100644 --- a/.gitea/workflows/sphinx_test.yml +++ b/.gitea/workflows/sphinx_test.yml @@ -13,13 +13,13 @@ jobs: steps: # 第一步:设置主工作目录和稳定的虚拟环境 - - name: Set up main worktree with stable environment + - name: Set up master worktree with stable environment run: | - echo "=== Setting up main worktree ===" + echo "=== Setting up master worktree ===" # 创建主工作目录并克隆仓库 if [ ! -d /home/ly0kos/work/test_env ]; then - echo "Cloning repository to main worktree..." + 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..." @@ -28,15 +28,15 @@ jobs: echo "Installing dependencies..." pip install --upgrade pip pip install -r requirements.txt - echo "✓ Main worktree and virtual environment created" + echo "✓ master worktree and virtual environment created" else - echo "Updating existing main worktree..." + echo "Updating existing master worktree..." cd /home/ly0kos/work/test_env - git pull origin main + git pull origin master source .venv/bin/activate echo "Updating dependencies if needed..." pip install -r requirements.txt - echo "✓ Main worktree updated" + echo "✓ master worktree updated" fi # 验证环境 From cb57bbd9a38196de6dc9f3c390d959ef30d39f67 Mon Sep 17 00:00:00 2001 From: YuYang Shen Date: Mon, 25 Aug 2025 12:20:53 +0800 Subject: [PATCH 06/10] Fix requirements.txt --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index cc7bf0e..1596ca3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -126,7 +126,7 @@ sphinxcontrib-jsmath==1.0.1 # via sphinx sphinxcontrib-qthelp==2.0.0 # via sphinx -sphinxcontrib-mermaid +sphinxcontrib-mermaid>=1.0.0 # via sphinx sphinxcontrib-serializinghtml==2.0.0 # via sphinx From 783dbf8b4a909f21ca91138b1b929fdee7a2f924 Mon Sep 17 00:00:00 2001 From: YuYang Shen Date: Mon, 25 Aug 2025 12:25:13 +0800 Subject: [PATCH 07/10] Add mermaid in requirments --- requirements.in | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.in b/requirements.in index bb3639e..61336f6 100644 --- a/requirements.in +++ b/requirements.in @@ -8,3 +8,4 @@ sphinxcontrib.images sphinxcontrib.video sphinxcontrib.htmlhelp sphinxcontrib.wavedrom +sphinxcontrib.mermaid \ No newline at end of file From d9e0b2f6bd73111c96bcbf01004ae95757fec928 Mon Sep 17 00:00:00 2001 From: YuYang Shen Date: Mon, 25 Aug 2025 12:45:32 +0800 Subject: [PATCH 08/10] Fix requirements.txt --- requirements.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 1596ca3..539cb83 100644 --- a/requirements.txt +++ b/requirements.txt @@ -76,6 +76,7 @@ pygments==2.19.2 pyyaml==6.0.2 # via # myst-parser + # sphinxcontrib-mermaid # wavedrom requests==2.32.5 # via @@ -100,6 +101,7 @@ sphinx==8.2.3 # sphinx-rtd-theme # sphinxcontrib-images # sphinxcontrib-jquery + # sphinxcontrib-mermaid # sphinxcontrib-video # sphinxcontrib-wavedrom sphinx-book-theme==1.1.4 @@ -124,10 +126,10 @@ sphinxcontrib-jquery==4.1 # via sphinx-rtd-theme sphinxcontrib-jsmath==1.0.1 # via sphinx +sphinxcontrib-mermaid==1.0.0 + # via -r requirements.in sphinxcontrib-qthelp==2.0.0 # via sphinx -sphinxcontrib-mermaid>=1.0.0 - # via sphinx sphinxcontrib-serializinghtml==2.0.0 # via sphinx sphinxcontrib-video==0.4.1 From 6f7975959f8e02e99dd58f7d52df39a8ca5bfc3b Mon Sep 17 00:00:00 2001 From: YuYang Shen Date: Mon, 25 Aug 2025 12:56:59 +0800 Subject: [PATCH 09/10] New action test --- .gitea/workflows/sphinx_test.yml | 99 ++++++++++++-------------------- 1 file changed, 36 insertions(+), 63 deletions(-) diff --git a/.gitea/workflows/sphinx_test.yml b/.gitea/workflows/sphinx_test.yml index 21aa204..32d7625 100644 --- a/.gitea/workflows/sphinx_test.yml +++ b/.gitea/workflows/sphinx_test.yml @@ -1,82 +1,55 @@ -#For test -name: Build and Deploy Sphinx Docs +name: Build Sphinx Documentation on: pull_request: - types: [opened, synchronize, reopened] - branches: [master] + 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 + # 第一步:检出PR分支代码 + - name: Checkout PR branch + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} # 检出PR分支而不是主分支 + fetch-depth: 0 + + # 第二步:设置Python虚拟环境 + - name: Set up Python virtual environment run: | - echo "=== Setting up master worktree ===" - - # 创建主工作目录并克隆仓库 - 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 + 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 }}/ + + echo "✓ Build completed for PR branch: ${{ github.head_ref }}" - # 第三步:使用主目录的虚拟环境构建文档 - - name: Build documentation + # 第四步:验证构建结果 + - 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/ \ No newline at end of file + echo "Build output for PR ${{ github.head_ref }}:" + ls -la /home/ly0kos/work/test_env/pr-builds/${{ github.head_ref }}/ | head -10 \ No newline at end of file From 8debfcd8b38d5e03b3f5856c45d7a79b1f98af35 Mon Sep 17 00:00:00 2001 From: YuYang Shen Date: Mon, 25 Aug 2025 13:02:09 +0800 Subject: [PATCH 10/10] Action revision --- .gitea/workflows/sphinx_deploy.yml | 146 +++++++++++++++++++++++------ .gitea/workflows/sphinx_test.yml | 115 ++++++++++++++++++----- 2 files changed, 205 insertions(+), 56 deletions(-) diff --git a/.gitea/workflows/sphinx_deploy.yml b/.gitea/workflows/sphinx_deploy.yml index 63731fd..c18c70c 100644 --- a/.gitea/workflows/sphinx_deploy.yml +++ b/.gitea/workflows/sphinx_deploy.yml @@ -1,42 +1,128 @@ -name: Deploy on Merge +name: Deploy Sphinx Documentation on: pull_request: types: [closed] - branches: [main] + branches: [master] jobs: deploy: - # 关键:只在PR被成功merge时运行 - if: github.event.pull_request.merged == true + # 只在PR被成功merge到master时运行 + if: github.event.pull_request.merged == true && github.base_ref == 'master' runs-on: linux - steps: - # 第一步:部署到Web服务器 - - name: Deploy to web server + + steps: + # 第一步:获取master分支最新代码 + - name: Fetch latest master branch code run: | - echo "=== Deploying to web server ===" - echo "[INFO] Removing Old file..." - rm -rf /var/www/docs_dev/* - echo "[INFO] Copying new file..." - cp -r /home/ly0kos/work/test_env/build/* /var/www/docs_dev/ - echo "✓ Documentation deployed to /var/www/docs_dev/" + echo "=== Fetching latest master branch code ===" - # 验证部署 - echo "Web server contents:" - ls -la /var/www/docs_dev/ | head -10 - - # 第二步:清理临时工作树 - - name: Cleanup temporary worktree - run: | - echo "=== Cleaning up ===" - cd /home/ly0kos/work/test_env - - # 移除工作树 - if [ -d /home/ly0kos/work/test_env/build ]; then - git worktree remove /home/ly0kos/work/test_env/build --force - echo "✓ Temporary worktree removed" - else - echo "Build worktree already removed" + # 确保目录存在 + if [ ! -d "/home/ly0kos/work/test_env" ]; then + echo "Cloning repository..." + git clone http://localhost:3000/yuysh/Manlink_Doc.git /home/ly0kos/work/test_env fi - echo "=== Process completed successfully ===" \ No newline at end of file + cd /home/ly0kos/work/test_env + + # 清理任何未提交的更改 + git reset --hard + git clean -fd + + # 获取所有远程更新 + git fetch --all --prune + + # 切换到master分支并获取最新代码 + git checkout master + git pull origin master --force + + echo "✓ Latest master code fetched" + echo "Current commit: $(git log --oneline -1)" + + # 第二步:复用生产虚拟环境 + - name: Reuse or update production Python environment + run: | + echo "Setting up production Python environment" + cd /home/ly0kos/work/test_env + + # 检查虚拟环境是否存在 + if [ ! -d ".venv-prod" ]; then + echo "Creating new production virtual environment..." + python -m venv .venv-prod + source .venv-prod/bin/activate + pip install --upgrade pip + # 安装基础依赖 + pip install sphinx sphinx-rtd-theme + else + echo "Reusing existing production virtual environment..." + source .venv-prod/bin/activate + fi + + # 检查并更新依赖 + if [ -f "requirements.txt" ]; then + echo "Checking for dependency updates in production..." + REQ_MOD_TIME=$(stat -c %Y requirements.txt 2>/dev/null || echo 0) + VENV_MOD_TIME=$(cat .venv-prod/last_update.txt 2>/dev/null || echo 0) + + if [ $REQ_MOD_TIME -gt $VENV_MOD_TIME ]; then + echo "Production requirements updated, installing new dependencies..." + pip install -r requirements.txt + echo $REQ_MOD_TIME > .venv-prod/last_update.txt + else + echo "No changes in production requirements, skipping installation" + fi + fi + + # 显示环境信息 + echo "Production environment ready:" + pip list | grep sphinx + + # 第三步:从master分支构建文档 + - name: Build documentation from master + run: | + echo "=== Building production documentation from master ===" + cd /home/ly0kos/work/test_env + source .venv-prod/bin/activate + + # 清理旧构建 + rm -rf build/ + + # 构建文档 + sphinx-build -b html source build -v -j 4 + echo "✓ Production build completed" + + # 第四步:部署到Web服务器 + - name: Deploy to web server + run: | + echo "=== Deploying to production web server ===" + cd /home/ly0kos/work/test_env + + echo "[INFO] Removing old files..." + sudo rm -rf /var/www/docs_dev/* + echo "[INFO] Copying new files..." + sudo cp -r build/* /var/www/docs_dev/ + + # 设置正确的文件权限 + sudo chown -R www-data:www-data /var/www/docs_dev/ + sudo chmod -R 755 /var/www/docs_dev/ + + echo "✓ Documentation deployed to /var/www/docs_dev/" + + # 第五步:清理PR预览文件 + - name: Cleanup PR previews + run: | + echo "Cleaning up PR preview files for branch: ${{ github.head_ref }}" + + # 清理预览文件(保留虚拟环境) + 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 PR branch: ${{ github.head_ref }}" + fi + + # 第六步:验证部署 + - name: Verify deployment + run: | + echo "Production deployment completed successfully!" + echo "Web server contents:" + ls -la /var/www/docs_dev/ | head -10 \ No newline at end of file diff --git a/.gitea/workflows/sphinx_test.yml b/.gitea/workflows/sphinx_test.yml index 32d7625..b4b9447 100644 --- a/.gitea/workflows/sphinx_test.yml +++ b/.gitea/workflows/sphinx_test.yml @@ -11,40 +11,102 @@ jobs: runs-on: linux steps: - # 第一步:检出PR分支代码 - - name: Checkout PR branch - uses: actions/checkout@v4 - with: - ref: ${{ github.head_ref }} # 检出PR分支而不是主分支 - fetch-depth: 0 - - # 第二步:设置Python虚拟环境 - - name: Set up Python virtual environment + # 第一步:获取PR分支最新代码 + - name: Fetch latest PR branch code 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 - else - echo "No requirements.txt found, installing sphinx" - pip install sphinx + echo "=== Fetching latest code for PR branch: ${{ github.head_ref }} ===" + + # 如果目录不存在,克隆仓库 + if [ ! -d "/home/ly0kos/work/test_env" ]; then + echo "Cloning repository..." + git clone http://localhost:3000/yuysh/Manlink_Doc.git /home/ly0kos/work/test_env fi + + # 进入目录并获取最新代码 + cd /home/ly0kos/work/test_env + + # 清理任何未提交的更改 + git reset --hard + git clean -fd + + # 获取所有远程分支和更新 + git fetch --all --prune + + # 切换到PR分支并获取最新代码 + git checkout ${{ github.head_ref }} + git pull origin ${{ github.head_ref }} --force + + echo "✓ Latest code fetched for branch: ${{ github.head_ref }}" + echo "Current commit: $(git log --oneline -1)" - # 第三步:构建文档(从PR分支) + # 第二步:复用或创建Python虚拟环境 + - name: Reuse or update Python virtual environment + run: | + echo "Setting up Python environment for PR branch: ${{ github.head_ref }}" + cd /home/ly0kos/work/test_env + + # 检查虚拟环境是否存在 + if [ ! -d ".venv-pr" ]; then + echo "Creating new virtual environment..." + python -m venv .venv-pr + source .venv-pr/bin/activate + pip install --upgrade pip + # 安装基础依赖 + pip install sphinx sphinx-rtd-theme + else + echo "Reusing existing virtual environment..." + source .venv-pr/bin/activate + fi + + # 检查requirements.txt是否更新 + if [ -f "requirements.txt" ]; then + echo "Checking for dependency updates..." + # 获取requirements.txt的修改时间 + REQ_MOD_TIME=$(stat -c %Y requirements.txt 2>/dev/null || echo 0) + # 获取虚拟环境中记录的最后更新时间 + VENV_MOD_TIME=$(cat .venv-pr/last_update.txt 2>/dev/null || echo 0) + + if [ $REQ_MOD_TIME -gt $VENV_MOD_TIME ]; then + echo "Requirements updated, installing new dependencies..." + pip install -r requirements.txt + # 记录更新时间 + echo $REQ_MOD_TIME > .venv-pr/last_update.txt + else + echo "No changes in requirements, skipping dependency installation" + fi + else + echo "No requirements.txt found, using existing packages" + fi + + # 显示当前环境信息 + echo "Python: $(python --version)" + echo "Pip: $(pip --version)" + echo "Installed packages:" + pip list | grep sphinx + + # 第三步:构建文档(从PR分支) - name: Build documentation from PR branch run: | echo "=== Building documentation from PR branch: ${{ github.head_ref }} ===" - source /home/ly0kos/work/test_env/.venv-pr-${{ github.head_ref }}/bin/activate + cd /home/ly0kos/work/test_env + source .venv-pr/bin/activate - # 在PR分支目录中构建 - sphinx-build -b html ./docs ./build -v -j 4 + # 确保源目录存在 + if [ ! -d "source" ]; then + echo "Error: source directory not found!" + exit 1 + fi - # 将构建结果移动到共享位置,便于查看 + # 清理旧构建 + rm -rf build/ + + # 构建文档 + sphinx-build -b html source build -v -j 4 + + # 将构建结果复制到预览位置 + mkdir -p /home/ly0kos/work/test_env/pr-builds/ 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 }}/ + cp -r build /home/ly0kos/work/test_env/pr-builds/${{ github.head_ref }} echo "✓ Build completed for PR branch: ${{ github.head_ref }}" @@ -52,4 +114,5 @@ jobs: - name: Verify build run: | echo "Build output for PR ${{ github.head_ref }}:" - ls -la /home/ly0kos/work/test_env/pr-builds/${{ github.head_ref }}/ | head -10 \ No newline at end of file + ls -la /home/ly0kos/work/test_env/pr-builds/${{ github.head_ref }}/ | head -10 + echo "Preview available at: /home/ly0kos/work/test_env/pr-builds/${{ github.head_ref }}/index.html" \ No newline at end of file