Skip to content

Commit

Permalink
fixing slack notification
Browse files Browse the repository at this point in the history
  • Loading branch information
ksuchitra532 committed Feb 27, 2025
1 parent def7de3 commit 2c8c2a0
Showing 1 changed file with 20 additions and 30 deletions.
50 changes: 20 additions & 30 deletions .github/workflows/slack-notification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,28 @@ jobs:
monitor-runners:
runs-on: ubuntu-24.04
steps:
- name: Check Offline Runners
id: check_runners
run: |
echo "Checking for offline runners..."
- 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')
# 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 }}
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: steps.check_runners.outputs.offline_runners != ''
uses: rtCamp/action-slack-notify@v2
env:
- 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
Expand Down

0 comments on commit 2c8c2a0

Please sign in to comment.