Skip to content

Commit

Permalink
add custom preview deploy/undeploy steps
Browse files Browse the repository at this point in the history
  • Loading branch information
leofang committed Jan 16, 2025
1 parent 6699fb8 commit b246c77
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 21 deletions.
99 changes: 99 additions & 0 deletions .github/actions/doc_preview/action.yml
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.
1 change: 1 addition & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ jobs:
permissions:
id-token: write
contents: write
pull-requests: write
needs:
- build
secrets: inherit
Expand Down
32 changes: 11 additions & 21 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b246c77

Please sign in to comment.