|
| 1 | +name: Build and Preview Site |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + branches: [master] |
| 6 | + types: [opened, synchronize, reopened, closed] |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + pull-requests: write |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: preview-${{ github.event.pull_request.number || github.run_id }} |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +defaults: |
| 17 | + run: |
| 18 | + shell: bash |
| 19 | + |
| 20 | +jobs: |
| 21 | + build-and-deploy-preview: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Checkout PR code |
| 26 | + if: github.event.action != 'closed' |
| 27 | + uses: actions/checkout@v6 |
| 28 | + with: |
| 29 | + repository: ${{ github.event.pull_request.head.repo.full_name }} |
| 30 | + ref: ${{ github.event.pull_request.head.sha }} |
| 31 | + persist-credentials: false |
| 32 | + fetch-depth: 0 |
| 33 | + |
| 34 | + - name: Checkout for cleanup |
| 35 | + if: github.event.action == 'closed' |
| 36 | + uses: actions/checkout@v6 |
| 37 | + with: |
| 38 | + ref: gh-pages |
| 39 | + fetch-depth: 0 |
| 40 | + |
| 41 | + - name: Setup Go |
| 42 | + if: github.event.action != 'closed' |
| 43 | + uses: actions/setup-go@v5 |
| 44 | + with: |
| 45 | + go-version-file: go.mod |
| 46 | + cache: true |
| 47 | + |
| 48 | + - name: Setup Hugo Extended |
| 49 | + if: github.event.action != 'closed' |
| 50 | + uses: peaceiris/actions-hugo@v3 |
| 51 | + with: |
| 52 | + hugo-version: '0.158.0' |
| 53 | + extended: true |
| 54 | + |
| 55 | + - name: Setup Node |
| 56 | + if: github.event.action != 'closed' |
| 57 | + uses: actions/setup-node@v4 |
| 58 | + with: |
| 59 | + node-version: '20' |
| 60 | + cache: 'npm' |
| 61 | + |
| 62 | + - name: Setup site dependencies |
| 63 | + if: github.event.action != 'closed' |
| 64 | + run: make setup |
| 65 | + |
| 66 | + - name: Build PR preview |
| 67 | + if: github.event.action != 'closed' |
| 68 | + run: | |
| 69 | + make build-preview BASE_URL="https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.pull_request.number }}/" |
| 70 | + touch public/.nojekyll |
| 71 | +
|
| 72 | + - name: Deploy PR preview |
| 73 | + if: github.event.action != 'closed' |
| 74 | + uses: rossjrw/pr-preview-action@v1.6.3 |
| 75 | + with: |
| 76 | + source-dir: ./public |
| 77 | + preview-branch: gh-pages |
| 78 | + umbrella-dir: pr-preview |
| 79 | + action: auto |
| 80 | + comment: false |
| 81 | + |
| 82 | + - name: Comment PR with Preview URL |
| 83 | + if: github.event.action != 'closed' |
| 84 | + uses: marocchino/sticky-pull-request-comment@v2 |
| 85 | + with: |
| 86 | + header: pr-preview |
| 87 | + message: | |
| 88 | + 🚀 **Preview deployment for PR #${{ github.event.pull_request.number }}** |
| 89 | +
|
| 90 | + 🌐 **Preview URL**: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.pull_request.number }}/ |
| 91 | +
|
| 92 | + _This preview will be updated automatically when you push new commits to this PR._ |
| 93 | +
|
| 94 | + - name: Cleanup PR preview on close |
| 95 | + if: github.event.action == 'closed' |
| 96 | + uses: rossjrw/pr-preview-action@v1.6.3 |
| 97 | + with: |
| 98 | + preview-branch: gh-pages |
| 99 | + umbrella-dir: pr-preview |
| 100 | + action: remove |
0 commit comments