2023-05-23 16:41:40 +00:00
|
|
|
#!/bin/sh -e
|
2023-07-27 13:40:53 +00:00
|
|
|
#
|
|
|
|
# Keep only last week worth of CI runs, selected workflows
|
2023-05-23 16:41:40 +00:00
|
|
|
|
|
|
|
type -p gh > /dev/null || { echo "ERROR: gh tool not found"; exit 1; }
|
|
|
|
type -p jq > /dev/null || { echo "ERROR: jq tool not found"; exit 1; }
|
|
|
|
|
|
|
|
repo="kdave/btrfs-progs"
|
|
|
|
|
|
|
|
daysmax=8
|
|
|
|
|
|
|
|
clean_workflow() {
|
|
|
|
local wf="$1"
|
2023-07-27 13:40:53 +00:00
|
|
|
local json=$(gh run -R "$repo" list --workflow "$wf" --json databaseId,startedAt)
|
2023-05-23 16:41:40 +00:00
|
|
|
|
|
|
|
echo "Cleaning workflow $wf"
|
|
|
|
i=0
|
|
|
|
while :; do
|
|
|
|
id=$(echo "$json" | jq -r ".[$i].databaseId")
|
|
|
|
if [ "$id" == "null" -o -z "$id" ]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
echo "ID: $id"
|
|
|
|
now=$(date +%s)
|
|
|
|
date=$(echo "$json" | jq -r ".[$i].startedAt")
|
|
|
|
ts=$(date --date=${date} +%s)
|
|
|
|
delta=$(($now-$ts))
|
|
|
|
days=$(($delta/3600/24))
|
|
|
|
echo "Started at $id, delta $delta, days $days"
|
|
|
|
if [ "$days" -ge "$daysmax" ]; then
|
|
|
|
echo "Delete run $id"
|
|
|
|
gh run -R "$repo" delete "$id"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# loop
|
|
|
|
i=$(($i+1))
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
clean_workflow "Testing CI build"
|
|
|
|
clean_workflow "Devel build and tests"
|