Skip to content

Runner Health Monitor #2146

Runner Health Monitor

Runner Health Monitor #2146

Workflow file for this run

name: Runner Health Monitor
on:
workflow_dispatch:
schedule:
- cron: "*/15 * * * *"
permissions:
actions: read
issues: write
contents: read
jobs:
check-runner:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.RUNNER_PAT || github.token }}
RUNNER_NAME: MyLocalPC
EMAIL_TO: ${{ secrets.EMAIL_TO }}
steps:
- name: Check runner status
id: status
run: |
set -euo pipefail
status=""
if ! status="$(gh api repos/${GITHUB_REPOSITORY}/actions/runners --jq ".runners[] | select(.name==\"${RUNNER_NAME}\") | .status")"; then
status="unknown"
fi
if [ -z "${status}" ]; then
status="not_found"
fi
echo "runner_status=${status}" >> "$GITHUB_OUTPUT"
- name: Notify when offline
if: steps.status.outputs.runner_status != 'online'
run: |
set -euo pipefail
title="Runner offline: ${RUNNER_NAME}"
marker="Autopilot Runner Health"
status="${{ steps.status.outputs.runner_status }}"
gh label create runner-offline --color "B60205" --description "Runner offline alerts" --force --repo "${GITHUB_REPOSITORY}" || true
existing="$(gh issue list -s open -l runner-offline -S "${title}" --repo "${GITHUB_REPOSITORY}" --json number --jq '.[0].number')"
body=$(cat <<EOF
${marker}
Runner: ${RUNNER_NAME}
Status: ${status}
Repo: ${GITHUB_REPOSITORY}
Time: $(date -u +"%Y-%m-%dT%H:%M:%SZ")
Action:
- Verify the runner service on the host
- Restart the service if needed
- Confirm network reachability to GitHub
- If status is "unknown", set RUNNER_PAT with repo/workflow/read:org scopes
EOF
)
if [ -n "${existing}" ]; then
gh issue comment "${existing}" -b "${body}" --repo "${GITHUB_REPOSITORY}"
else
gh issue create -t "${title}" -b "${body}" -l "runner-offline" --repo "${GITHUB_REPOSITORY}"
fi
- name: Email notification
if: steps.status.outputs.runner_status != 'online' && env.SMTP_SERVER != '' && env.EMAIL_TO != ''
uses: dawidd6/action-send-mail@4226df7daafa6fc901a43789c49bf7ab309066e7 # v3
env:
SMTP_SERVER: ${{ secrets.SMTP_SERVER }}
SMTP_PORT: ${{ secrets.SMTP_PORT }}
SMTP_USERNAME: ${{ secrets.SMTP_USERNAME }}
SMTP_PASSWORD: ${{ secrets.SMTP_PASSWORD }}
EMAIL_FROM: ${{ secrets.EMAIL_FROM }}
with:
server_address: ${{ env.SMTP_SERVER }}
server_port: ${{ env.SMTP_PORT }}
username: ${{ env.SMTP_USERNAME }}
password: ${{ env.SMTP_PASSWORD }}
subject: "Runner offline: MyLocalPC"
body: |
Runner: MyLocalPC
Repo: ${{ github.repository }}
Status: ${{ steps.status.outputs.runner_status }}
to: ${{ env.EMAIL_TO }}
from: ${{ env.EMAIL_FROM }}