Skip to content

Commit c9a8a12

Browse files
🎁 Adding PR previews (#2)
* Adding PR previews * Adding required permissions to remove the preview * Update .github/workflows/pr-close.yml Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Remove unnecessary directory creation step --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent cab66db commit c9a8a12

File tree

2 files changed

+111
-11
lines changed

2 files changed

+111
-11
lines changed

.github/workflows/docs.yml

Lines changed: 79 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
name: docs
1+
name: Docs
22

33
on:
44
push:
55
branches:
66
- master
77
- main
8+
pull_request:
9+
branches:
10+
- '**'
11+
812
env:
913
SITE_DIR: "gh-pages"
14+
1015
jobs:
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-
uses: JamesIves/[email protected]
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+
uses: hasura/[email protected]
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+
uses: hasura/[email protected]
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 }}

.github/workflows/pr-close.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: PR Close
2+
on:
3+
pull_request:
4+
types: [closed]
5+
6+
jobs:
7+
delete_preview:
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
name: Delete preview for PR
12+
runs-on: [ ubuntu-24.04 ]
13+
env:
14+
SITE_DIR: "gh-pages"
15+
PR_PATH: pull-${{ github.event.number }}
16+
steps:
17+
- name: Removing PR preview
18+
uses: JamesIves/github-pages-deploy-action@v4
19+
with:
20+
token: ${{ secrets.GITHUB_TOKEN }}
21+
folder: "${{ env.SITE_DIR }}"
22+
target-folder: "${{ env.PR_PATH }}"
23+
commit-message: "[CI] Delete Preview for PR #${{ github.event.number }}"
24+
25+
- name: Comment on PR
26+
uses: hasura/[email protected]
27+
with:
28+
github-token: ${{ secrets.GITHUB_TOKEN }}
29+
repository: ${{ github.repository }}
30+
number: ${{ github.event.number }}
31+
id: deploy-preview
32+
message: "🪓 PR closed, deleted preview at https://github.com/${{ github.repository }}/tree/gh-pages/${{ env.PR_PATH }}"

0 commit comments

Comments
 (0)