|
22 | 22 |
|
23 | 23 | steps:
|
24 | 24 | - name: Debug dump
|
| 25 | + if: runner.debug == '1' |
25 | 26 | uses: crazy-max/ghaction-dump-context@v2
|
26 | 27 |
|
27 | 28 | - name: Checkout branch contents
|
| 29 | + if: github.event.action != 'closed' |
28 | 30 | uses: actions/checkout@v4
|
29 | 31 | with:
|
30 | 32 | repository: ${{ github.event.pull_request.head.repo.full_name }}
|
|
52 | 54 | JEKYLL_ENV=production bundle exec jekyll build --baseurl "${{ steps.pages.outputs.base_path || '' }}/${{ env.PREVIEWS_FOLDER }}/pr-${{ github.event.number }}"
|
53 | 55 |
|
54 | 56 | - name: Commit preview to Pages branch
|
| 57 | + if: github.event.action != 'closed' |
55 | 58 | uses: rossjrw/pr-preview-action@v1.4.7
|
56 | 59 | with:
|
57 | 60 | source-dir: _site
|
58 | 61 | umbrella-dir: ${{ env.PREVIEWS_FOLDER }}
|
| 62 | + |
| 63 | + - name: Checkout Pages branch |
| 64 | + uses: actions/checkout@v4 |
| 65 | + with: |
| 66 | + ref: gh-pages |
| 67 | + |
| 68 | + - name: Clean up preview folders |
| 69 | + uses: actions/github-script@v7 |
| 70 | + with: |
| 71 | + script: | |
| 72 | + const { rm } = require("fs").promises; |
| 73 | + const { PREVIEWS_FOLDER } = process.env; |
| 74 | + const { owner, repo } = context.repo; |
| 75 | + const prs = (await github.rest.pulls.list({ owner, repo, state: "closed" })).data; |
| 76 | + for (const { number } of prs) |
| 77 | + await rm(`${PREVIEWS_FOLDER}/pr-${number}`, { recursive: true, force: true }); |
| 78 | +
|
| 79 | + - name: Commit changed files |
| 80 | + uses: stefanzweifel/git-auto-commit-action@v5 |
| 81 | + with: |
| 82 | + branch: gh-pages |
| 83 | + commit_message: "Clean up previews" |
0 commit comments