Skip to content

Commit d4a68b8

Browse files
authored
CI: add a warning banner to the preview docs (#410)
1 parent d62c7fa commit d4a68b8

File tree

6 files changed

+85
-54
lines changed

6 files changed

+85
-54
lines changed

.github/actions/doc_preview/action.yml

Lines changed: 14 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,97 +6,57 @@ inputs:
66
source-folder:
77
required: true
88
type: string
9+
pr-number:
10+
required: true
11+
type: string
912

1013
runs:
1114
using: composite
1215
steps:
1316
# 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-
17+
# Note: the PR previews will be removed once merged to main (see below)
3218
- name: Deploy doc preview
3319
if: ${{ github.ref_name != 'main' }}
3420
uses: JamesIves/github-pages-deploy-action@v4
3521
with:
3622
git-config-name: cuda-python-bot
3723
git-config-email: [email protected]
3824
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 }})"
25+
target-folder: docs/pr-preview/pr-${{ inputs.pr-number }}/
26+
commit-message: "Deploy doc preview for PR ${{ inputs.pr-number }} (${{ github.sha }})"
4127

4228
- name: Leave a comment after deployment
4329
if: ${{ github.ref_name != 'main' }}
4430
uses: marocchino/sticky-pull-request-comment@v2
4531
with:
4632
header: pr-preview
47-
number: ${{ env.PR_NUMBER }}
33+
number: ${{ inputs.pr-number }}
4834
skip_unchanged: true
4935
message: |
5036
Doc Preview CI
5137
:---:
52-
| <p></p> :rocket: View preview at <br> https://nvidia.github.io/cuda-python/pr-preview/pr-${{ env.PR_NUMBER }}/ <br>
53-
| <br> https://nvidia.github.io/cuda-python/pr-preview/pr-${{ env.PR_NUMBER }}/cuda-core/ <br>
54-
| <br> https://nvidia.github.io/cuda-python/pr-preview/pr-${{ env.PR_NUMBER }}/cuda-bindings/ <br><br>
38+
| <p></p> :rocket: View preview at <br> https://nvidia.github.io/cuda-python/pr-preview/pr-${{ inputs.pr-number }}/ <br>
39+
| <br> https://nvidia.github.io/cuda-python/pr-preview/pr-${{ inputs.pr-number }}/cuda-core/ <br>
40+
| <br> https://nvidia.github.io/cuda-python/pr-preview/pr-${{ inputs.pr-number }}/cuda-bindings/ <br><br>
5541
| <h6><br> Preview will be ready when the GitHub Pages deployment is complete. <br><br></h6>
5642
57-
# The steps below are executed only when building on main.
58-
- name: Get PR data
59-
if: ${{ github.ref_name == 'main' }}
60-
uses: actions/github-script@v7
61-
id: get-pr-data
62-
with:
63-
script: |
64-
return (
65-
await github.rest.repos.listPullRequestsAssociatedWithCommit({
66-
commit_sha: context.sha,
67-
owner: context.repo.owner,
68-
repo: context.repo.repo,
69-
})
70-
).data[0];
71-
72-
- name: Extract PR number from data
73-
if: ${{ github.ref_name == 'main' }}
74-
shell: bash --noprofile --norc -xeuo pipefail {0}
75-
run: |
76-
PR_NUMBER="${{ fromJSON(steps.get-pr-data.outputs.result).number }}"
77-
if [[ "$PR_NUMBER" == "" ]]; then
78-
echo "cannot extract PR number"
79-
exit 1
80-
else
81-
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
82-
fi
83-
43+
# The steps below are executed only when building on main.
8444
- name: Remove doc preview
8545
if: ${{ github.ref_name == 'main' }}
8646
uses: JamesIves/github-pages-deploy-action@v4
8747
with:
8848
git-config-name: cuda-python-bot
8949
git-config-email: [email protected]
9050
folder: ${{ inputs.source-folder }}
91-
target-folder: docs/pr-preview/pr-${{ env.PR_NUMBER }}/
92-
commit-message: "Clean up doc preview for PR ${{ env.PR_NUMBER }} (${{ github.sha }})"
51+
target-folder: docs/pr-preview/pr-${{ inputs.pr-number }}/
52+
commit-message: "Clean up doc preview for PR ${{ inputs.pr-number }} (${{ github.sha }})"
9353

9454
- name: Leave a comment after removal
9555
if: ${{ github.ref_name == 'main' }}
9656
uses: marocchino/sticky-pull-request-comment@v2
9757
with:
9858
header: pr-preview
99-
number: ${{ env.PR_NUMBER }}
59+
number: ${{ inputs.pr-number }}
10060
hide_and_recreate: true
10161
hide_classify: "OUTDATED"
10262
message: |
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Get the PR number
2+
3+
description: Get the PR number without relying on the pull_request* event triggers.
4+
5+
runs:
6+
using: composite
7+
steps:
8+
- name: Get PR info (non-main branch)
9+
if: ${{ github.ref_name != 'main' }}
10+
uses: nv-gha-runners/get-pr-info@main
11+
id: get-pr-info
12+
13+
- name: Extract PR number (non-main branch)
14+
if: ${{ github.ref_name != 'main' }}
15+
shell: bash --noprofile --norc -xeuo pipefail {0}
16+
run: |
17+
trap 'echo "Error at line $LINENO"; exit 1' ERR
18+
PR_NUMBER="${{ fromJSON(steps.get-pr-info.outputs.pr-info).number }}"
19+
if [[ -z "$PR_NUMBER" ]]; then
20+
echo "Cannot extract PR number for ref: ${{ github.ref_name }}"
21+
exit 1
22+
fi
23+
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
24+
25+
- name: Get PR data (main branch)
26+
if: ${{ github.ref_name == 'main' }}
27+
uses: actions/github-script@v7
28+
id: get-pr-data
29+
with:
30+
script: |
31+
const prs = await github.rest.repos.listPullRequestsAssociatedWithCommit({
32+
commit_sha: context.sha,
33+
owner: context.repo.owner,
34+
repo: context.repo.repo,
35+
});
36+
if (!prs.data.length) {
37+
core.setFailed("No PR associated with this commit on 'main'.");
38+
} else {
39+
return prs.data[0];
40+
}
41+
42+
- name: Extract PR number (main branch)
43+
if: ${{ github.ref_name == 'main' }}
44+
shell: bash --noprofile --norc -xeuo pipefail {0}
45+
run: |
46+
trap 'echo "Error at line $LINENO"; exit 1' ERR
47+
PR_NUMBER="${{ fromJSON(steps.get-pr-data.outputs.result).number }}"
48+
if [[ -z "$PR_NUMBER" ]]; then
49+
echo "No associated PR found for the commit in 'main'."
50+
exit 1
51+
fi
52+
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV

.github/workflows/build-docs.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ jobs:
114114
115115
pip install cuda_python*.whl
116116
117+
# This step sets the PR_NUMBER env var.
118+
- name: Get PR number
119+
uses: ./.github/actions/get_pr_number
120+
117121
- name: Build all (latest) docs
118122
id: build
119123
run: |
@@ -140,6 +144,7 @@ jobs:
140144
with:
141145
source-folder: ${{ (github.ref_name != 'main' && 'artifacts/docs') ||
142146
'artifacts/empty_docs' }}
147+
pr-number: ${{ env.PR_NUMBER }}
143148

144149
- name: Deploy doc update
145150
if: ${{ github.ref_name == 'main' }}

cuda_bindings/docs/source/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@
7070
# "navbar-icon-links",
7171
# ],
7272
}
73+
if os.environ.get("CI"):
74+
PR_NUMBER = f"{os.environ['PR_NUMBER']}"
75+
PR_TEXT = f'<a href="https://github.com/NVIDIA/cuda-python/pull/{PR_NUMBER}">PR {PR_NUMBER}</a>'
76+
html_theme_options["announcement"] = f"<em>Warning</em>: This documentation is only a preview for {PR_TEXT}!"
7377

7478
# Add any paths that contain custom static files (such as style sheets) here,
7579
# relative to this directory. They are copied after the builtin static files,

cuda_core/docs/source/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
# "navbar-icon-links",
7676
# ],
7777
}
78+
if os.environ.get("CI"):
79+
PR_NUMBER = f"{os.environ['PR_NUMBER']}"
80+
PR_TEXT = f'<a href="https://github.com/NVIDIA/cuda-python/pull/{PR_NUMBER}">PR {PR_NUMBER}</a>'
81+
html_theme_options["announcement"] = f"<em>Warning</em>: This documentation is only a preview for {PR_TEXT}!"
7882

7983
# Add any paths that contain custom static files (such as style sheets) here,
8084
# relative to this directory. They are copied after the builtin static files,

cuda_python/docs/source/conf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@
7171
# "navbar-icon-links",
7272
# ],
7373
}
74+
if os.environ.get("CI"):
75+
PR_NUMBER = f"{os.environ['PR_NUMBER']}"
76+
PR_TEXT = f'<a href="https://github.com/NVIDIA/cuda-python/pull/{PR_NUMBER}">PR {PR_NUMBER}</a>'
77+
html_theme_options["announcement"] = (
78+
f"<em>Warning</em>: This documentation is only a preview for {PR_TEXT}!"
79+
)
7480

7581
# Add any paths that contain custom static files (such as style sheets) here,
7682
# relative to this directory. They are copied after the builtin static files,

0 commit comments

Comments
 (0)