|
1 | 1 | name: Publish docs
|
2 | 2 | on:
|
3 | 3 | workflow_dispatch:
|
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths: |
| 8 | + - "docs/**" |
| 9 | + - "mkdocs.yml" |
| 10 | + - ".github/workflows/mkdocs.yml" |
4 | 11 | push:
|
5 | 12 | branches:
|
6 | 13 | - main
|
|
11 | 18 | - "mkdocs.yml"
|
12 | 19 |
|
13 | 20 | jobs:
|
| 21 | + docs-preview: |
| 22 | + name: Publish docs preview |
| 23 | + runs-on: ubuntu-latest |
| 24 | + # only pull requests should generate a preview |
| 25 | + if: github.event.pull_request |
| 26 | + permissions: |
| 27 | + pull-requests: write |
| 28 | + steps: |
| 29 | + - name: Checkout |
| 30 | + uses: actions/checkout@v4 |
| 31 | + with: |
| 32 | + ref: "refs/pull/${{ github.event.number }}/merge" |
| 33 | + |
| 34 | + - name: Setup Python |
| 35 | + uses: actions/setup-python@v5 |
| 36 | + with: |
| 37 | + python-version-file: .github/workflows/.python-version |
| 38 | + cache: pip |
| 39 | + cache-dependency-path: "docs/requirements.txt" |
| 40 | + |
| 41 | + - name: Build MkDocs website |
| 42 | + run: | |
| 43 | + pip install -r docs/requirements.txt |
| 44 | + mkdocs build |
| 45 | +
|
| 46 | + - name: Install Netlify CLI |
| 47 | + run: npm install --location=global netlify-cli@17.x.x |
| 48 | + |
| 49 | + - name: Deploy Preview to Netlify |
| 50 | + run: | |
| 51 | + netlify deploy \ |
| 52 | + --alias="${GITHUB_REPOSITORY#*/}-${{ github.event.number }}" \ |
| 53 | + --auth=${{ secrets.NETLIFY_AUTH_TOKEN }} \ |
| 54 | + --dir="site" \ |
| 55 | + --site=${{ vars.NETLIFY_PREVIEW_APP_SITE_ID }} |
| 56 | +
|
| 57 | + - name: Find existing comment |
| 58 | + uses: peter-evans/find-comment@v3 |
| 59 | + id: find-comment |
| 60 | + with: |
| 61 | + issue-number: ${{ github.event.number }} |
| 62 | + comment-author: "github-actions[bot]" |
| 63 | + body-includes: "Preview url: https://" |
| 64 | + |
| 65 | + - name: Add Netlify link PR comment |
| 66 | + uses: actions/github-script@v7 |
| 67 | + if: steps.find-comment.outputs.comment-id == '' |
| 68 | + with: |
| 69 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 70 | + script: | |
| 71 | + const hostnameSuffix = "compiler-previews.netlify.app" |
| 72 | + github.rest.issues.createComment({ |
| 73 | + issue_number: context.issue.number, |
| 74 | + owner: context.repo.owner, |
| 75 | + repo: context.repo.repo, |
| 76 | + body: `Preview url: https://${context.repo.repo}-${{ github.event.number }}--${hostnameSuffix}`, |
| 77 | + }) |
| 78 | +
|
14 | 79 | docs:
|
15 | 80 | name: Publish docs
|
16 | 81 | runs-on: ubuntu-latest
|
| 82 | + # don't publish for pull requests |
| 83 | + if: github.event.pull_request == null |
17 | 84 | permissions:
|
18 | 85 | contents: write
|
19 | 86 | steps:
|
|
0 commit comments