-
Notifications
You must be signed in to change notification settings - Fork 25
58 lines (51 loc) · 1.88 KB
/
e2e-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
# Nightly cleanup to remove old PRs from skyux-pr-preview. Runs at 3:00 AM UTC.
name: E2E Cleanup
on:
schedule:
- cron: '0 3 * * *'
jobs:
cleanup:
name: Cleanup
runs-on: ubuntu-latest
steps:
- name: Checkout blackbaud/skyux-pr-preview
uses: actions/checkout@v4
with:
repository: blackbaud/skyux-pr-preview
ref: 'main'
fetch-depth: 1
token: ${{secrets.GH_PERSONAL_ACCESS_TOKEN}}
- name: Delete old PR previews
run: |
set -exuo pipefail
# List open PR numbers and save to a temporary file.
gh pr list -R blackbaud/skyux -s open --json number --jq '.[] | .number' > ${{ runner.temp }}/open-prs.txt
if [[ ! -s ${{ runner.temp }}/open-prs.txt ]]
then
echo "No open PRs found. Exiting."
exit 0
fi
# List the checkout files, filter to just number directories, filter out open PRs.
ls | grep -E '^[0-9]+$' | grep -v -f ${{ runner.temp }}/open-prs.txt > ${{ runner.temp }}/delete-prs.txt
# Delete the directories.
if [[ -s ${{ runner.temp }}/delete-prs.txt ]]
then
for pr in $(cat ${{ runner.temp }}/delete-prs.txt)
do
if [[ -d $pr ]]
then
echo "Deleting $pr"
git rm -qrf $pr
fi
done
fi
# If there are any changes, configure the user, commit the deletions, and push to skyux-pr-preview repo.
if [[ -n "$(git status --porcelain)" ]]
then
git config user.name 'Blackbaud Sky Build User'
git config user.email '[email protected]'
git commit -m "Delete old PR previews $(date +'%Y-%m-%d')"
git push
fi
env:
GITHUB_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}