This file contains hidden or 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
| name: Deploy Documentation Preview | |
| on: | |
| pull_request: | |
| branches: [ main ] | |
| paths: | |
| - 'docs/**' | |
| - 'varunayan/**' | |
| - 'pyproject.toml' | |
| - '.github/workflows/preview-deploy.yml' | |
| jobs: | |
| deploy-preview: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| issues: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements-docs.txt | |
| pip install -e . | |
| - name: Build documentation | |
| run: | | |
| cd docs | |
| make clean | |
| make html | |
| - name: Deploy to Netlify | |
| uses: nwtgck/actions-netlify@v2.1 | |
| with: | |
| publish-dir: './docs/_build/html' | |
| production-branch: main | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| deploy-message: "Deploy from GitHub Actions" | |
| enable-pull-request-comment: true | |
| enable-commit-comment: true | |
| overwrites-pull-request-comment: true | |
| env: | |
| NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | |
| NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} | |
| timeout-minutes: 10 | |
| - name: Comment PR with preview link | |
| uses: actions/github-script@v7 | |
| if: github.event_name == 'pull_request' | |
| with: | |
| script: | | |
| const { data: deployments } = await github.rest.repos.listDeployments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| environment: 'preview' | |
| }); | |
| if (deployments.length > 0) { | |
| const deployment = deployments[0]; | |
| const { data: statuses } = await github.rest.repos.listDeploymentStatuses({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| deployment_id: deployment.id | |
| }); | |
| const successStatus = statuses.find(status => status.state === 'success'); | |
| if (successStatus && successStatus.target_url) { | |
| await github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: `**Documentation Preview Ready!**\n\n**Preview URL:** ${successStatus.target_url}\n\nThis preview will be updated with each new commit to this PR.` | |
| }); | |
| } | |
| } |