-
Notifications
You must be signed in to change notification settings - Fork 171
CI: add a warning banner to the preview docs #410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cd20e7a
add a warning banner
leofang 4f42d2c
[pre-commit.ci] auto code formatting
pre-commit-ci[bot] 945ef54
add hyperlink back to the PR
leofang bbf7ff1
refactor to create the get_pr_number action
leofang d11c727
take pr-number as input
leofang eefa549
ensure PR_NUMBER is visible during doc build
leofang 963261f
propagate the banner to cuda-core
leofang 4e63abe
propagate the banner to cuda-bindings
leofang 1946ef7
[pre-commit.ci] auto code formatting
pre-commit-ci[bot] e163f15
try to apply suggestions
leofang 197e317
Merge branch 'main' into banner
leofang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,97 +6,57 @@ inputs: | |
source-folder: | ||
required: true | ||
type: string | ||
pr-number: | ||
required: true | ||
type: string | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
# The steps below are executed only when testing in a PR. | ||
# Note: the PR previews will be removed once merged to main (see below) | ||
- name: Get PR info | ||
if: ${{ github.ref_name != 'main' }} | ||
uses: nv-gha-runners/get-pr-info@main | ||
id: get-pr-info | ||
|
||
- name: Extract PR number from info | ||
if: ${{ github.ref_name != 'main' }} | ||
shell: bash --noprofile --norc -xeuo pipefail {0} | ||
run: | | ||
PR_NUMBER="${{ fromJSON(steps.get-pr-info.outputs.pr-info).number }}" | ||
if [[ "$PR_NUMBER" == "" ]]; then | ||
echo "cannot extract PR number" | ||
exit 1 | ||
else | ||
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV | ||
fi | ||
|
||
# Note: the PR previews will be removed once merged to main (see below) | ||
- name: Deploy doc preview | ||
if: ${{ github.ref_name != 'main' }} | ||
uses: JamesIves/github-pages-deploy-action@v4 | ||
with: | ||
git-config-name: cuda-python-bot | ||
git-config-email: [email protected] | ||
folder: ${{ inputs.source-folder }} | ||
target-folder: docs/pr-preview/pr-${{ env.PR_NUMBER }}/ | ||
commit-message: "Deploy doc preview for PR ${{ env.PR_NUMBER }} (${{ github.sha }})" | ||
target-folder: docs/pr-preview/pr-${{ inputs.pr-number }}/ | ||
commit-message: "Deploy doc preview for PR ${{ inputs.pr-number }} (${{ github.sha }})" | ||
|
||
- name: Leave a comment after deployment | ||
if: ${{ github.ref_name != 'main' }} | ||
uses: marocchino/sticky-pull-request-comment@v2 | ||
with: | ||
header: pr-preview | ||
number: ${{ env.PR_NUMBER }} | ||
number: ${{ inputs.pr-number }} | ||
skip_unchanged: true | ||
message: | | ||
Doc Preview CI | ||
:---: | ||
| <p></p> :rocket: View preview at <br> https://nvidia.github.io/cuda-python/pr-preview/pr-${{ env.PR_NUMBER }}/ <br> | ||
| <br> https://nvidia.github.io/cuda-python/pr-preview/pr-${{ env.PR_NUMBER }}/cuda-core/ <br> | ||
| <br> https://nvidia.github.io/cuda-python/pr-preview/pr-${{ env.PR_NUMBER }}/cuda-bindings/ <br><br> | ||
| <p></p> :rocket: View preview at <br> https://nvidia.github.io/cuda-python/pr-preview/pr-${{ inputs.pr-number }}/ <br> | ||
| <br> https://nvidia.github.io/cuda-python/pr-preview/pr-${{ inputs.pr-number }}/cuda-core/ <br> | ||
| <br> https://nvidia.github.io/cuda-python/pr-preview/pr-${{ inputs.pr-number }}/cuda-bindings/ <br><br> | ||
| <h6><br> Preview will be ready when the GitHub Pages deployment is complete. <br><br></h6> | ||
|
||
# The steps below are executed only when building on main. | ||
- name: Get PR data | ||
if: ${{ github.ref_name == 'main' }} | ||
uses: actions/github-script@v7 | ||
id: get-pr-data | ||
with: | ||
script: | | ||
return ( | ||
await github.rest.repos.listPullRequestsAssociatedWithCommit({ | ||
commit_sha: context.sha, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
}) | ||
).data[0]; | ||
|
||
- name: Extract PR number from data | ||
if: ${{ github.ref_name == 'main' }} | ||
shell: bash --noprofile --norc -xeuo pipefail {0} | ||
run: | | ||
PR_NUMBER="${{ fromJSON(steps.get-pr-data.outputs.result).number }}" | ||
if [[ "$PR_NUMBER" == "" ]]; then | ||
echo "cannot extract PR number" | ||
exit 1 | ||
else | ||
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV | ||
fi | ||
|
||
# The steps below are executed only when building on main. | ||
- name: Remove doc preview | ||
if: ${{ github.ref_name == 'main' }} | ||
uses: JamesIves/github-pages-deploy-action@v4 | ||
with: | ||
git-config-name: cuda-python-bot | ||
git-config-email: [email protected] | ||
folder: ${{ inputs.source-folder }} | ||
target-folder: docs/pr-preview/pr-${{ env.PR_NUMBER }}/ | ||
commit-message: "Clean up doc preview for PR ${{ env.PR_NUMBER }} (${{ github.sha }})" | ||
target-folder: docs/pr-preview/pr-${{ inputs.pr-number }}/ | ||
commit-message: "Clean up doc preview for PR ${{ inputs.pr-number }} (${{ github.sha }})" | ||
|
||
- name: Leave a comment after removal | ||
if: ${{ github.ref_name == 'main' }} | ||
uses: marocchino/sticky-pull-request-comment@v2 | ||
with: | ||
header: pr-preview | ||
number: ${{ env.PR_NUMBER }} | ||
number: ${{ inputs.pr-number }} | ||
hide_and_recreate: true | ||
hide_classify: "OUTDATED" | ||
message: | | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: Get the PR number | ||
|
||
description: Get the PR number without relying on the pull_request* event triggers. | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Get PR info (non-main branch) | ||
if: ${{ github.ref_name != 'main' }} | ||
uses: nv-gha-runners/get-pr-info@main | ||
id: get-pr-info | ||
|
||
- name: Extract PR number (non-main branch) | ||
if: ${{ github.ref_name != 'main' }} | ||
shell: bash --noprofile --norc -xeuo pipefail {0} | ||
run: | | ||
trap 'echo "Error at line $LINENO"; exit 1' ERR | ||
PR_NUMBER="${{ fromJSON(steps.get-pr-info.outputs.pr-info).number }}" | ||
if [[ -z "$PR_NUMBER" ]]; then | ||
echo "Cannot extract PR number for ref: ${{ github.ref_name }}" | ||
exit 1 | ||
fi | ||
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV | ||
|
||
- name: Get PR data (main branch) | ||
if: ${{ github.ref_name == 'main' }} | ||
uses: actions/github-script@v7 | ||
id: get-pr-data | ||
with: | ||
script: | | ||
const prs = await github.rest.repos.listPullRequestsAssociatedWithCommit({ | ||
commit_sha: context.sha, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
}); | ||
if (!prs.data.length) { | ||
core.setFailed("No PR associated with this commit on 'main'."); | ||
} else { | ||
return prs.data[0]; | ||
} | ||
|
||
- name: Extract PR number (main branch) | ||
if: ${{ github.ref_name == 'main' }} | ||
shell: bash --noprofile --norc -xeuo pipefail {0} | ||
run: | | ||
trap 'echo "Error at line $LINENO"; exit 1' ERR | ||
PR_NUMBER="${{ fromJSON(steps.get-pr-data.outputs.result).number }}" | ||
if [[ -z "$PR_NUMBER" ]]; then | ||
echo "No associated PR found for the commit in 'main'." | ||
exit 1 | ||
fi | ||
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.