id: github-actions-flaky-workflow-triage
namespace: company.team
description: |
Scan GitHub Actions repositories for failed and flaky workflow runs,
identify repeat offenders, and post a triage digest to Slack.
triggers:
- id: weekday_mornings
type: io.kestra.plugin.core.trigger.Schedule
description: Triage CI health every weekday morning
cron: "0 8 * * 1-5"
- id: on_demand_webhook
type: io.kestra.plugin.core.trigger.Webhook
description: On-demand CI triage after a bad merge
key: "{{ secret('WEBHOOK_KEY') }}"
inputs:
- id: repositories
type: ARRAY
itemType: STRING
displayName: Repositories to scan
description: Full repo names (owner/repo) scanned for workflow failures
defaults:
- "kestra-io/kestra"
- id: lookback_hours
type: INT
displayName: Lookback window (hours)
description: Only consider workflow runs created within this window
defaults: 24
- id: fail_threshold
type: INT
displayName: Failure threshold
description: Alert when a workflow has at least this many failures in window
defaults: 2
tasks:
- id: scan_repositories
type: io.kestra.plugin.core.flow.Loop
description: Fan out GitHub Actions scans across repositories
values: "{{ inputs.repositories }}"
concurrencyLimit: 3
tasks:
- id: fetch_runs
type: io.kestra.plugin.core.http.Request
description: Fetch recent workflow runs via GitHub REST API
uri: "https://api.github.com/repos/{{ item.value }}/actions/runs?per_page=50"
method: GET
headers:
Accept: application/vnd.github+json
Authorization: "Bearer {{ secret('GITHUB_TOKEN') }}"
- id: triage_runs
type: io.kestra.plugin.scripts.python.Script
description: Flag failed runs and repeat-offender workflows in window
containerImage: python:3.11
dependencies:
- kestra
inputFiles:
runs.json: "{{ outputs.fetch_runs.body }}"
script: |
import json
from datetime import datetime, timedelta, timezone
from kestra import Kestra
repo = """{{ item.value }}"""
lookback = {{ inputs.lookback_hours }}
threshold = {{ inputs.fail_threshold }}
cutoff = datetime.now(timezone.utc) - timedelta(hours=lookback)
with open("runs.json") as f:
payload = json.load(f)
failures = []
by_workflow = {}
for run in payload.get("workflow_runs", []):
created = run.get("created_at", "")
try:
ts = datetime.fromisoformat(created.replace("Z", "+00:00"))
except Exception:
continue
if ts < cutoff:
continue
name = run.get("name", "unknown")
conclusion = run.get("conclusion", "")
if conclusion in ("failure", "timed_out", "cancelled"):
failures.append({"workflow": name, "branch": run.get("head_branch"), "url": run.get("html_url"), "conclusion": conclusion})
by_workflow[name] = by_workflow.get(name, 0) + 1
offenders = {k: v for k, v in by_workflow.items() if v >= threshold}
Kestra.outputs({
"repo": repo,
"failures": failures[:10],
"failure_count": len(failures),
"offenders": offenders,
"breached": len(offenders) > 0,
})
- id: alert_on_offenders
type: io.kestra.plugin.core.flow.If
description: Notify Slack when a workflow is a repeat offender
condition: "{{ outputs.triage_runs.vars.breached }}"
then:
- id: notify_slack
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Post flaky-workflow digest with run links
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
messageText: |
:rotating_light: *Flaky CI Alert*, `{{ item.value }}`
{{ outputs.triage_runs.vars.failure_count }} failure(s) in last {{ inputs.lookback_hours }}h.
Repeat offenders: {{ outputs.triage_runs.vars.offenders }}
Latest: {% for f in outputs.triage_runs.vars.failures %}<{{ f.url }}|{{ f.workflow }} ({{ f.branch }})> {% endfor %}
Execution: `{{ execution.id }}`
- id: emit_ci_metrics
type: io.kestra.plugin.core.output.OutputValues
description: Export CI scan coverage for history
values:
repos_scanned: "{{ inputs.repositories | length }}"
lookback_hours: "{{ inputs.lookback_hours }}"
scanned_at: "{{ now() }}"
errors:
- id: alert_on_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Alert on-call if the CI scan itself fails
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
messageText: |
:warning: *CI Triage FAILED*
Flow: `{{ flow.id }}` execution `{{ execution.id }}`
Check GITHUB_TOKEN scopes and API rate limits.