Skip to content

Commit 1801b8a

Browse files
committed
fix(ci/docs): Separate build and deploy jobs for documentation
Refactor the GitHub Pages documentation workflow to explicitly separate the build and deployment phases into distinct jobs. Previously, both build and deploy steps were part of a single `docs` job. This change introduces a dedicated `build` job to generate the MkDocs site and upload it as an artifact, and a `deploy` job to download this artifact and publish it to GitHub Pages. This separation improves: - **Clarity and maintainability:** Clearly delineates responsibilities for building versus deploying. - **Robustness:** Ensures that the deployment logic, including the `if` condition for the `main` branch, is applied at the job level, preventing unintended deployments or permission issues. - **Best practices:** Aligns with recommended GitHub Pages deployment patterns using `actions/configure-pages` and `actions/deploy-pages`. This enhances the reliability and structure of the documentation deployment process.
1 parent 375fca4 commit 1801b8a

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

template/.github/workflows/docs.yaml

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,19 @@ on:
1414
workflow_dispatch:
1515

1616
jobs:
17-
docs:
18-
name: Docs
19-
permissions:
20-
id-token: write
21-
pages: write
17+
build:
18+
name: Build
2219
runs-on: ubuntu-latest
23-
environment:
24-
name: github-pages
25-
url: ${{ steps.deploy.outputs.page_url }}
2620
steps:
2721
- name: Checkout
2822
uses: actions/checkout@v5
2923
with:
3024
fetch-depth: 0
31-
- name: Configure GitHub Pages
25+
- id: config
26+
name: Configure GitHub Pages
3227
uses: actions/configure-pages@v5
28+
- name: Set Environment Variables
29+
run: printf 'SITE_URL=%s\n' '${{ steps.config.outputs.base_url }}' >> "$GITHUB_ENV"
3330
- name: Setup Python
3431
uses: liblaf/actions/setup-python@v1
3532
- if: hashFiles('docs/scripts/pre-build.sh') != ''
@@ -41,7 +38,20 @@ jobs:
4138
uses: actions/upload-pages-artifact@v4
4239
with:
4340
path: site
41+
42+
deploy:
43+
name: Deploy
44+
permissions:
45+
id-token: write
46+
pages: write
47+
needs:
48+
- build
49+
if: github.ref == 'refs/heads/main'
50+
runs-on: ubuntu-latest
51+
environment:
52+
name: github-pages
53+
url: ${{ steps.deploy.outputs.page_url }}
54+
steps:
4455
- id: deploy
45-
if: ${{ github.ref == 'refs/heads/main' }}
4656
name: Deploy Github Pages Site
4757
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)