|
| 1 | +name: Build and Preview Docs |
| 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-24.04 |
| 23 | + env: |
| 24 | + HUGO_VERSION: 0.157.0 |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout PR code |
| 28 | + if: github.event.action != 'closed' |
| 29 | + uses: actions/checkout@v6 |
| 30 | + with: |
| 31 | + repository: ${{ github.event.pull_request.head.repo.full_name }} |
| 32 | + ref: ${{ github.event.pull_request.head.sha }} |
| 33 | + persist-credentials: false |
| 34 | + submodules: recursive |
| 35 | + fetch-depth: 0 |
| 36 | + |
| 37 | + - name: Checkout for cleanup |
| 38 | + if: github.event.action == 'closed' |
| 39 | + uses: actions/checkout@v6 |
| 40 | + with: |
| 41 | + ref: gh-pages |
| 42 | + fetch-depth: 0 |
| 43 | + |
| 44 | + - name: Install Hugo CLI |
| 45 | + if: github.event.action != 'closed' |
| 46 | + run: | |
| 47 | + wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \ |
| 48 | + && sudo dpkg -i ${{ runner.temp }}/hugo.deb |
| 49 | +
|
| 50 | + - name: Install Dart Sass |
| 51 | + if: github.event.action != 'closed' |
| 52 | + run: sudo snap install dart-sass |
| 53 | + |
| 54 | + - name: Setup Node |
| 55 | + if: github.event.action != 'closed' |
| 56 | + uses: actions/setup-node@v4 |
| 57 | + with: |
| 58 | + node-version: "20" |
| 59 | + |
| 60 | + - name: Install dependencies |
| 61 | + if: github.event.action != 'closed' |
| 62 | + run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true" |
| 63 | + |
| 64 | + - name: Build PR preview |
| 65 | + if: github.event.action != 'closed' |
| 66 | + env: |
| 67 | + HUGO_ENVIRONMENT: production |
| 68 | + HUGO_ENV: production |
| 69 | + HUGO_PREVIEW: "true" |
| 70 | + run: | |
| 71 | + hugo \ |
| 72 | + --gc \ |
| 73 | + --minify \ |
| 74 | + --baseURL "/" |
| 75 | + cat > public/robots.txt <<'EOF' |
| 76 | + User-agent: * |
| 77 | + Disallow: / |
| 78 | + EOF |
| 79 | +
|
| 80 | + - name: Deploy PR preview |
| 81 | + if: github.event.action != 'closed' |
| 82 | + uses: rossjrw/pr-preview-action@v1.6.3 |
| 83 | + with: |
| 84 | + source-dir: ./public |
| 85 | + preview-branch: gh-pages |
| 86 | + umbrella-dir: pr-preview |
| 87 | + action: auto |
| 88 | + comment: false |
| 89 | + |
| 90 | + - name: Comment PR with Preview URL |
| 91 | + if: github.event.action != 'closed' |
| 92 | + uses: marocchino/sticky-pull-request-comment@v2 |
| 93 | + with: |
| 94 | + header: pr-preview |
| 95 | + message: | |
| 96 | + 🚀 **Preview deployment for PR #${{ github.event.pull_request.number }}** |
| 97 | +
|
| 98 | + 🌐 **Preview URL**: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.pull_request.number }}/ |
| 99 | +
|
| 100 | + _This preview will be updated automatically when you push new commits to this PR._ |
| 101 | + - name: Cleanup PR preview on close |
| 102 | + if: github.event.action == 'closed' |
| 103 | + uses: rossjrw/pr-preview-action@v1.6.3 |
| 104 | + with: |
| 105 | + preview-branch: gh-pages |
| 106 | + umbrella-dir: pr-preview |
| 107 | + action: remove |
0 commit comments