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