-
-
Notifications
You must be signed in to change notification settings - Fork 0
95 lines (82 loc) · 2.74 KB
/
cleanup-runs.yml
File metadata and controls
95 lines (82 loc) · 2.74 KB
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
91
92
93
94
95
name: Cleanup Runs
on:
workflow_call:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
permissions:
contents: write
actions: write
jobs:
cleanup-runs:
name: Delete all workflow runs for ${{ matrix.workflow_file }}
runs-on: ubuntu-latest
strategy:
matrix:
workflow_file:
- trigger.yml
- bump-all.yml
- bump-needed.yml
- cleanup-runs.yml
- clear-caches.yml
steps:
- uses: actions/checkout@v4
- name: Delete all workflow runs for ${{ matrix.workflow_file }}
continue-on-error: true
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
run: |
# Get workflow ID by filename
workflow_id=$(gh api \
-H "Accept: application/vnd.github+json" \
"/repos/$REPO/actions/workflows/${{ matrix.workflow_file }}" \
--jq .id)
echo "Workflow ID: $workflow_id"
# Get all run IDs for the workflow
run_ids=$(gh api \
-H "Accept: application/vnd.github+json" \
"/repos/$REPO/actions/workflows/$workflow_id/runs?per_page=100" \
--jq '.workflow_runs[].id')
for run_id in $run_ids; do
echo "Deleting run $run_id"
gh run delete "$run_id" || true
done
cleanup-bump-runs:
name: Delete cancelled, skipped, or timed out runs for bump.yml
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Delete runs
continue-on-error: true
env:
GH_TOKEN: ${{ github.token }}
run: |
gh run list\
--limit 9999 \
--workflow bump.yml \
--json status,databaseId,conclusion |
jq -r '.[] | select(.conclusion == "cancelled" or .conclusion == "skipped" or .conclusion == "timed_out") | .databaseId' |
while read run_id; do
echo "Deleting run $run_id"
gh run delete "$run_id" || true
done
cleanup-update-yaml-runs:
name: Delete successful, cancelled, skipped, or timed out runs for update-yaml.yml
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Delete runs
continue-on-error: true
env:
GH_TOKEN: ${{ github.token }}
run: |
gh run list\
--limit 9999 \
--workflow update-yaml.yml \
--json status,databaseId,conclusion |
jq -r '.[] | select(.conclusion == "success" or .conclusion == "cancelled" or .conclusion == "skipped" or .conclusion == "timed_out") | .databaseId' |
while read run_id; do
echo "Deleting run $run_id"
gh run delete "$run_id" || true
done