diff --git a/.github/workflows/docs-deploy.yml b/.github/workflows/docs-deploy.yml new file mode 100644 index 000000000..5afc4c0a9 --- /dev/null +++ b/.github/workflows/docs-deploy.yml @@ -0,0 +1,76 @@ +# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Deploy Documentation + +on: + push: + branches: + - dev + # - main # Uncomment after dev is merged into main + paths: + - "docs/**" + - "pyproject.toml" + - ".github/workflows/docs-deploy.yml" + workflow_dispatch: + +concurrency: + group: docs-deploy-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: write + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install uv + uses: astral-sh/setup-uv@v7 + with: + version: "0.9.5" + enable-cache: true + cache-dependency-glob: "pyproject.toml" + + - name: Build documentation + run: uv run --group docs sphinx-build docs docs/_build/html -W --keep-going + + - name: Deploy docs (dev branch) + if: github.ref == 'refs/heads/dev' + uses: peaceiris/actions-gh-pages@v4 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./docs/_build/html + publish_branch: gh-pages + destination_dir: dev + keep_files: true + user_name: "github-actions[bot]" + user_email: "github-actions[bot]@users.noreply.github.com" + commit_message: "docs: deploy dev from ${{ github.sha }}" + + # Uncomment after dev is merged into main + # - name: Deploy docs (main branch) + # if: github.ref == 'refs/heads/main' + # uses: peaceiris/actions-gh-pages@v4 + # with: + # github_token: ${{ secrets.GITHUB_TOKEN }} + # publish_dir: ./docs/_build/html + # publish_branch: gh-pages + # keep_files: true + # user_name: "github-actions[bot]" + # user_email: "github-actions[bot]@users.noreply.github.com" + # commit_message: "docs: deploy from ${{ github.sha }}" diff --git a/.github/workflows/docs-preview.yml b/.github/workflows/docs-preview.yml new file mode 100644 index 000000000..52bea7c4a --- /dev/null +++ b/.github/workflows/docs-preview.yml @@ -0,0 +1,128 @@ +# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Deploy PR Documentation Preview + +on: + pull_request: + branches: + - dev + # - main # Uncomment after dev is merged into main + paths: + - "docs/**" + - "pyproject.toml" + - ".github/workflows/docs-preview.yml" + types: [opened, synchronize, reopened, closed] + +concurrency: + group: docs-preview-${{ github.event.pull_request.number }} + cancel-in-progress: true + +permissions: + contents: write + pull-requests: write + +jobs: + build-and-deploy-preview: + if: github.event.action != 'closed' + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install uv + uses: astral-sh/setup-uv@v7 + with: + version: "0.9.5" + enable-cache: true + cache-dependency-glob: "pyproject.toml" + + - name: Build documentation + run: uv run --group docs sphinx-build docs docs/_build/html + + - name: Deploy PR preview + uses: peaceiris/actions-gh-pages@v4 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./docs/_build/html + publish_branch: gh-pages + destination_dir: pr-${{ github.event.pull_request.number }} + keep_files: true + user_name: "github-actions[bot]" + user_email: "github-actions[bot]@users.noreply.github.com" + commit_message: "docs: preview for PR #${{ github.event.pull_request.number }}" + + - name: Comment PR with preview link + uses: actions/github-script@v7 + with: + script: | + const prNumber = context.payload.pull_request.number; + const owner = context.repo.owner; + const repo = context.repo.repo; + const previewUrl = `https://${owner}.github.io/${repo}/pr-${prNumber}/`; + + const comments = await github.rest.issues.listComments({ + owner, + repo, + issue_number: prNumber, + }); + + const botComment = comments.data.find( + (c) => c.user.type === "Bot" && c.body.includes("Documentation Preview") + ); + + const body = `## Documentation Preview + +:book: **Preview URL:** ${previewUrl} + +_Built from commit ${context.sha.substring(0, 7)}_`; + + if (botComment) { + await github.rest.issues.updateComment({ + owner, + repo, + comment_id: botComment.id, + body, + }); + } else { + await github.rest.issues.createComment({ + owner, + repo, + issue_number: prNumber, + body, + }); + } + + cleanup-preview: + if: github.event.action == 'closed' + runs-on: ubuntu-latest + steps: + - name: Checkout gh-pages branch + uses: actions/checkout@v4 + with: + ref: gh-pages + fetch-depth: 0 + + - name: Delete preview directory + run: | + PR_DIR="pr-${{ github.event.pull_request.number }}" + if [ -d "$PR_DIR" ]; then + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git rm -rf "$PR_DIR" + git commit -m "docs: cleanup preview for PR #${{ github.event.pull_request.number }}" + git push origin gh-pages + else + echo "Preview directory $PR_DIR does not exist, skipping cleanup" + fi