cleanup-pr-previews.yml
The housekeeping half of the PR-preview family. On a schedule, it deletes gh-pages preview directories for pull requests that are no longer open.
Inputs
| Input | Type | Default | Description |
|---|---|---|---|
preview-dir |
string | 'pr-preview' |
Directory on gh-pages that holds the per-PR preview subdirectories. |
compact-history |
boolean | false |
Orphan-squash the gh-pages branch to a single commit after pruning, discarding accumulated preview/publish history to reclaim the space deleted snapshots still occupy. Safe for branch-based Pages (what the preview family uses). |
Permissions
Grant contents: write (commit the deletions to gh-pages) and pull-requests: read.
Example
Do not name a concurrency: group gh-pages anywhere in your caller workflow – neither a top-level block nor one on the calling job, which deadlock identically. Any other group name is fine, and is how you serialize the caller’s own runs. cleanup-pr-previews.yml serializes its gh-pages branch modifications with the deploy workflows on its cleanup job (group: gh-pages). A caller-level block with the same group name deadlocks GitHub Actions against the nested job: cleanup fails with no runner, no steps, and no log. This workflow publishes nothing, so the symptom is not a stale site: the deletions never land, and preview directories for closed PRs accumulate on gh-pages (gha#809).
# Copy to .github/workflows/cleanup-pr-previews.yml in your repo.
# Housekeeping half of the PR-preview family: periodically deletes gh-pages
# preview directories for PRs that are no longer open. The calling job grants
# contents:write so it can commit the deletions back to gh-pages.
name: Clean up PR Previews
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * 0" # Weekly on Sunday at midnight UTC
jobs:
cleanup:
permissions:
contents: write
pull-requests: read
uses: Morrison-Lab/gha/.github/workflows/cleanup-pr-previews.yml@v2
# with:
# preview-dir: pr-preview # gh-pages dir holding the per-PR previews
# compact-history: true # orphan-squash gh-pages to one commit after
# # pruning, so deleted snapshots stop bloating
# # the repo. Branch-based Pages only.See examples/cleanup-pr-previews.yml for the full caller stub.