Slack Notification for Offline Runners #104
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: 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: Check Offline Runners | |
id: check_runners | |
run: | | |
echo "Checking for offline runners..." | |
# Get the list of runners for the specific repository | |
RESPONSE=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/YoYoGames/GM-TF/actions/runners || echo '{"runners":[]}') | |
echo "Raw API response: $RESPONSE" | |
# Check if the response contains any runners | |
RUNNERS_COUNT=$(echo "$RESPONSE" | jq '.runners | length') | |
if [ "$RUNNERS_COUNT" -eq 0 ]; then | |
echo "No runners found." | |
echo "offline_runners=" >> $GITHUB_ENV | |
else | |
# Look for offline runners | |
OFFLINE_RUNNERS=$(echo "$RESPONSE" | jq -r '.runners[] | select(.status != "online") | .name') | |
if [ -z "$OFFLINE_RUNNERS" ]; then | |
echo "No offline runners detected." | |
echo "offline_runners=" >> $GITHUB_ENV | |
else | |
echo "Offline runners detected: $OFFLINE_RUNNERS" | |
echo "offline_runners=$OFFLINE_RUNNERS" >> $GITHUB_ENV | |
fi | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} | |
- name: Notify Slack (if runners restarted) | |
if: steps.check_runners.outputs.offline_runners != '' | |
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: 'Runners are offline......' | |
SLACK_TITLE: Notification for Runers | |
SLACK_USERNAME: ${{ github.actor }} | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} | |