Skip to content

Notification Poller #16

Notification Poller

Notification Poller #16

Workflow file for this run

name: Notification Poller
# Polls the GitHub notifications API every 15 minutes for unread CI failure
# notifications. When any are found, triggers resolve-failures.yml immediately
# rather than waiting for its daily 07:30 UTC schedule.
#
# This workflow itself is intentionally minimal — no checkout, no scripts,
# just a single API call. All the actual fix logic lives in resolve-failures.
#
# Concurrency: if a resolve-failures run is already in progress (cancel-in-
# progress: false), the triggered run will queue behind it automatically.
on:
schedule:
- cron: '*/15 * * * *' # Every 15 minutes
workflow_dispatch: {}
permissions:
actions: write # Needed to trigger workflow_dispatch on resolve-failures.yml
# ── Rate limits ──────────────────────────────────────────────────────────────
# One GitHub notifications API call every 15 minutes = 4 req/hr, well within
# the 5 000 req/hr primary limit.
# If SYNC_TOKEN is temporarily rate-limited, curl -sf exits non-zero, count
# defaults to 0, and no resolver trigger is sent. The next poll retries
# automatically 15 minutes later.
jobs:
poll:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Check for unread CI failure notifications
id: check
env:
GH_TOKEN: ${{ secrets.SYNC_TOKEN }}
run: |
# grep -c outputs a bare integer with a trailing newline.
# Trim it before writing to GITHUB_OUTPUT — a trailing newline
# causes "Invalid format" and fails the step.
raw=$(curl -sf \
-H "Authorization: token ${GH_TOKEN}" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/notifications?all=false&per_page=50" \
| grep -c '"ci_activity"') || raw=0
count=$(printf '%s' "$raw" | tr -d '[:space:]')
printf 'ci_failure_count=%s\n' "${count}" >> "$GITHUB_OUTPUT"
echo "Unread CI activity notifications: ${count}"
- name: Trigger resolver if failures found
if: ${{ steps.check.outputs.ci_failure_count != '0' }}
env:
GH_TOKEN: ${{ secrets.SYNC_TOKEN }}
run: |
echo "Found ${{ steps.check.outputs.ci_failure_count }} CI notification(s) — triggering resolver..."
curl -sf \
-X POST \
-H "Authorization: token ${GH_TOKEN}" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/${{ github.repository }}/actions/workflows/resolve-failures.yml/dispatches" \
-d '{"ref":"main"}' \
&& echo "Resolver triggered." \
|| echo "Failed to trigger resolver — will retry on next poll."