-
Notifications
You must be signed in to change notification settings - Fork 56
90 lines (81 loc) · 2.51 KB
/
purge-main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: Purge old images from main branch
on:
workflow_dispatch:
schedule:
- cron: "0 0/3 * * *"
- cron: "0 1/3 * * *"
- cron: "0 2/3 * * *"
jobs:
find-version:
name: Delete version from main ref
runs-on: ubuntu-22.04
outputs:
version: ${{ steps.find.outputs.version }}
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ github.head_ref }}
- name: Login to AWS
uses: aws-actions/configure-aws-credentials@5fd3084fc36e372ff1fff382a39b10d03659f355 # v2.2.0
with:
role-to-assume: arn:aws:iam::795746500882:role/GithubConstellationVersionsAPIRead
aws-region: eu-central-1
- name: Determine stream
id: stream
run: |
case "${{ github.event.schedule }}" in
"0 0/3 * * *")
echo "stream=debug" | tee -a "$GITHUB_OUTPUT"
;;
"0 1/3 * * *")
echo "stream=console" | tee -a "$GITHUB_OUTPUT"
;;
"0 2/3 * * *")
echo "stream=nightly" | tee -a "$GITHUB_OUTPUT"
;;
*)
echo "Unknown schedule: ${{ github.event.schedule }}"
exit 1
;;
esac
- name: List versions
id: list
uses: ./.github/actions/versionsapi
with:
command: list
ref: main
stream: ${{ steps.stream.outputs.stream }}
- name: Find version to delete
id: find
shell: bash
run: |
versions=$(cat versionsapi_output.txt)
echo "Found versions:"
echo "${versions}"
echo "Newest 10 versions shouldn't be deleted"
deletable=$(echo "${versions}" | head -n -10)
if [[ -z "${deletable}" ]]; then
echo "No deletable versions found"
exit 0
fi
echo "Found deletable versions:"
echo "${deletable}"
ver=$(echo "${deletable}" | head -n 1)
echo "Deleting oldest version: ${ver}"
echo "version=${ver}" | tee -a "$GITHUB_OUTPUT"
delete:
name: Delete version
if: needs.find-version.outputs.version != ''
permissions:
id-token: write
contents: read
uses: ./.github/workflows/versionsapi.yml
needs: find-version
secrets: inherit
with:
command: remove
version_path: ${{ needs.find-version.outputs.version }}