Skip to content

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 11 commits into from
Jan 19, 2025
Merged
68 changes: 14 additions & 54 deletions .github/actions/doc_preview/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
52 changes: 52 additions & 0 deletions .github/actions/get_pr_number/action.yml
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
5 changes: 5 additions & 0 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ jobs:

pip install cuda_python*.whl

# This step sets the PR_NUMBER env var.
- name: Get PR number
uses: ./.github/actions/get_pr_number

- name: Build all (latest) docs
id: build
run: |
Expand All @@ -140,6 +144,7 @@ jobs:
with:
source-folder: ${{ (github.ref_name != 'main' && 'artifacts/docs') ||
'artifacts/empty_docs' }}
pr-number: ${{ env.PR_NUMBER }}

- name: Deploy doc update
if: ${{ github.ref_name == 'main' }}
Expand Down
4 changes: 4 additions & 0 deletions cuda_bindings/docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
# "navbar-icon-links",
# ],
}
if os.environ.get("CI"):
PR_NUMBER = f"{os.environ['PR_NUMBER']}"
PR_TEXT = f'<a href="https://github.com/NVIDIA/cuda-python/pull/{PR_NUMBER}">PR {PR_NUMBER}</a>'
html_theme_options["announcement"] = f"<em>Warning</em>: This documentation is only a preview for {PR_TEXT}!"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
Expand Down
4 changes: 4 additions & 0 deletions cuda_core/docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@
# "navbar-icon-links",
# ],
}
if os.environ.get("CI"):
PR_NUMBER = f"{os.environ['PR_NUMBER']}"
PR_TEXT = f'<a href="https://github.com/NVIDIA/cuda-python/pull/{PR_NUMBER}">PR {PR_NUMBER}</a>'
html_theme_options["announcement"] = f"<em>Warning</em>: This documentation is only a preview for {PR_TEXT}!"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
Expand Down
6 changes: 6 additions & 0 deletions cuda_python/docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@
# "navbar-icon-links",
# ],
}
if os.environ.get("CI"):
PR_NUMBER = f"{os.environ['PR_NUMBER']}"
PR_TEXT = f'<a href="https://github.com/NVIDIA/cuda-python/pull/{PR_NUMBER}">PR {PR_NUMBER}</a>'
html_theme_options["announcement"] = (
f"<em>Warning</em>: This documentation is only a preview for {PR_TEXT}!"
)

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