-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdelete-workflow-runs.sh
executable file
·70 lines (60 loc) · 1.5 KB
/
delete-workflow-runs.sh
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
#!/bin/bash
# Name: Delete Workflow Runs
# Author: "John Valai <git@jvk.to>"
# License": "MIT"
# This npm module can be used to easily delete unneeded GitHub Workflow runs
# from your GitHub remote repository. You can select multiple entries to be
# deleted at once easily from a navigable list.
# make script exit when a command fails:
set -o errexit
# if any element of the pipeline fails, then the pipeline as a whole will fail:
set -o pipefail
# Use supplied repo name, otherwise grab from current repo folder
get_repo_name() {
[ "$#" -eq 0 ] && repo=$(git remote show origin -n | grep h.URL | sed 's/.*://;s/.git$//') || repo=$1
}
jqscript() {
cat <<EOF
def symbol:
sub("skipped"; "SKIP") |
sub("success"; "GOOD") |
sub("failure"; "FAIL");
def tz:
gsub("[TZ]"; " ");
.workflow_runs[]
| [
(.conclusion | symbol),
(.created_at | tz),
.id,
.event,
.name
]
| @tsv
EOF
}
select_runs() {
gh api --paginate "/repos/$repo/actions/runs" \
| jq -r -f <(jqscript) \
| fzf --multi
}
delete_run() {
local run id result
run=$1
id="$(cut -f 3 <<< "$run")"
gh api -X DELETE "/repos/$repo/actions/runs/$id" --silent \
&& result="Deleted ✅" \
|| result="Failed! ❌"
printf "%s\t%s\n" "$result" "$run"
}
delete_runs() {
local id
while read -r run; do
delete_run "$run"
sleep 0.25
done
}
main() {
get_repo_name $1
select_runs | delete_runs
}
main "$@"