From 3aa6d5a8ac82ab84b33b400d28fc6b21b171a732 Mon Sep 17 00:00:00 2001 From: Igor Pecovnik Date: Mon, 30 Dec 2024 18:48:40 +0100 Subject: [PATCH 1/3] Display runners status --- .github/workflows/generate-runners-status.yml | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 .github/workflows/generate-runners-status.yml diff --git a/.github/workflows/generate-runners-status.yml b/.github/workflows/generate-runners-status.yml new file mode 100644 index 00000000..b856dcf9 --- /dev/null +++ b/.github/workflows/generate-runners-status.yml @@ -0,0 +1,72 @@ +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-24.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 "" >> $GITHUB_STEP_SUMMARY + echo "" >> $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')" + printf "\n" $NAME ${CPU/.*/} $MEM $DISK $RUNNERS >> $GITHUB_STEP_SUMMARY + unset IFS + echo -e "" >> $GITHUB_STEP_SUMMARY + done + echo "
NameCPU coresMemory GBStorage GBRunners
%s%3d%d%d%d
" >> $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 ]] && echo ":+1:" >> $GITHUB_STEP_SUMMARY || echo ":exclamation: ($runner)" >> $GITHUB_STEP_SUMMARY + done + echo -e "
" >> $GITHUB_STEP_SUMMARY \ No newline at end of file From 3c2b833e2de5ddac2cefefcbe5e147549610b481 Mon Sep 17 00:00:00 2001 From: Igor Date: Fri, 3 Jan 2025 19:17:51 +0100 Subject: [PATCH 2/3] Update generate-runners-status.yml --- .github/workflows/generate-runners-status.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/generate-runners-status.yml b/.github/workflows/generate-runners-status.yml index b856dcf9..0834f061 100644 --- a/.github/workflows/generate-runners-status.yml +++ b/.github/workflows/generate-runners-status.yml @@ -60,7 +60,8 @@ jobs: 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')" - printf "%s%3d%d%d%d\n" $NAME ${CPU/.*/} $MEM $DISK $RUNNERS >> $GITHUB_STEP_SUMMARY + CALC_MEM=$(echo $MEM | awk '{$1/=1024;printf "%.0f\n",$1}') + printf "%s%3d%d%d%d\n" $NAME ${CPU/.*/} $CALC_MEM $DISK $RUNNERS >> $GITHUB_STEP_SUMMARY unset IFS echo -e "" >> $GITHUB_STEP_SUMMARY for runner in $(seq -f "%02g" 1 $RUNNERS | sed -e "s/.*/$NAME-&/"); do @@ -69,4 +70,4 @@ jobs: done echo -e "" >> $GITHUB_STEP_SUMMARY done - echo "" >> $GITHUB_STEP_SUMMARY \ No newline at end of file + echo "" >> $GITHUB_STEP_SUMMARY From d58dfe21f3774d7a8a967f4958e31ec800df7614 Mon Sep 17 00:00:00 2001 From: Igor Pecovnik Date: Fri, 3 Jan 2025 19:25:14 +0100 Subject: [PATCH 3/3] Aligns --- .github/workflows/generate-runners-status.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/generate-runners-status.yml b/.github/workflows/generate-runners-status.yml index 0834f061..737ec61f 100644 --- a/.github/workflows/generate-runners-status.yml +++ b/.github/workflows/generate-runners-status.yml @@ -15,7 +15,7 @@ jobs: Check: name: "Check permissions" - runs-on: "ubuntu-24.04" + runs-on: "ubuntu-22.04" steps: - name: "Check permissions" @@ -52,7 +52,7 @@ jobs: done echo "" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY + echo "" >> $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') @@ -66,7 +66,7 @@ jobs: echo -e "" >> $GITHUB_STEP_SUMMARY done
NameCPU coresMemory GBStorage GBRunners
NameCPU coresMemory GBStorage GBRunners
" >> $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 ]] && echo ":+1:" >> $GITHUB_STEP_SUMMARY || echo ":exclamation: ($runner)" >> $GITHUB_STEP_SUMMARY + [[ -n $INFO || ${NAME} == github ]] && echo ":+1:" >> $GITHUB_STEP_SUMMARY || echo ":exclamation: ($runner)" >> $GITHUB_STEP_SUMMARY done echo -e "