GitHub Pages Cleanup #35
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |