Skip to content

Slack Notification for Offline Runners #163

Slack Notification for Offline Runners

Slack Notification for Offline Runners #163

name: Slack Notification for Offline Runners
on:
schedule:
- cron: "0 9-18/3 * * *" # Runs every 10 minutes
workflow_dispatch: # Allows manual triggering
jobs:
monitor-runners:
runs-on: ubuntu-24.04
steps:
- name: Set up GitHub CLI
run: |
echo "${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}" | gh auth login --with-token
- name: Check Runner Status
id: check-runner
run: |
STATUS=$(gh api repos/YoYoGames/GM-TestFramework/actions/runners --jq '.runners[] | select(.status != "online") | .name' | paste -sd ',' -)
if [[ -n "$STATUS" ]]; then
echo "Offline runners detected: $STATUS"
echo "RUNNER_OFFLINE=true" >> $GITHUB_ENV
echo "OFFLINE_RUNNERS=$STATUS" >> $GITHUB_ENV
else
echo "All runners are online."
echo "RUNNER_OFFLINE=false" >> $GITHUB_ENV
fi
- name: Notify Slack (if runners restarted)
if: ${{ env.RUNNER_OFFLINE == 'true' }}
uses: rtCamp/action-slack-notify@v2
env:
SLACK_CHANNEL: gmtestframework-pipeline
SLACK_COLOR: ${{ job.status }}
SLACK_ICON: https://github.com/black.png?size=48
SLACK_MESSAGE: "🚨 *Runner Offline Alert!* 🚨The following runners are offline:${{ env.OFFLINE_RUNNERS }} Repository: GM-TestFramework"
SLACK_TITLE: Notification for Runners
SLACK_USERNAME: ${{ github.actor }}
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}