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.
This commit is contained in:
cydia2001
2026-03-11 01:10:46 +00:00
parent 9d75cdc6c3
commit b938d3824e
2 changed files with 58 additions and 14 deletions

View File

@@ -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

View File

@@ -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()