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 9389d1a commit 7bf3ed7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
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: read
needs:
- build
secrets: inherit
Expand Down
55 changes: 39 additions & 16 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,40 +126,63 @@ jobs:
mkdir -p artifacts/docs
mv cuda_python/docs/build/html/* artifacts/docs/
# create an empty folder for removal use
mkdir -p artifacts/empty_docs
# TODO: remove this step
- name: Upload doc artifacts
uses: actions/upload-pages-artifact@v3
with:
path: artifacts/
retention-days: 3

- name: Collect PR data
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: Get PR number
run: |
PR_NUMBER="${{ fromJson(steps.get_pr_data.outputs.result).number }}"
echo "PR_NUMBER=${PR_NUMBER}" >> $GITHUB_ENV
# 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 doc preview
if: ${{ github.ref_name != 'main' }}
uses: JamesIves/github-pages-deploy-action@v4
with:
source-dir: artifacts/docs/
preview-branch: gh-pages
umbrella-dir: docs/pr-preview
pages-base-path: docs
action: deploy
git-config-name: cuda-python-bot
git-config-email: [email protected]
folder: artifacts/docs/
target-folder: docs/pr-preview/pr-${{ env.PR_NUMBER }}/
commit-message: "Deploy doc preview for PR ${{ env.PR_NUMBER }} (${{ github.sha }})"

# 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() }}
- name: Remove doc preview
if: ${{ github.ref_name == 'main' }}
uses: JamesIves/github-pages-deploy-action@v4
with:
source-dir: artifacts/docs/
preview-branch: gh-pages
umbrella-dir: docs/pr-preview
pages-base-path: docs
action: remove
git-config-name: cuda-python-bot
git-config-email: [email protected]
folder: artifacts/empty_docs/
target-folder: docs/pr-preview/pr-${{ env.PR_NUMBER }}/
commit-message: "Deploy doc preview for PR ${{ env.PR_NUMBER }} (${{ github.sha }})"

0 comments on commit 7bf3ed7

Please sign in to comment.