-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckStatus.sh
executable file
·38 lines (31 loc) · 1.05 KB
/
CheckStatus.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
#!/bin/bash
STATUSES=()
RUNNER_STATUS=()
function check_status(){
RUNNER_NAME=$1
RESPONSE=$(curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_RUNNER_TOKEN}" \
-H "X-GitHub-Api-Version: ${GITHUB_API_VERSION}" \
https://api.github.com/orgs/${ORG_NAME}/actions/runners)
RUNNERS=$(echo "${RESPONSE}" | jq -r '.runners')
if [ "${RUNNERS}" = "null" ]; then
echo "Problem with the token"
exit 1
return
fi
STATUS=$(echo "${RESPONSE}" | jq -r ".runners[] | select(.name == \"${RUNNER_NAME}\") | .status")
echo "${RUNNER_NAME^^} IS ${STATUS^^}"
if [ "${STATUS}" = "offline" ]; then
RUNNER_STATUS+=("${RUNNER_NAME^^} IS ${STATUS^^},\n")
fi
STATUSES+=("${STATUS^^}")
}
runners=( ${RUNNER_NAMES} )
for runner in "${runners[@]}"
do
check_status "${runner}"
done
# These outputs are used in other steps/jobs via action.yml
echo "status=${STATUSES[@]}" >> $GITHUB_OUTPUT
echo "each_runner_status=${RUNNER_STATUS[@]}" >> $GITHUB_OUTPUT