Use PERSONAL_ACCESS_TOKEN #3
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Collect Uptime from Runners | |
on: | |
push: | |
jobs: | |
get-runners: | |
runs-on: ubuntu-latest | |
outputs: | |
runners: ${{ steps.get-runners.outputs.runners }} | |
steps: | |
- name: Get Self-Hosted Runners | |
id: get-runners | |
run: | | |
echo "Fetching self-hosted runners..." | |
response=$(curl -s -w "%{http_code}" -H "Authorization: Bearer ${{ secrets.PERSONAL_ACCESS_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
"https://api.github.com/repos/${{ github.repository }}/actions/runners") | |
echo "Response: $response" | |
http_status=$(echo "$response" | tail -n1) | |
echo "HTTP Status Code: $http_status" | |
if [ "$http_status" -ne 200 ]; then | |
echo "Failed to fetch runners. Status code: $http_status" | |
exit 1 | |
fi | |
echo "Response Body: $(echo "$response" | head -n -1)" | |
echo "::set-output name=response_body::$(echo "$response" | head -n -1)" | |
- name: Parse Runners with jq | |
id: parse-runners | |
run: | | |
runners=$(echo "${{ steps.fetch-runners.outputs.response_body }}" | jq -r '.runners[] | select(.status=="online") | .name') | |
echo "::set-output name=runners::$(echo $runners | tr '\n' ',')" | |
run-uptime: | |
needs: get-runners | |
runs-on: ${{ matrix.runner }} | |
strategy: | |
matrix: | |
runner: ${{ fromJson(needs.get-runners.outputs.runners) }} | |
steps: | |
- name: Run Uptime Command | |
run: | | |
uptime > uptime.txt | |
echo "Runner: ${{ matrix.runner }}" >> uptime.txt | |
- name: Upload Uptime Artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: uptime-${{ matrix.runner }} | |
path: uptime.txt | |
combine-artifacts: | |
needs: run-uptime | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download Uptime Artifacts | |
uses: actions/download-artifact@v2 | |
with: | |
name: uptime-* | |
path: ./artifacts | |
- name: Combine Artifacts into CSV | |
run: | | |
echo "Runner Name,Uptime" > uptime_report.csv | |
for file in ./artifacts/*; do | |
runner_name=$(basename "$file" | sed 's/^uptime-//') | |
uptime=$(cat "$file") | |
echo "$runner_name,$uptime" >> uptime_report.csv | |
done | |
- name: Upload Combined CSV | |
uses: actions/upload-artifact@v2 | |
with: | |
name: uptime-report | |
path: uptime_report.csv |