1- name : docs
1+ name : Docs
22
33on :
44 push :
55 branches :
66 - master
77 - main
8+ pull_request :
9+ branches :
10+ - ' **'
11+
812env :
913 SITE_DIR : " gh-pages"
14+
1015jobs :
1116 build_site :
1217 name : " Build site with Antora"
13- runs-on : [ubuntu-latest ]
18+ runs-on : [ubuntu-24.04 ]
1419 steps :
1520 - name : Checkout
16- uses : actions/checkout@v2
21+ uses : actions/checkout@v4
1722 - name : " Generate site using antora site action"
1823 uses : kameshsampath/antora-site-action@master
1924 with :
@@ -23,23 +28,86 @@ jobs:
2328 with :
2429 name : site
2530 path : " ${{ github.workspace }}/${{ env.SITE_DIR }}"
31+
2632 deploy_site :
27- runs-on : [ubuntu-latest]
33+ permissions :
34+ contents : write
35+ pull-requests : write
36+ repository-projects : write
37+ id-token : write
38+ runs-on : [ubuntu-24.04]
2839 needs : [build_site]
2940 name : " Deploy GitHub Pages"
41+ if : github.event_name != 'pull_request'
3042 steps :
3143 - name : Checkout
32- uses : actions/checkout@v2
44+ uses : actions/checkout@v4
3345 - name : Download generated site
3446 uses : actions/download-artifact@v4
3547 with :
3648 name : site
3749 path : " ${{ github.workspace }}/${{ env.SITE_DIR }}"
3850 - name : Deploy to GitHub Pages
39- 51+ uses : JamesIves/github-pages-deploy-action@v4
52+ with :
53+ token : ${{ secrets.GITHUB_TOKEN }}
54+ folder : " ${{ env.SITE_DIR }}"
55+ commit-message : " [CI] Publish Documentation for ${{ github.sha }}"
56+
57+ # Based on : https://daiyi.co/blog/pr-previews-for-github-pages/
58+ deploy_preview :
59+ permissions :
60+ contents : write
61+ pull-requests : write
62+ repository-projects : write
63+ id-token : write
64+ env :
65+ PR_PATH : pull-${{ github.event.number }}
66+ runs-on : [ ubuntu-24.04 ]
67+ needs : [ build_site ]
68+ name : " Deploy preview for PR"
69+ if : github.event_name == 'pull_request'
70+ steps :
71+ - name : Comment on PR
72+ 73+ with :
74+ github-token : ${{ secrets.GITHUB_TOKEN }}
75+ repository : ${{ github.repository }}
76+ number : ${{ github.event.number }}
77+ id : deploy-preview
78+ message : " Starting deployment of preview for ${{ github.event.pull_request.head.sha }} ⏳..."
79+
80+ - name : Set base URL for preview
81+ run : echo "BASE_URL=https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ env.PR_PATH }}" >> "$GITHUB_ENV"
82+
83+ - name : Checkout
84+ uses : actions/checkout@v4
85+ - name : Download generated site
86+ uses : actions/download-artifact@v4
87+ with :
88+ name : site
89+ path : " ${{ github.workspace }}/${{ env.SITE_DIR }}"
90+
91+ - name : Deploy PR preview
92+ uses : JamesIves/github-pages-deploy-action@v4
93+ with :
94+ token : ${{ secrets.GITHUB_TOKEN }}
95+ folder : " ${{ env.SITE_DIR }}"
96+ target-folder : " ${{ env.PR_PATH }}"
97+ commit-message : " [CI] Publish Preview for PR #${{ github.event.number }}"
98+
99+ - name : Update comment
100+ 40101 with :
41- # ACCESS_TOKEN: # optional
42- GITHUB_TOKEN : " ${{ github.token}}"
43- FOLDER : " ${{ env.SITE_DIR }}"
44- BRANCH : " gh-pages"
45- COMMIT_MESSAGE : " [CI] Publish Documentation for ${{ github.sha }}"
102+ github-token : ${{ secrets.GITHUB_TOKEN }}
103+ repository : ${{ github.repository }}
104+ number : ${{ github.event.number }}
105+ id : deploy-preview
106+ message : |
107+ A preview of ${{ github.event.pull_request.head.sha }} is uploaded and can be seen here:
108+
109+ ✨ ${{ env.BASE_URL }} ✨
110+
111+ Changes may take a few minutes to propagate.
112+
113+ The source is here: https://github.com/${{ github.repository }}/tree/gh-pages/${{ env.PR_PATH }}
0 commit comments