Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.

Commit ebd4a34

Browse files
committed
automatic update: hooks/gh-clean Makefile
1 parent a59a8fd commit ebd4a34

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
export TOX_SCENARIO ?= default
33
export TOX_ANSIBLE ?= ansible_8.5
44

5-
.PHONY: converge destroy verify test lint
5+
.PHONY: converge destroy verify test lint gh-clean
66

77
default: converge
88

@@ -20,3 +20,6 @@ test:
2020

2121
lint:
2222
@hooks/lint
23+
24+
gh-clean:
25+
@hooks/gh-clean

hooks/gh-clean

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
org=bodsch
6+
repo=$(basename $(git rev-parse --show-toplevel))
7+
8+
keep_first_two() {
9+
local arr=("$@") # Das Array wird als Argument übergeben
10+
local new_arr=("${arr[@]:0:2}") # Die ersten beiden Elemente werden beibehalten
11+
echo "${new_arr[@]}" # Das neue Array wird ausgegeben
12+
}
13+
14+
remove_elements() {
15+
local arr=("$@")
16+
local result=()
17+
local length=${#arr[@]}
18+
19+
# Check whether the array has more than two elements
20+
if [ $length -le 2 ]
21+
then
22+
return
23+
fi
24+
25+
# Keep the first two elements
26+
for ((i=2; i<length; i++))
27+
do
28+
result+=("${arr[i]}") # Collect removed elements
29+
done
30+
31+
echo "${result[@]}"
32+
}
33+
34+
35+
if [ -n "${org}" ] && [ -n "${repo}" ]
36+
then
37+
38+
# Get workflow IDs with status "active"
39+
workflow_ids=($(gh api repos/$org/$repo/actions/workflows --paginate | jq '.workflows[] | select(.["state"] | contains("active")) | .id'))
40+
41+
for workflow_id in "${workflow_ids[@]}"
42+
do
43+
echo "Listing runs for the workflow ID $workflow_id"
44+
run_ids=( $(gh api repos/$org/$repo/actions/workflows/$workflow_id/runs --paginate | jq '.workflow_runs[].id') )
45+
46+
# echo "${run_ids[@]}"
47+
48+
# count array
49+
count_ids=${#run_ids[@]}
50+
# echo " - ${count_ids} entries"
51+
52+
if [ ${count_ids} -gt 2 ]
53+
then
54+
# remove the first two elements of the list
55+
array=$(remove_elements "${run_ids[@]}")
56+
57+
for run_id in ${array}
58+
do
59+
echo "Deleting Run ID $run_id"
60+
gh api repos/$org/$repo/actions/runs/$run_id -X DELETE >/dev/null
61+
done
62+
63+
echo "-------------------------------------------------"
64+
fi
65+
done
66+
else
67+
echo "missing values:"
68+
echo " - org : '${org}'"
69+
echo " - repo: '${repo}'"
70+
71+
exit 1
72+
fi

0 commit comments

Comments
 (0)