Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display runners status #16

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions .github/workflows/generate-runners-status.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: "Generate runners status"

on:
push:
# schedule:
# - cron: '0 * * * *' # Run every hour
workflow_dispatch: # Manually triggered via GitHub Actions UI

#concurrency:
# group: redirector
# cancel-in-progress: false

jobs:

Check:

name: "Check permissions"
runs-on: "ubuntu-22.04"
steps:

- name: "Check permissions"
uses: armbian/actions/team-check@main
with:
ORG_MEMBERS: ${{ secrets.ORG_MEMBERS }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TEAM: "Release manager"

build:
name: "Get self hosted runners status"
runs-on: ubuntu-24.04
needs: Check
steps:

- name: "Install dependencies: jq"
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: jq
version: 1.0

- name: "Get runners from ORG"
env:
GH_TOKEN: ${{ secrets.RUNNERS }}
run: |

# get list of self hosted runners
for i in `seq 0 1 10`; do
curl -s -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.RUNNERS }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/orgs/armbian/actions/runners?page=${i} >> runners.json
done

echo "<table>" >> $GITHUB_STEP_SUMMARY
echo "<tr><td>Name</td><td alignt=right>CPU cores</td><td alignt=right>Memory GB</td><td alignt=right>Storage GB</td><td alignt=right>Runners</td></tr>" >> $GITHUB_STEP_SUMMARY
SERVERS=$(curl -s -H "Authorization: Token ${{ secrets.NETBOX_TOKEN }}" -H "Accept: application/json; indent=4" \
"${{ secrets.NETBOX_API }}/virtualization/virtual-machines/?limit=500&name__empty=false&role=userlevel-runner&status=active" \
| jq -r '.results[] | .id')

for s in ${SERVERS}; do
IFS=' ' read -r NAME CPU MEM DISK RUNNERS ID<<< "$(curl -s -H "Authorization: Token ${{ secrets.NETBOX_TOKEN }}" -H "Accept: application/json; indent=4" \
"${{ secrets.NETBOX_API }}/virtualization/virtual-machines/?id=$s" | jq -r '.results[] | .name,.vcpus,.memory,.disk,.custom_fields["runners"],.id' | xargs -n6 -d'\n')"
CALC_MEM=$(echo $MEM | awk '{$1/=1024;printf "%.0f\n",$1}')
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/.*/} $CALC_MEM $DISK $RUNNERS >> $GITHUB_STEP_SUMMARY
unset IFS
echo -e "<tr><td colspan=5>" >> $GITHUB_STEP_SUMMARY
for runner in $(seq -f "%02g" 1 $RUNNERS | sed -e "s/.*/$NAME-&/"); do
INFO=$(cat runners.json | jq -r '.runners[] | select(.name | startswith("'$runner'"))' | jq -r '.name,.status,.busy' | xargs -n3 -d'\n' | sort | uniq)
[[ -n $INFO || ${NAME} == github ]] && echo ":+1:" >> $GITHUB_STEP_SUMMARY || echo ":exclamation: <small>($runner)</small>" >> $GITHUB_STEP_SUMMARY
done
echo -e "</td></tr>" >> $GITHUB_STEP_SUMMARY
done
echo "</table>" >> $GITHUB_STEP_SUMMARY