Skip to content

Commit 19f4dea

Browse files
committed
ci: deploy docs via official GitHub Pages actions
Replace the hand-rolled 'git init + force push to gh-pages' approach with the officially supported actions/configure-pages, actions/upload-pages-artifact and actions/deploy-pages. This relies on OIDC for authentication (no GITHUB_TOKEN write scope on contents needed) and removes the force-pushed branch. Also: - Enable uv cache (enable-cache: true) for a faster build job. - Add a 'pages' concurrency group with cancel-in-progress: false so Pages deployments are serialised but never interrupted. - Add timeout-minutes safety nets to each job. - Drop the now-unused GITHUB_PAGES_BRANCH env var. NOTE: This requires the repository's Pages source to be set to 'GitHub Actions' (Settings -> Pages -> Build and deployment -> Source).
1 parent a10e4d6 commit 19f4dea

1 file changed

Lines changed: 31 additions & 17 deletions

File tree

.github/workflows/publish-docs.yaml

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,49 @@ on:
44
workflow_dispatch:
55
workflow_call:
66

7-
env:
8-
GITHUB_PAGES_BRANCH: gh-pages
7+
# Pages deployments must not run in parallel. Do not cancel an in-flight
8+
# deployment, otherwise we risk leaving the site in a broken state.
9+
concurrency:
10+
group: pages
11+
cancel-in-progress: false
912

1013
jobs:
11-
publish-docs:
14+
build:
15+
name: "Build docs site"
1216
runs-on: ubuntu-latest
13-
17+
timeout-minutes: 10
1418
steps:
1519
- name: Checkout repository
1620
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
1721

1822
- name: Install uv
1923
uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0
24+
with:
25+
enable-cache: true
2026

2127
- name: Install dependencies and build website
28+
working-directory: ./docs
2229
run: |
23-
cd docs
2430
uv sync --locked
2531
uv run zensical build
2632
27-
- name: Push static files to Github Pages branch
28-
run: |
29-
cd docs/site
30-
CREATED_FROM_REF=$(git rev-parse --short HEAD)
31-
git init
32-
git config user.name "GitHub Actions Bot"
33-
git config user.email "<>"
34-
git checkout -b $GITHUB_PAGES_BRANCH
35-
git remote add $GITHUB_PAGES_BRANCH https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/equinor/template-fastapi-react
36-
git add .
37-
git commit -m "Built from commit '$CREATED_FROM_REF'"
38-
git push -f --set-upstream gh-pages gh-pages
33+
- name: Configure Pages
34+
uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0
35+
36+
- name: Upload Pages artifact
37+
uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
38+
with:
39+
path: ./docs/site
40+
41+
deploy:
42+
name: "Deploy to GitHub Pages"
43+
needs: build
44+
runs-on: ubuntu-latest
45+
timeout-minutes: 5
46+
environment:
47+
name: github-pages
48+
url: ${{ steps.deployment.outputs.page_url }}
49+
steps:
50+
- name: Deploy to GitHub Pages
51+
id: deployment
52+
uses: actions/deploy-pages@cd2ce8fcbc39b97be8ca5fce6e763baed58fa128 # v5.0.0

0 commit comments

Comments
 (0)