Skip to content

GH Pages Cleanup

GH Pages Cleanup #80

name: GH Pages Cleanup
on:
#Scheduled to run every Friday
schedule:
- cron: "0 8 * * 5"
workflow_dispatch:
inputs:
days:
description: 'Number of days ago to clean. Gh-pages artifacts from before this date will be removed.'
required: false
default: '5'
type: string
jobs:
cleanup:
runs-on: ubuntu-20.04
env:
DAYS: ${{ inputs.days || '5' }}
steps:
- name: Checkout GH Pages
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # pin@v4
with:
ref: 'gh-pages'
path: 'gh-pages'
- name: Configure Git
run: |
git config --global user.name "GitHub Actions Bot"
git config --global user.email "[email protected]"
#Look in spotbugs and test reports for directories containing a date.txt file.
#If the date.txt file contains a UTC string older than
#the input number of days ago, delete the directory.
- name: Delete old spotbugs folders
run: |
cd gh-pages
directories=$(find spotbugs -name date.txt -exec dirname {} \;)
for directory in $directories; do
date_in_file_utc=$(cat "$directory/date.txt")
clean_days_ago_utc=$(date -u -d "${{ env.DAYS }} days ago" +%s)
if ((date_in_file_utc < clean_days_ago_utc)); then
rm -rf $directory
fi
done
- name: Delete old reports folders
run: |
cd gh-pages
directories=$(find reports -name date.txt -exec dirname {} \;)
for directory in $directories; do
if [ -f $directory/date.txt ]; then
date_in_file_utc=$(cat "$directory/date.txt")
clean_days_ago_utc=$(date -u -d "${{ env.DAYS }} days ago" +%s)
if ((date_in_file_utc < clean_days_ago_utc)); then
rm -rf $directory
fi
fi
done
- name: Commit and push
run: |
cd gh-pages
git add .
git commit -m "Removing old folders from spotbugs and test reports"
git push