Skip to content

Commit c271903

Browse files
authored
Add doc preview CI (#380)
* add doc preview steps * add custom preview deploy/undeploy steps * specify shell * address PR reviews
1 parent 32fdd2d commit c271903

File tree

3 files changed

+116
-6
lines changed

3 files changed

+116
-6
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Preview or clean up docs built from PRs
2+
3+
# A re-implementation based on the logic of https://github.com/rossjrw/pr-preview-action/blob/41a957c44a456a34718e9bcf825363194db5e6d5/README.md, due to limitations illustrated in NVIDIA/cuda-python#380.
4+
5+
inputs:
6+
source-folder:
7+
required: true
8+
type: string
9+
10+
runs:
11+
using: composite
12+
steps:
13+
# The steps below are executed only when testing in a PR.
14+
# Note: the PR previews will be removed once merged to main (see below)
15+
- name: Get PR info
16+
if: ${{ github.ref_name != 'main' }}
17+
uses: nv-gha-runners/get-pr-info@main
18+
id: get-pr-info
19+
20+
- name: Extract PR number from info
21+
if: ${{ github.ref_name != 'main' }}
22+
shell: bash --noprofile --norc -xeuo pipefail {0}
23+
run: |
24+
PR_NUMBER="${{ fromJSON(steps.get-pr-info.outputs.pr-info).number }}"
25+
if [[ "$PR_NUMBER" == "" ]]; then
26+
echo "cannot extract PR number"
27+
exit 1
28+
else
29+
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
30+
fi
31+
32+
- name: Deploy doc preview
33+
if: ${{ github.ref_name != 'main' }}
34+
uses: JamesIves/github-pages-deploy-action@v4
35+
with:
36+
git-config-name: cuda-python-bot
37+
git-config-email: [email protected]
38+
folder: ${{ inputs.source-folder }}
39+
target-folder: docs/pr-preview/pr-${{ env.PR_NUMBER }}/
40+
commit-message: "Deploy doc preview for PR ${{ env.PR_NUMBER }} (${{ github.sha }})"
41+
42+
- name: Leave a comment after deployment
43+
if: ${{ github.ref_name != 'main' }}
44+
uses: marocchino/sticky-pull-request-comment@v2
45+
with:
46+
header: pr-preview
47+
number: ${{ env.PR_NUMBER }}
48+
skip_unchanged: true
49+
message: |
50+
Doc Preview CI
51+
:---:
52+
| <p></p> :rocket: View preview at <br> https://nvidia.github.io/cuda-python/pr-preview/pr-${{ env.PR_NUMBER }}/ <br><br>
53+
| <h6><br> Preview will be ready when the GitHub Pages deployment is complete. <br><br></h6>
54+
55+
# The steps below are executed only when building on main.
56+
- name: Get PR data
57+
if: ${{ github.ref_name == 'main' }}
58+
uses: actions/github-script@v7
59+
id: get-pr-data
60+
with:
61+
script: |
62+
return (
63+
await github.rest.repos.listPullRequestsAssociatedWithCommit({
64+
commit_sha: context.sha,
65+
owner: context.repo.owner,
66+
repo: context.repo.repo,
67+
})
68+
).data[0];
69+
70+
- name: Extract PR number from data
71+
if: ${{ github.ref_name == 'main' }}
72+
shell: bash --noprofile --norc -xeuo pipefail {0}
73+
run: |
74+
PR_NUMBER="${{ fromJSON(steps.get-pr-data.outputs.result).number }}"
75+
if [[ "$PR_NUMBER" == "" ]]; then
76+
echo "cannot extract PR number"
77+
exit 1
78+
else
79+
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
80+
fi
81+
82+
- name: Remove doc preview
83+
if: ${{ github.ref_name == 'main' }}
84+
uses: JamesIves/github-pages-deploy-action@v4
85+
with:
86+
git-config-name: cuda-python-bot
87+
git-config-email: [email protected]
88+
folder: ${{ inputs.source-folder }}
89+
target-folder: docs/pr-preview/pr-${{ env.PR_NUMBER }}/
90+
commit-message: "Clean up doc preview for PR ${{ env.PR_NUMBER }} (${{ github.sha }})"
91+
92+
- name: Leave a comment after removal
93+
if: ${{ github.ref_name == 'main' }}
94+
uses: marocchino/sticky-pull-request-comment@v2
95+
with:
96+
header: pr-preview
97+
number: ${{ env.PR_NUMBER }}
98+
hide_and_recreate: true
99+
hide_classify: "OUTDATED"
100+
message: |
101+
Doc Preview CI
102+
:---:
103+
Preview removed because the pull request was closed or merged.

.github/workflows/build-and-test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ jobs:
263263
permissions:
264264
id-token: write
265265
contents: write
266+
pull-requests: write
266267
needs:
267268
- build
268269
secrets: inherit

.github/workflows/build-docs.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ jobs:
5050
# WAR: Building the doc currently requires CTK installed (NVIDIA/cuda-python#326,327)
5151
- name: Set up mini CTK
5252
uses: ./.github/actions/fetch_ctk
53-
continue-on-error: false
5453
with:
5554
host-platform: linux-64
5655
cuda-version: ${{ inputs.build-ctk-ver }}
@@ -126,22 +125,29 @@ jobs:
126125
mkdir -p artifacts/docs
127126
mv cuda_python/docs/build/html/* artifacts/docs/
128127
129-
# Note: currently this is only for manual inspection. This step will become
130-
# required once we switch to use GHA for doc deployment (see the bottom).
128+
# create an empty folder for removal use
129+
mkdir -p artifacts/empty_docs
130+
131+
# TODO: Consider removing this step?
131132
- name: Upload doc artifacts
132133
uses: actions/upload-pages-artifact@v3
133134
with:
134135
path: artifacts/
135136
retention-days: 3
136137

137-
# The step below is not executed unless when building on main.
138+
- name: Deploy or clean up doc preview
139+
uses: ./.github/actions/doc_preview
140+
with:
141+
source-folder: ${{ (github.ref_name != 'main' && 'artifacts/docs') ||
142+
'artifacts/empty_docs' }}
143+
138144
- name: Deploy doc update
139-
if: ${{ github.ref_name == 'main' && success() }}
145+
if: ${{ github.ref_name == 'main' }}
140146
uses: JamesIves/github-pages-deploy-action@v4
141147
with:
142-
folder: artifacts/docs/
143148
git-config-name: cuda-python-bot
144149
git-config-email: [email protected]
150+
folder: artifacts/docs/
145151
target-folder: docs/
146152
commit-message: "Deploy latest docs: ${{ github.sha }}"
147153
clean: false

0 commit comments

Comments
 (0)