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