-
Notifications
You must be signed in to change notification settings - Fork 113
46 lines (38 loc) · 1.51 KB
/
cleanup-nightly-assets.yaml
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
name: Cleanup Nightly Assets
on:
workflow_dispatch: # Manual trigger
schedule:
- cron: '0 0 * * 0' # At 00:00 on Sunday, UTC
jobs:
nightly:
if: ${{ github.repository == 'shipwright-io/build' }}
runs-on: ubuntu-latest
permissions:
contents: write # To be able to update releases.
steps:
- uses: actions/checkout@v3
- name: Get current month
id: currentmonth
run: echo "date=$(date +'%Y-%m')" >> $GITHUB_OUTPUT
- name: Get previous month
id: previousmonth
run: echo "date=$(date -d "1 month ago" +%Y-%m)" >> $GITHUB_OUTPUT
- name: Generate and upload release YAMLs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
WORK_DIR=`mktemp -d -p "$DIR"`
gh release download nightly -D ${WORK_DIR}
ASSETS_TOTAL=$(ls $WORK_DIR | wc -l)
echo "[INFO] Currently ${ASSETS_TOTAL} assets for nightly release"
ASSETS_TO_REMOVE=$(ls $WORK_DIR | grep -v "${{ steps.currentmonth.outputs.date }}\|${{ steps.previousmonth.outputs.date }}" | wc -l)
if [ "$ASSETS_TO_REMOVE" -eq "0" ]; then
echo "[INFO] Nothing to delete"
exit 0
fi
find $WORK_DIR -type f -iname "*.yaml" -printf "%f\n" | grep -v "${{ steps.currentmonth.outputs.date }}\|${{ steps.previousmonth.outputs.date }}" |
while IFS= read FILE; do
gh release delete-asset nightly $FILE -y
done
rm -rf "$WORK_DIR"
echo "[INFO] Deleted temporary directory ${WORK_DIR}"