From cd20e7a44bc3a8aecdf80961b3469d9d8cfeb1cf Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Sat, 18 Jan 2025 21:15:40 -0500 Subject: [PATCH 01/10] add a warning banner --- cuda_python/docs/source/conf.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cuda_python/docs/source/conf.py b/cuda_python/docs/source/conf.py index ab00c22036..553fb2166b 100644 --- a/cuda_python/docs/source/conf.py +++ b/cuda_python/docs/source/conf.py @@ -71,6 +71,8 @@ # "navbar-icon-links", # ], } +if os.environ.get("CI"): + html_theme_options["announcement"] = "Warning: This documentation is only a preview for the pull request!" # 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, From 4f42d2c521490d5cd2e8e9c48db4c059e83db0e8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 19 Jan 2025 02:19:27 +0000 Subject: [PATCH 02/10] [pre-commit.ci] auto code formatting --- cuda_python/docs/source/conf.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cuda_python/docs/source/conf.py b/cuda_python/docs/source/conf.py index 553fb2166b..c554e2c5cd 100644 --- a/cuda_python/docs/source/conf.py +++ b/cuda_python/docs/source/conf.py @@ -72,7 +72,9 @@ # ], } if os.environ.get("CI"): - html_theme_options["announcement"] = "Warning: This documentation is only a preview for the pull request!" + html_theme_options["announcement"] = ( + "Warning: This documentation is only a preview for the pull request!" + ) # 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, From 945ef5452e1a500bb7a25aba53241c1e293a6a9f Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Sat, 18 Jan 2025 22:05:15 -0500 Subject: [PATCH 03/10] add hyperlink back to the PR --- cuda_python/docs/source/conf.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cuda_python/docs/source/conf.py b/cuda_python/docs/source/conf.py index c554e2c5cd..49928d8665 100644 --- a/cuda_python/docs/source/conf.py +++ b/cuda_python/docs/source/conf.py @@ -72,8 +72,10 @@ # ], } if os.environ.get("CI"): + PR_NUMBER = f"{os.environ['PR_NUMBER']}" + PR_TEXT = f'PR {PR_NUMBER}' html_theme_options["announcement"] = ( - "Warning: This documentation is only a preview for the pull request!" + f"Warning: This documentation is only a preview for {PR_TEXT}!" ) # Add any paths that contain custom static files (such as style sheets) here, From bbf7ff14933ad28ff5312eb458e522a8acfecb36 Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Sat, 18 Jan 2025 22:31:54 -0500 Subject: [PATCH 04/10] refactor to create the get_pr_number action --- .github/actions/get_pr_number/action.yml | 51 ++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .github/actions/get_pr_number/action.yml diff --git a/.github/actions/get_pr_number/action.yml b/.github/actions/get_pr_number/action.yml new file mode 100644 index 0000000000..4aecb9f4f7 --- /dev/null +++ b/.github/actions/get_pr_number/action.yml @@ -0,0 +1,51 @@ +name: Get the PR number + +description: Get the PR number without relying on the pull_request* event triggers. + +runs: + using: composite + steps: + # The steps below are executed only when testing in a PR. + - 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 + + # 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 From d11c727117e0564f87c85aecb7f659f4ee2e4b97 Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Sat, 18 Jan 2025 22:34:33 -0500 Subject: [PATCH 05/10] take pr-number as input --- .github/actions/doc_preview/action.yml | 68 ++++++-------------------- 1 file changed, 14 insertions(+), 54 deletions(-) diff --git a/.github/actions/doc_preview/action.yml b/.github/actions/doc_preview/action.yml index 12816d12f3..fda47e746e 100644 --- a/.github/actions/doc_preview/action.yml +++ b/.github/actions/doc_preview/action.yml @@ -6,29 +6,15 @@ 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 @@ -36,51 +22,25 @@ runs: git-config-name: cuda-python-bot git-config-email: cuda-python-bot@users.noreply.github.com 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 :---: - |

:rocket: View preview at
https://nvidia.github.io/cuda-python/pr-preview/pr-${{ env.PR_NUMBER }}/
- |
https://nvidia.github.io/cuda-python/pr-preview/pr-${{ env.PR_NUMBER }}/cuda-core/
- |
https://nvidia.github.io/cuda-python/pr-preview/pr-${{ env.PR_NUMBER }}/cuda-bindings/

+ |

:rocket: View preview at
https://nvidia.github.io/cuda-python/pr-preview/pr-${{ inputs.pr-number }}/
+ |
https://nvidia.github.io/cuda-python/pr-preview/pr-${{ inputs.pr-number }}/cuda-core/
+ |
https://nvidia.github.io/cuda-python/pr-preview/pr-${{ inputs.pr-number }}/cuda-bindings/

|

Preview will be ready when the GitHub Pages deployment is complete.

- # 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 @@ -88,15 +48,15 @@ runs: git-config-name: cuda-python-bot git-config-email: cuda-python-bot@users.noreply.github.com 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: | From eefa549d82ddbc1c9cccbf578cf4c8b3196c634e Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Sat, 18 Jan 2025 22:37:04 -0500 Subject: [PATCH 06/10] ensure PR_NUMBER is visible during doc build --- .github/workflows/build-docs.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/build-docs.yml b/.github/workflows/build-docs.yml index d7b4ad6cd7..e2e45868a1 100644 --- a/.github/workflows/build-docs.yml +++ b/.github/workflows/build-docs.yml @@ -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: | @@ -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' }} From 963261f68751e02175d660bb7ceb981c872424e0 Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Sat, 18 Jan 2025 23:00:01 -0500 Subject: [PATCH 07/10] propagate the banner to cuda-core --- cuda_core/docs/source/conf.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cuda_core/docs/source/conf.py b/cuda_core/docs/source/conf.py index ca59d588b9..f23a179769 100644 --- a/cuda_core/docs/source/conf.py +++ b/cuda_core/docs/source/conf.py @@ -75,6 +75,12 @@ # "navbar-icon-links", # ], } +if os.environ.get("CI"): + PR_NUMBER = f"{os.environ['PR_NUMBER']}" + PR_TEXT = f'PR {PR_NUMBER}' + html_theme_options["announcement"] = ( + f"Warning: 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, From 4e63abed717a2857d996c4ed3c198eb68d8b301e Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Sat, 18 Jan 2025 23:00:56 -0500 Subject: [PATCH 08/10] propagate the banner to cuda-bindings --- cuda_bindings/docs/source/conf.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cuda_bindings/docs/source/conf.py b/cuda_bindings/docs/source/conf.py index 01f0fb4927..47b6a43e41 100644 --- a/cuda_bindings/docs/source/conf.py +++ b/cuda_bindings/docs/source/conf.py @@ -70,6 +70,12 @@ # "navbar-icon-links", # ], } +if os.environ.get("CI"): + PR_NUMBER = f"{os.environ['PR_NUMBER']}" + PR_TEXT = f'PR {PR_NUMBER}' + html_theme_options["announcement"] = ( + f"Warning: 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, From 1946ef782dfe5c3e5f707938e9c972d9374857b1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 19 Jan 2025 04:01:53 +0000 Subject: [PATCH 09/10] [pre-commit.ci] auto code formatting --- cuda_bindings/docs/source/conf.py | 4 +--- cuda_core/docs/source/conf.py | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/cuda_bindings/docs/source/conf.py b/cuda_bindings/docs/source/conf.py index 47b6a43e41..f8a4712b38 100644 --- a/cuda_bindings/docs/source/conf.py +++ b/cuda_bindings/docs/source/conf.py @@ -73,9 +73,7 @@ if os.environ.get("CI"): PR_NUMBER = f"{os.environ['PR_NUMBER']}" PR_TEXT = f'PR {PR_NUMBER}' - html_theme_options["announcement"] = ( - f"Warning: This documentation is only a preview for {PR_TEXT}!" - ) + html_theme_options["announcement"] = f"Warning: 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, diff --git a/cuda_core/docs/source/conf.py b/cuda_core/docs/source/conf.py index f23a179769..b122a63113 100644 --- a/cuda_core/docs/source/conf.py +++ b/cuda_core/docs/source/conf.py @@ -78,9 +78,7 @@ if os.environ.get("CI"): PR_NUMBER = f"{os.environ['PR_NUMBER']}" PR_TEXT = f'PR {PR_NUMBER}' - html_theme_options["announcement"] = ( - f"Warning: This documentation is only a preview for {PR_TEXT}!" - ) + html_theme_options["announcement"] = f"Warning: 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, From e163f154b67931836e7ec18e7a11ea6ca45ce016 Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Sun, 19 Jan 2025 14:15:26 -0500 Subject: [PATCH 10/10] try to apply suggestions --- .github/actions/get_pr_number/action.yml | 49 ++++++++++++------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/.github/actions/get_pr_number/action.yml b/.github/actions/get_pr_number/action.yml index 4aecb9f4f7..58cf1b81eb 100644 --- a/.github/actions/get_pr_number/action.yml +++ b/.github/actions/get_pr_number/action.yml @@ -5,47 +5,48 @@ description: Get the PR number without relying on the pull_request* event trigge runs: using: composite steps: - # The steps below are executed only when testing in a PR. - - name: Get PR info + - 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 from 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 [[ "$PR_NUMBER" == "" ]]; then - echo "cannot extract PR number" + if [[ -z "$PR_NUMBER" ]]; then + echo "Cannot extract PR number for ref: ${{ github.ref_name }}" exit 1 - else - echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV fi - - # The steps below are executed only when building on main. - - name: Get PR data + 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: | - 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 + 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 [[ "$PR_NUMBER" == "" ]]; then - echo "cannot extract PR number" + if [[ -z "$PR_NUMBER" ]]; then + echo "No associated PR found for the commit in 'main'." exit 1 - else - echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV fi + echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV