garbage collection #13
This file contains 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: garbage collection | |
on: | |
# pull_request: | |
# types: [opened, reopened, synchronize] | |
# https://crontab.guru/#0_1_1_*_* | |
workflow_dispatch: | |
schedule: | |
- cron: "0 1 1 * *" | |
permissions: | |
actions: write | |
contents: write | |
id-token: write | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
jobs: | |
garbage_collection: | |
name: Remove old build result on GH page | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: gh-pages | |
- id: remove | |
run: | | |
OLD_FOLDERS=$(git ls-tree -r --name-only gh-pages@{30.days.ago} | cut -d/ -f1 | uniq) | |
echo OLD_FOLDERS=$OLD_FOLDERS | |
if [ -z "$OLD_FOLDERS" ]; then | |
echo "result=''" >> $GITHUB_OUTPUT | |
else | |
rm -r $OLD_FOLDERS | |
git add . | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
git commit -m "docs: 🤖 garbage collection old build results" | |
echo "result=1" >> $GITHUB_OUTPUT | |
fi | |
- name: Push changes | |
uses: ad-m/github-push-action@master | |
if: ${{ steps.remove.outputs.result == 1 }} | |
with: | |
github_token: ${{ env.GITHUB_TOKEN }} | |
branch: gh-pages | |
trigger_schedule: | |
name: Trigger schedule | |
needs: [garbage_collection] | |
uses: ./.github/workflows/schedule.yml |