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
# 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.