Skip to content

Commit a35c2f3

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 1170ab0 commit a35c2f3

File tree

1 file changed

+56
-3
lines changed

1 file changed

+56
-3
lines changed

.github/workflows/hugo.yml

+56-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
name: Generate and upload Hugo docs
22

33
on:
4+
# Only run the workflow on changes to the following paths
45
push:
56
branches: master
7+
pull_request:
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+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.ref }}
18+
env:
19+
DEP: ${{ vars.PREVIEW_HUGO_DOCS }}
1120

1221
steps:
1322
- name: Checkout code
@@ -18,13 +27,19 @@ jobs:
1827
with:
1928
hugo-version: '0.127.0'
2029

21-
- name: Build
30+
- name: Build with defaults from doc/hugo.yml for the xapi-project/xen-api master
31+
if: |
32+
github.repository == 'xapi-project/xen-api' &&
33+
github.ref == 'refs/heads/master'
2234
run: |
2335
cd doc
2436
hugo --minify
2537
26-
- name: Deploy
38+
- name: Deploy xapi-project/xen-api master to https://xapi-project.github.io/new-docs
2739
uses: peaceiris/actions-gh-pages@v4
40+
if: |
41+
github.repository == 'xapi-project/xen-api' &&
42+
github.ref == 'refs/heads/master'
2843
with:
2944
deploy_key: ${{ secrets.ACTIONS_DOCS_DEPLOY_KEY }}
3045
publish_dir: ./doc/public
@@ -35,3 +50,41 @@ jobs:
3550
destination_dir: new-docs # temporary staging branch
3651
allow_empty_commit: false
3752
enable_jekyll: true # do not create .nojekyll file
53+
54+
- name: Build to deploy to a clone's GitHub Pages for documentation update reviews
55+
if: ${{ vars.PREVIEW_HUGO_DOCS == 'true' || env.DEP == 'true' }}
56+
env:
57+
# Override the Hugo baseUrl in doc/hugo.toml with the repo name for doc reviews:
58+
HUGO_BASEURL: ${{ steps.deployment.outputs.page_url }}
59+
run: cd doc;hugo --minify
60+
61+
62+
# When pushed to other repositories, deploy to the repository's GitHub Pages
63+
preview-docs:
64+
# Add a dependency to the hugo job, skip if the hugo job did not complete
65+
needs: hugo
66+
67+
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
68+
permissions:
69+
id-token: write # Required for the deployment job to access the uploaded artifact
70+
pages: write # Required for the deployment job to deploy to GitHub Pages
71+
72+
# Deploy to the github-pages environment for doc reviews
73+
# This variable is used in the preview-docs job to determine whether to preview the Hugo docs
74+
# You can set this variable in the repository's environment or secrets settings:
75+
if: vars.PREVIEW_HUGO_DOCS
76+
environment:
77+
name: github-pages
78+
url: ${{ steps.deployment.outputs.page_url }}
79+
80+
# Specify runner + deployment step
81+
runs-on: ubuntu-latest
82+
steps:
83+
- name: Upload Hugo static site as an artifact for documentation update reviews
84+
uses: actions/upload-pages-artifact@v3
85+
with:
86+
path: ./doc/public
87+
88+
- name: Deploy uploaded artifact to GitHub Pages for documentation update reviews
89+
id: deployment
90+
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)