Files
2026-07-13 12:24:33 +08:00

107 lines
3.4 KiB
YAML

name: Build and Deploy Online Documentation
on:
# Trigger the workflow on push request,
# for the dev branch
push:
branches:
- 'dev'
paths:
- 'docs/**'
- 'lmcache/**'
- 'examples/**'
- '.github/workflows/build_doc.yml'
jobs:
build-docs:
name: Build docs
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
with:
egress-policy: audit
- name: Checkout code
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
# Full git history needed for sphinx-multiversion to detect all tags/branches
fetch-depth: 0
# Fetch all branches and tags
fetch-tags: true
- name: Setup Python 3.13
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
with:
python-version: "3.13"
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements/docs.txt
- name: Build Versioned Sphinx Documentation
run: |
sphinx-multiversion docs/source output
SPHINX_LANGUAGE=zh_CN sphinx-multiversion docs/source output-zh
continue-on-error: false
- name: Setup root docs, .nojekyll, and Chinese docs
run: |
touch output/.nojekyll
# Copy dev docs to root (latest docs at root URL)
cp -r output/dev/* output/
# Remove dev directory to avoid duplication
rm -rf output/dev
# Copy Chinese dev docs to /zh_CN/ and versioned docs under /zh_CN/<version>/
mkdir -p output/zh_CN
cp -r output-zh/dev/* output/zh_CN/
rm -rf output-zh/dev
cp -r output-zh/. output/zh_CN/
rm -rf output-zh
- name: Upload doc artifacts to GHA
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: doc-artifacts
path: output/
deploy-docs:
name: Deploy docs online
runs-on: ubuntu-latest
needs: build-docs
steps:
- name: Harden Runner
uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
with:
egress-policy: audit
- name: Fetch doc artifacts
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
name: doc-artifacts
path: output
- name: Checkout code
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
repository: LM-Cache-Website/lm-cache-website.github.io
token: ${{ secrets.LMCACHE_DOC }}
path: target-repo
- name: Copy Files to Target Repository
run: |
cp -r output/* target-repo/
- name: Commit and Push to Target Repository
run: |
cd target-repo
git config user.name "github-actions[bot]"
git config user.email "github-actions@github.com"
git add .
if ! git diff --cached --quiet; then
git commit -m "Deploy updated online docs"
git push https://x-access-token:${{ secrets.LMCACHE_DOC }}@github.com/LM-Cache-Website/lm-cache-website.github.io.git main --force
else
echo "No changes to commit."
fi