Skip to content

Commit 9820dbf

Browse files
authored
chore: switch to separate docs deployment job (#52)
- uses actions/deploy-pages (for better provenance) - uses a separate conditional job to deploy docs (for a clean env with limited attack surface) - uses action/upload-pages-artifact (for preparing artifact in expected format) - an input option with a default value is not a required input
1 parent 724d561 commit 9820dbf

2 files changed

Lines changed: 49 additions & 24 deletions

File tree

.github/workflows/mkdocs.yml

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,39 @@ on:
44
workflow_call:
55

66
jobs:
7-
mkdocs-deploy:
7+
build:
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v5
10+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
11+
with:
12+
persist-credentials: false
1113
- uses: astral-sh/setup-uv@557e51de59eb14aaaba2ed9621916900a91d50c6 # v6.6.1
1214
- name: Install dependencies
1315
run: uv sync --group docs
1416
- name: Check mkdocs build
15-
if: github.ref != 'refs/heads/main'
1617
run: uv run mkdocs build
1718
- name: Upload docs build as artifact
18-
if: github.ref != 'refs/heads/main'
19-
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 #v4
19+
uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4.0.0
2020
with:
2121
name: ${{ github.event.repository.name }}_docs
2222
path: ${{ github.workspace }}/site
23-
- name: Build docs and deploy to gh-pages
24-
if: github.ref == 'refs/heads/main'
25-
run: |
26-
git config user.name 'github-actions'
27-
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
28-
uv run mkdocs gh-deploy --force
23+
24+
deploy:
25+
if: github.ref == 'refs/heads/main'
26+
runs-on: ubuntu-latest
27+
needs: [build]
28+
permissions:
29+
# to deploy to Pages
30+
pages: write
31+
# to verify the deployment originates from an appropriate source
32+
id-token: write
33+
# Deploy to the github-pages environment
34+
environment:
35+
name: github-pages
36+
url: ${{ steps.deployment.outputs.page_url }}
37+
steps:
38+
- name: Deploy to GitHub Pages
39+
id: deployment
40+
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5
41+
with:
42+
artifact_name: ${{ github.event.repository.name }}_docs

.github/workflows/sphinx.yml

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,45 @@ on:
44
workflow_call:
55
inputs:
66
path-to-doc:
7-
required: true
7+
required: false
88
type: string
99
default: docs/_build/html
1010
description: The docs path name
1111

1212
jobs:
13-
sphinx-deploy:
13+
build:
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v5
16+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
17+
with:
18+
persist-credentials: false
1719
- uses: astral-sh/setup-uv@557e51de59eb14aaaba2ed9621916900a91d50c6 # v6.6.1
18-
1920
- name: Install dependencies
2021
run: uv sync --group docs
21-
2222
- name: Build docs
2323
run: uv run sphinx-build docs ${{ inputs.path-to-doc }}
24-
2524
- name: Upload docs build as artifact
26-
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 #v4
25+
uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4.0.0
2726
with:
2827
name: ${{ github.event.repository.name }}_docs
2928
path: ${{ github.workspace }}/${{ inputs.path-to-doc }}
3029

31-
- name: Upload to github pages
32-
# only publish doc changes from main branch
33-
if: github.ref == 'refs/heads/main'
34-
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e #v4
30+
deploy:
31+
if: github.ref == 'refs/heads/main'
32+
runs-on: ubuntu-latest
33+
needs: [build]
34+
permissions:
35+
# to deploy to Pages
36+
pages: write
37+
# to verify the deployment originates from an appropriate source
38+
id-token: write
39+
# Deploy to the github-pages environment
40+
environment:
41+
name: github-pages
42+
url: ${{ steps.deployment.outputs.page_url }}
43+
steps:
44+
- name: Deploy to GitHub Pages
45+
id: deployment
46+
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5
3547
with:
36-
github_token: ${{ secrets.GITHUB_TOKEN }}
37-
publish_dir: ./${{ inputs.path-to-doc }}
48+
artifact_name: ${{ github.event.repository.name }}_docs

0 commit comments

Comments
 (0)