|
| 1 | +name: Site preview |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +jobs: |
| 9 | + site-preview: |
| 10 | + name: Publish site preview |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + pull-requests: write |
| 14 | + steps: |
| 15 | + - name: Checkout |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + ref: "refs/pull/${{ github.event.number }}/merge" |
| 19 | + |
| 20 | + - name: Setup Ruby |
| 21 | + uses: ruby/setup-ruby@v1 |
| 22 | + with: |
| 23 | + ruby-version: "3.1" |
| 24 | + bundler-cache: true |
| 25 | + |
| 26 | + - name: Build Jekyll website |
| 27 | + run: bundler exec jekyll build |
| 28 | + |
| 29 | + - name: Install Netlify CLI |
| 30 | + run: npm install --location=global [email protected] |
| 31 | + |
| 32 | + - name: Deploy Preview to Netlify |
| 33 | + run: | |
| 34 | + netlify deploy \ |
| 35 | + --alias="${GITHUB_REPOSITORY#*/}-${{ github.event.number }}" \ |
| 36 | + --auth=${{ secrets.NETLIFY_AUTH_TOKEN }} \ |
| 37 | + --dir="_site" \ |
| 38 | + --site=${{ vars.NETLIFY_PREVIEW_APP_SITE_ID }} |
| 39 | +
|
| 40 | + - name: Find existing comment |
| 41 | + uses: peter-evans/find-comment@v3 |
| 42 | + id: find-comment |
| 43 | + with: |
| 44 | + issue-number: ${{ github.event.number }} |
| 45 | + comment-author: "github-actions[bot]" |
| 46 | + body-includes: "Preview url: https://" |
| 47 | + |
| 48 | + - name: Add Netlify link PR comment |
| 49 | + uses: actions/github-script@v7 |
| 50 | + if: steps.find-comment.outputs.comment-id == '' |
| 51 | + with: |
| 52 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 53 | + script: | |
| 54 | + const hostnameSuffix = "compiler-previews.netlify.app" |
| 55 | + github.rest.issues.createComment({ |
| 56 | + issue_number: context.issue.number, |
| 57 | + owner: context.repo.owner, |
| 58 | + repo: context.repo.repo, |
| 59 | + body: `Preview url: https://${context.repo.repo}-${{ github.event.number }}--${hostnameSuffix}`, |
| 60 | + }) |
0 commit comments