Added PR previews to documentation. #7
Workflow file for this run
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: docs | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| permissions: | |
| pages: write | |
| id-token: write | |
| jobs: | |
| # Build job | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| lfs: true | |
| - name: Set up Python | |
| uses: actions/setup-python@v2 | |
| - name: Install package | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install setuptools wheel | |
| pip install -e .[doc] | |
| - name: Setup Pages | |
| id: pages | |
| uses: actions/configure-pages@v3 | |
| - name: Build with Sphinx | |
| run: | | |
| cd ./docs | |
| make html | |
| - name: Upload build artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: docs/_build/html/ | |
| - name: Generate meta.json | |
| if: github.event_name == 'pull_request' | |
| env: | |
| PR_NUMBER: ${{ github.event.number }} | |
| PR_BRANCH: ${{ github.head_ref }} | |
| run: | | |
| echo "{\"pr_number\": \"$PR_NUMBER\", \"pr_branch\": \"$PR_BRANCH\"}" > meta.json | |
| - name: Upload meta.json | |
| if: github.event_name == 'pull_request' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: meta.json | |
| path: meta.json | |
| # Deployment job | |
| deploy: | |
| if: github.event_name == 'push' | |
| environment: | |
| name: github-pages | |
| url: ${{steps.deployment.outputs.page_url}} | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 | |
| deploy-preview: | |
| if: github.event_name == 'pull_request' | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - name: 'Download build artifact' | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: github-pages | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| run-id: ${{ github.event.workflow_run.id }} | |
| - name: 'Download meta.json' | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: meta.json | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| run-id: ${{ github.event.workflow_run.id }} | |
| - name: Parse meta.json | |
| run: | | |
| echo "PR_NUMBER=$(jq -r .pr_number meta.json)" >> $GITHUB_ENV | |
| echo "PR_BRANCH=$(jq -r .pr_branch meta.json)" >> $GITHUB_ENV | |
| - name: Url slug variable | |
| run: | | |
| echo "URL_SLUG=${{ env.PR_NUMBER }}-${{ env.PR_BRANCH }}" >> $GITHUB_ENV | |
| - name: Deploy | |
| uses: JamesIves/github-pages-deploy-action@v4 | |
| with: | |
| folder: github-pages | |
| repository-name: esis-mission/esis-pr-previews | |
| branch: 'main' | |
| clean: true | |
| target-folder: ${{ env.URL_SLUG }} | |
| ssh-key: ${{ secrets.DEPLOY_KEY }} | |
| commit-message: "Update preview for PR ${{ env.URL_SLUG }}" | |
| single-commit: true | |
| - name: Comment PR | |
| uses: thollander/actions-comment-pull-request@v2 | |
| with: | |
| message: | | |
| Preview available at https://esis-mission.github.io/esis-pr-previews/${{ env.URL_SLUG }} | |
| Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed. | |
| pr_number: ${{ env.PR_NUMBER }} | |
| comment_tag: 'esis-preview' |