Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 40 additions & 7 deletions .github/workflows/CleanPreviewDoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,62 @@ name: Cleanup Preview Documentation
on:
pull_request:
types: [closed]
schedule:
- cron: "0 0 * * 0" # Run weekly on Sunday at midnight
workflow_dispatch:

permissions:
contents: write
deployments: write

jobs:
cleanup-preview-doc:
runs-on: ubuntu-latest
steps:
- name: Checkout gh-pages branch
uses: actions/checkout@v5
uses: actions/checkout@v4
with:
ref: gh-pages
- name: Delete preview and history + push changes
- name: Delete preview(s) and reset history
run: |
if [ -d "previews/PR$PRNUM" ]; then
# If triggered by PR close, delete that specific preview
if [ "${{ github.event_name }}" = "pull_request" ]; then
PRNUM=${{ github.event.number }}
if [ -d "previews/PR$PRNUM" ]; then
echo "Deleting preview for PR #$PRNUM"
git rm -rf "previews/PR$PRNUM"
fi
else
# Scheduled/manual run: check all previews against open PRs
echo "Checking all preview folders for stale PRs..."

# Get list of all PR preview folders
if [ -d "previews" ]; then
for dir in previews/PR*; do
[ -d "$dir" ] || continue
PRNUM=$(echo "$dir" | grep -oP 'PR\K\d+')

# Check if PR is still open via GitHub API
STATUS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/$PRNUM" \
| jq -r '.state // "closed"')

if [ "$STATUS" != "open" ]; then
echo "Deleting stale preview for closed PR #$PRNUM"
git rm -rf "$dir"
fi
done
fi
fi

# Only commit and push if there are changes
if ! git diff --cached --quiet; then
git config user.name "Documenter.jl"
git config user.email "[email protected]"
git rm -rf "previews/PR$PRNUM"
git commit -m "delete preview"
git commit -m "delete preview(s)"
git branch gh-pages-new $(echo "delete history" | git commit-tree HEAD^{tree})
git push --force origin gh-pages-new:gh-pages
else
echo "No stale previews found"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PRNUM: ${{ github.event.number }}
Loading