Skip to content

Commit 6f99129

Browse files
committed
Display runners status
1 parent bf2aac6 commit 6f99129

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: "Generate runners status"
2+
3+
on:
4+
push:
5+
# schedule:
6+
# - cron: '0 * * * *' # Run every hour
7+
workflow_dispatch: # Manually triggered via GitHub Actions UI
8+
9+
#concurrency:
10+
# group: redirector
11+
# cancel-in-progress: false
12+
13+
jobs:
14+
15+
Check:
16+
17+
name: "Check permissions"
18+
runs-on: "ubuntu-24.04"
19+
steps:
20+
21+
- name: "Check permissions"
22+
uses: armbian/actions/team-check@main
23+
with:
24+
ORG_MEMBERS: ${{ secrets.ORG_MEMBERS }}
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
TEAM: "Release manager"
27+
28+
build:
29+
name: "Get self hosted runners status"
30+
runs-on: ubuntu-24.04
31+
needs: Check
32+
steps:
33+
34+
- name: "Install dependencies: jq"
35+
uses: awalsh128/cache-apt-pkgs-action@latest
36+
with:
37+
packages: jq
38+
version: 1.0
39+
40+
- name: "Get runners from ORG"
41+
env:
42+
GH_TOKEN: ${{ secrets.RUNNERS }}
43+
run: |
44+
45+
# get list of self hosted runners
46+
for i in `seq 0 1 10`; do
47+
curl -s -L \
48+
-H "Accept: application/vnd.github+json" \
49+
-H "Authorization: Bearer ${{ secrets.RUNNERS }}" \
50+
-H "X-GitHub-Api-Version: 2022-11-28" \
51+
https://api.github.com/orgs/armbian/actions/runners?page=${i} >> runners.json
52+
done
53+
54+
echo "<table>" >> $GITHUB_STEP_SUMMARY
55+
echo "<tr><td>Name</td><td>CPU cores</td><td>Memory GB</td><td>Storage GB</td><td alignt=right>Runners</td></tr>" >> $GITHUB_STEP_SUMMARY
56+
SERVERS=$(curl -s -H "Authorization: Token ${{ secrets.NETBOX_TOKEN }}" -H "Accept: application/json; indent=4" \
57+
"${{ secrets.NETBOX_API }}/virtualization/virtual-machines/?limit=500&name__empty=false&role=userlevel-runner&status=active" \
58+
| jq -r '.results[] | .id')
59+
60+
for s in ${SERVERS}; do
61+
IFS=' ' read -r NAME CPU MEM DISK RUNNERS ID<<< "$(curl -s -H "Authorization: Token ${{ secrets.NETBOX_TOKEN }}" -H "Accept: application/json; indent=4" \
62+
"${{ secrets.NETBOX_API }}/virtualization/virtual-machines/?id=$s" | jq -r '.results[] | .name,.vcpus,.memory,.disk,.custom_fields["runners"],.id' | xargs -n6 -d'\n')"
63+
printf "<tr><td>%s</td><td align=right>%3d</td><td align=right>%d</td><td align=right>%d</td><td align=right>%d</td></tr>\n" $NAME ${CPU/.*/} $MEM $DISK $RUNNERS >> $GITHUB_STEP_SUMMARY
64+
unset IFS
65+
echo -e "<tr><td colspan=5>" >> $GITHUB_STEP_SUMMARY
66+
for runner in $(seq -f "%02g" 1 $RUNNERS | sed -e "s/.*/$NAME-&/"); do
67+
INFO=$(cat runners.json | jq -r '.runners[] | select(.name | startswith("'$runner'"))' | jq -r '.name,.status,.busy' | xargs -n3 -d'\n' | sort | uniq)
68+
[[ -n $INFO ]] && echo ":+1:" >> $GITHUB_STEP_SUMMARY || echo ":exclamation: <small>($runner)</small>" >> $GITHUB_STEP_SUMMARY
69+
done
70+
echo -e "</td></tr>" >> $GITHUB_STEP_SUMMARY
71+
done
72+
echo "</table>" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)