-
Notifications
You must be signed in to change notification settings - Fork 150
66 lines (60 loc) · 2.06 KB
/
GHPages-Cleanup.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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@v3
with:
ref: 'gh-pages'
path: 'gh-pages'
- name: Configure Git
run: |
git config --global user.name "GitHub Actions Bot"
git config --global user.email "actions@users.noreply.github.com"
#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