From b938d3824e6449383728c5e6ee57b35db3d8c98d Mon Sep 17 00:00:00 2001 From: cydia2001 Date: Wed, 11 Mar 2026 01:10:46 +0000 Subject: [PATCH] ci: use official pages deployment workflow Switch the docs deployment workflow to the official GitHub Pages actions flow and verify it uses Pages action outputs for the deployment URL. --- .github/workflows/update_docs.yml | 48 +++++++++++++++++++++--------- tests/test_update_docs_workflow.py | 24 +++++++++++++++ 2 files changed, 58 insertions(+), 14 deletions(-) create mode 100644 tests/test_update_docs_workflow.py diff --git a/.github/workflows/update_docs.yml b/.github/workflows/update_docs.yml index 7f19a6b..0c3ff3c 100644 --- a/.github/workflows/update_docs.yml +++ b/.github/workflows/update_docs.yml @@ -5,12 +5,24 @@ on: branches: [main] workflow_dispatch: +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: github-pages + cancel-in-progress: true + jobs: - deploy: - runs-on: ubuntu-22.04 + build: + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 + + - id: pages + uses: actions/configure-pages@v5 - name: Set up Python 3.10 uses: actions/setup-python@v5 @@ -39,21 +51,29 @@ jobs: - name: Build Chinese HTML with mdBook run: bash build_mdbook_zh.sh - - name: Deploy to GitHub Pages + - name: Assemble GitHub Pages artifact env: - DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }} + DEPLOY_TARGET_URL: ${{ steps.pages.outputs.base_url }} run: | - git clone https://x-access-token:${DEPLOY_TOKEN}@github.com/openmlsys/openmlsys.github.io.git + echo "Deploy target: ${DEPLOY_TARGET_URL}" >> "$GITHUB_STEP_SUMMARY" python3 tools/assemble_docs_publish_tree.py \ - --destination-root openmlsys.github.io \ - --docs-subdir docs \ + --destination-root _site \ + --docs-subdir . \ --en-source .mdbook/book \ --zh-source .mdbook-zh/book - cd openmlsys.github.io - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - git add . - git commit -m "deploy: update docs (en+zh) from openmlsys-zh@${{ github.sha }}" || echo "No changes to commit" - git push + - name: Upload GitHub Pages artifact + uses: actions/upload-pages-artifact@v4 + with: + path: _site + + deploy: + needs: build + runs-on: ubuntu-latest + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - id: deployment + uses: actions/deploy-pages@v4 diff --git a/tests/test_update_docs_workflow.py b/tests/test_update_docs_workflow.py new file mode 100644 index 0000000..a13304d --- /dev/null +++ b/tests/test_update_docs_workflow.py @@ -0,0 +1,24 @@ +from __future__ import annotations + +import unittest +from pathlib import Path + + +REPO_ROOT = Path(__file__).resolve().parents[1] +WORKFLOW_PATH = REPO_ROOT / ".github" / "workflows" / "update_docs.yml" + + +class UpdateDocsWorkflowTests(unittest.TestCase): + def test_workflow_uses_official_pages_actions_and_page_variables(self) -> None: + workflow = WORKFLOW_PATH.read_text(encoding="utf-8") + + self.assertIn("uses: actions/configure-pages@v5", workflow) + self.assertIn("uses: actions/upload-pages-artifact@v4", workflow) + self.assertIn("uses: actions/deploy-pages@v4", workflow) + self.assertIn("url: ${{ steps.deployment.outputs.page_url }}", workflow) + self.assertIn("${{ steps.pages.outputs.base_url }}", workflow) + self.assertNotIn("git clone https://x-access-token:${DEPLOY_TOKEN}", workflow) + + +if __name__ == "__main__": + unittest.main()