Skip to content

Commit cfa2be2

Browse files
committed
added delete-offline-runners.sh script
1 parent d244ad1 commit cfa2be2

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ docker compose up --scale runner=X -d
6666

6767
where `X` is the number of runners.
6868

69+
70+
## Deleting stuck runners
71+
72+
Runners should automatically clean up after themselves once stopped, but if
73+
a SIGKILL occurs, a container may get stuck in the "Offline" state. Should
74+
this happen, run the `./delete-offline-runners.sh` script with the required
75+
arguments.
76+
6977
## Useful commands
7078

7179
* `docker image list` - view a list of built images

delete-offline-runners.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
GITHUB=$1
4+
TARGET=$2
5+
TOKEN=$3
6+
7+
if [[ "$#" -ne 3 ]]; then
8+
echo "Usage: $0 GITHUB_URL TARGET TOKEN"
9+
exit
10+
fi
11+
12+
# test if the target is a repo, prepend /repos for the api
13+
curl --fail --silent -k -X GET -H "Authorization: token ${TOKEN}" -H "Accept: application/vnd.github+json" \
14+
https://api.${GITHUB}/repos/${TARGET} > /dev/null && API_TARGET=repos/${TARGET}
15+
16+
# test if the target is an org, prepend /orgs for the api
17+
curl --fail --silent -k -X GET -H "Authorization: token ${TOKEN}" -H "Accept: application/vnd.github+json" \
18+
https://api.${GITHUB}/orgs/${TARGET} > /dev/null && API_TARGET=orgs/${TARGET}
19+
20+
if [[ -z ${API_TARGET} ]]; then
21+
echo "The target provided (${TARGET}) is neither a repo nor an org, exiting"
22+
exit 1
23+
fi
24+
25+
echo "Removing offline GH actions runners on https://${GITHUB}/${TARGET}..."
26+
27+
RUNNER_LIST=$(curl -H "Authorization: token ${TOKEN}" -H "Accept: application/vnd.github+json" \
28+
https://api.${GITHUB}/${API_TARGET}/actions/runners \
29+
| jq '[.runners[] | select(.status | contains("offline")) | {id: .id}]')
30+
31+
32+
for id in $(echo "$RUNNER_LIST" | jq -r '.[] | @base64'); do
33+
_jq() {
34+
echo ${id} | base64 --decode | jq -r ${1}
35+
}
36+
echo "Deleting $(_jq '.id')"
37+
curl -X DELETE -H "Accept: application/vnd.github+json" \
38+
-H "Authorization: token ${TOKEN}" \
39+
https://api.${GITHUB}/${API_TARGET}/actions/runners/$(_jq '.id')
40+
done

0 commit comments

Comments
 (0)