Skip to content

GitHub Pages Cleanup #35

GitHub Pages Cleanup

GitHub Pages Cleanup #35

name: GitHub Pages Cleanup
on:
schedule:
- cron: 0 0 * * 6 # midnight on Saturdays
workflow_dispatch:
jobs:
cleanup:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Check out GitHub Pages branch
uses: actions/checkout@v4
with:
# replace `fetch-depth` with `shallow-since` if and when actions/checkout#619 (or an equivalent) gets merged
fetch-depth: 0
ref: gh-pages
- name: Mark stale directories for removal
run: |
for dir in */; do
if [ -z "$(git log -n 1 --since "1 month ago" -- "$dir")" ]; then
echo "Removing stale directory: $dir"
git rm --quiet -r "$dir"
fi
done
- name: Configure git user
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
- name: Commit
run: |
if diff --staged --quiet; then
echo 'No stale directories were found. Nothing to commit.'
else
git commit -m 'chore: remove stale GitHub Pages branches'
fi
- name: Push
run: "git push"