-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.sh
executable file
·65 lines (53 loc) · 1.36 KB
/
start.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
#!/bin/bash
if [ "$RUNNER_ALLOW_RUNASROOT" != "1" ]; then
echo "Error: RUNNER_ALLOW_RUNASROOT is not set to 1."
exit 1
fi
if [ -z "$PAT" ]; then
echo "Error: PAT is not set."
exit 1
fi
if [ -z "$ORG" ]; then
echo "Error: ORG is not set."
exit 1
fi
run() {
token=$(
curl -s -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${PAT}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/orgs/${ORG}/actions/runners/registration-token \
| jq -r .token
)
./config.sh --unattended --url https://github.com/${ORG} --token $token --ephemeral
./run.sh
}
cleanup() {
runner_ids=$(
curl -s -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${PAT}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/orgs/${ORG}/actions/runners \
| jq -r '.runners[].id'
)
runner_len=$(echo "$runner_ids" | wc -l)
echo "Detected $runner_len runners."
if [ $runner_len -ge 2 ]; then
for runner_id in $runner_ids; do
curl -s -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${PAT}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/orgs/${ORG}/actions/runners/${runner_id}
done
echo "Cleaned up $runner_len runners."
fi
}
echo "Trying to cleanup runners..."
cleanup
echo "Starting runner..."
run