Skip to content

Commit 67693bb

Browse files
Hugo docs: Support reviews of Hugo updates by publishing to a clone's gh-pages
Signed-off-by: Bernhard Kaindl <bernhard.kaindl@cloud.com>
1 parent 748359d commit 67693bb

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

.github/workflows/hugo.yml

+63-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@ name: Generate and upload Hugo docs
33
on:
44
push:
55
branches: master
6+
pull_request:
7+
# Only run the workflow on changes to the following paths
8+
paths:
9+
- 'doc/**'
10+
- '.github/workflows/hugo.yml'
611

712
jobs:
8-
ocaml:
13+
hugo:
914
name: Docs
1015
runs-on: ubuntu-22.04
16+
environment:
17+
# To be able read var.PREVIEW_HUGO_DOCS, if set in the github-pages environment:
18+
name: github-pages
19+
outputs:
20+
preview: ${{ steps.preview.outputs.done }} # Set to true if the preview job runs
1121

1222
steps:
1323
- name: Checkout code
@@ -25,6 +35,9 @@ jobs:
2535
2636
- name: Deploy
2737
uses: peaceiris/actions-gh-pages@v4
38+
# The deploy key used for deployment to https://xenapi-project.github.io
39+
# It is stored in the repository's secrets and is used to push the built
40+
# documentation. This step skips deployment if it is not set on a clone.
2841
with:
2942
deploy_key: ${{ secrets.ACTIONS_DOCS_DEPLOY_KEY }}
3043
publish_dir: ./doc/public
@@ -35,3 +48,52 @@ jobs:
3548
destination_dir: new-docs # temporary staging branch
3649
allow_empty_commit: false
3750
enable_jekyll: true # do not create .nojekyll file
51+
52+
# Deploy to the github-pages environment for doc reviews in other repositories
53+
# if vars.PREVIEW_HUGO_DOCS set by the admin in the repository's environment
54+
# This is done without commiting to the repository's gh-pages branch, only
55+
# an artifact is deployed to the clone's github-pages environment instead:
56+
57+
- name: If vars.PREVIEW_HUGO_DOCS is true, enable github pages for the preview
58+
if: ${{ vars.PREVIEW_HUGO_DOCS == 'true' }} # Only runs if set by the admin
59+
id: configure-pages
60+
with:
61+
enablement: true # Enables GitHub Pages for the clone repository
62+
uses: actions/configure-pages@v5 # output: the base_url for the preview site
63+
64+
- name: If vars.PREVIEW_HUGO_DOCS is true, build the hugo preview
65+
if: ${{ vars.PREVIEW_HUGO_DOCS == 'true' }}
66+
id: preview
67+
env:
68+
# Override the Hugo baseUrl in doc/hugo.toml with the repo name for doc reviews:
69+
HUGO_BASEURL: ${{ steps.configure-pages.outputs.base_url }}
70+
run: cd doc && hugo --minify && echo done=true >$GITHUB_OUTPUT
71+
72+
- name: If vars.PREVIEW_HUGO_DOCS is true, upload the Hugo site as an artifact
73+
if: ${{ vars.PREVIEW_HUGO_DOCS == 'true' }}
74+
uses: actions/upload-pages-artifact@v3
75+
with:
76+
path: ./doc/public
77+
78+
79+
# When pushed to other repositories, deploy to the repository's GitHub Pages
80+
preview-docs:
81+
# Add a dependency to the hugo job, skip if the hugo job did not complete
82+
needs: hugo
83+
84+
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
85+
permissions:
86+
id-token: write # Required for the deployment job to access the uploaded artifact
87+
pages: write # Required for the deployment job to deploy to GitHub Pages
88+
89+
environment:
90+
name: github-pages
91+
url: ${{ steps.deployment.outputs.page_url }}
92+
93+
# Specify runner + deployment step
94+
runs-on: ubuntu-24.04-arm
95+
steps:
96+
- name: Deploy uploaded artifact to GitHub Pages for documentation update reviews
97+
if: ${{ needs.hugo.outputs.preview == 'true' }}
98+
id: deployment
99+
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)