mirror of
https://github.com/openmlsys/openmlsys-zh.git
synced 2026-04-01 09:50:23 +08:00
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:
48
.github/workflows/update_docs.yml
vendored
48
.github/workflows/update_docs.yml
vendored
@@ -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
|
||||
|
||||
24
tests/test_update_docs_workflow.py
Normal file
24
tests/test_update_docs_workflow.py
Normal 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()
|
||||
Reference in New Issue
Block a user