-
Notifications
You must be signed in to change notification settings - Fork 0
74 lines (67 loc) · 2.1 KB
/
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
67
68
69
70
71
72
73
74
name: cleanup
on:
workflow_call:
inputs:
branches:
description: "Branches to cleanup (comma separated)"
default: dev
required: false
type: string
endswith:
description: "Endswiths to cleanup (comma separated)"
default: -beta
required: false
type: string
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
branches: ${{ steps.targets.outputs.branches }}
endswith: ${{ steps.targets.outputs.endswith }}
steps:
- id: targets
run: |
# Convert comma-separated string to JSON array
BRANCHES=$(echo -n '${{ inputs.branches }}' | jq -R -s -c 'split(",")')
echo "branches=${BRANCHES}" >> ${GITHUB_OUTPUT}
ENDSWITH=$(echo -n '${{ inputs.endswith }}' | jq -R -s -c 'split(",")')
echo "endswith=${ENDSWITH}" >> ${GITHUB_OUTPUT}
echo "branches: ${BRANCHES}"
echo "endswith: ${ENDSWITH}"
branches:
runs-on: ubuntu-24.04
needs: prepare
continue-on-error: true
strategy:
matrix:
branch: ${{fromJson(needs.prepare.outputs.branches)}}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
- name: Cleanup old builds for `${{ matrix.branch }}`
run: |
gh run list --limit 500 \
--status completed \
--branch ${{ matrix.branch }} \
--json databaseId \
-q ".[].databaseId" \
| xargs -n 1 gh run delete
endswith:
runs-on: ubuntu-24.04
needs: prepare
continue-on-error: true
strategy:
matrix:
endswith: ${{fromJson(needs.prepare.outputs.endswith)}}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
- name: Cleanup old builds ending with `${{ matrix.endswith }}`
run: |
gh run list --limit 500 \
--status completed \
--json databaseId,headBranch \
-q '.[] | select(.headBranch | endswith("${{ matrix.endswith }}")) | .databaseId' \
| xargs -n 1 gh run delete