|
| 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. |
0 commit comments