-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add custom preview deploy/undeploy steps
- Loading branch information
Showing
3 changed files
with
111 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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,99 @@ | ||
name: Preview docs built from PRs | ||
|
||
inputs: | ||
source-folder: | ||
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' }} | ||
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 | ||
- 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 }})" | ||
|
||
- 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 }} | ||
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> | ||
| <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' }} | ||
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 | ||
- 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 }})" | ||
|
||
- 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 }} | ||
hide_and_recreate: true | ||
hide_classify: "OUTDATED" | ||
message: | | ||
Doc Preview CI | ||
:---: | ||
Preview removed because the pull request was closed or merged. |
This file contains 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 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 |
---|---|---|
|
@@ -126,40 +126,30 @@ jobs: | |
mkdir -p artifacts/docs | ||
mv cuda_python/docs/build/html/* artifacts/docs/ | ||
# TODO: remove this step | ||
# create an empty folder for removal use | ||
mkdir -p artifacts/empty_docs | ||
# TODO: Consider removing this step? | ||
- name: Upload doc artifacts | ||
uses: actions/upload-pages-artifact@v3 | ||
with: | ||
path: artifacts/ | ||
retention-days: 3 | ||
|
||
# Note: the PR previews will be removed once merged to main (see below) | ||
- uses: rossjrw/pr-preview-action@v1 | ||
if: ${{ github.ref_name != 'main' && success() }} | ||
- name: Deploy or clean up doc preview | ||
uses: ./.github/actions/doc_preview | ||
continue-on-error: false | ||
with: | ||
source-dir: artifacts/docs/ | ||
preview-branch: gh-pages | ||
umbrella-dir: docs/pr-preview | ||
pages-base-path: docs | ||
action: deploy | ||
source-folder: ${{ (github.ref_name != 'main' && 'artifacts/docs') || | ||
'artifacts/empty_docs' }} | ||
|
||
# The steps below are not executed unless when building on main. | ||
- name: Deploy doc update | ||
if: ${{ github.ref_name == 'main' && success() }} | ||
if: ${{ github.ref_name == 'main' }} | ||
uses: JamesIves/github-pages-deploy-action@v4 | ||
with: | ||
folder: artifacts/docs/ | ||
git-config-name: cuda-python-bot | ||
git-config-email: [email protected] | ||
folder: artifacts/docs/ | ||
target-folder: docs/ | ||
commit-message: "Deploy latest docs: ${{ github.sha }}" | ||
clean: false | ||
|
||
- uses: rossjrw/pr-preview-action@v1 | ||
if: ${{ github.ref_name == 'main' && success() }} | ||
with: | ||
source-dir: artifacts/docs/ | ||
preview-branch: gh-pages | ||
umbrella-dir: docs/pr-preview | ||
pages-base-path: docs | ||
action: remove |