diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7af4531..b6901c3 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -7,11 +7,9 @@ on: branches: [main] workflow_dispatch: -# Allow the workflow to write to GitHub Pages +# Write access to push the built site to the gh-pages branch permissions: - contents: read - pages: write - id-token: write + contents: write # Only allow one deployment at a time; don't cancel in-progress runs concurrency: @@ -19,7 +17,7 @@ concurrency: cancel-in-progress: false jobs: - build: + build-and-deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 @@ -41,18 +39,9 @@ jobs: # hugo.toml sets minifyOutput = false because Hugo's minifier # breaks PaperMod's JSON-LD schema output. - - name: Upload Pages artifact - uses: actions/upload-pages-artifact@v5 + - name: Deploy to gh-pages branch + uses: peaceiris/actions-gh-pages@v4 with: - path: site/public - - deploy: - needs: build - runs-on: ubuntu-latest - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - steps: - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v5 + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: site/public + publish_branch: gh-pages diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml new file mode 100644 index 0000000..35223d8 --- /dev/null +++ b/.github/workflows/preview.yml @@ -0,0 +1,40 @@ +name: PR Preview + +on: + pull_request: + types: [opened, synchronize, reopened, closed] + +# Write to gh-pages branch and post comments on the PR +permissions: + contents: write + pull-requests: write + +jobs: + preview: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + with: + submodules: recursive + fetch-depth: 0 + + - name: Setup Hugo + if: github.event.action != 'closed' + uses: peaceiris/actions-hugo@v3 + with: + hugo-version: '0.155.3' + extended: true + + - name: Build preview + if: github.event.action != 'closed' + # -D includes drafts so in-progress posts are visible in the preview + run: hugo --source site --baseURL "https://mathieson.github.io/blog/pr-preview/pr-${{ github.event.number }}/" -D + + - name: Deploy / remove preview + uses: rossjrw/pr-preview-action@v1 + with: + source-dir: site/public + preview-branch: gh-pages + umbrella-dir: pr-preview + action: auto + token: ${{ secrets.GITHUB_TOKEN }}