Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ trail: the former in-run alert jobs and `nightly-alert-issue.sh` were removed
in favor of this single external check, because an in-run alert dies with its
own run on a startup_failure and can never see a cron that didn't fire.

### Main branch alerting

`main-ci-slack-alerts.yml` watches completed `workflow_run` events for the
current `push` to `main` workflows: Code Style, Tests (Reborn), Reborn E2E,
Platform & Compat, Replay Snapshot Gate, Code Coverage,
nearai-bench dispatcher tests, and Release-plz. Any watched run that concludes
`failure`, `timed_out`, `action_required`, or `startup_failure` posts a Slack
message with the workflow, conclusion, failed job names, commit, actor, and run
link.

Alerts go to `secrets.MAIN_CI_SLACK_WEBHOOK_URLS`; the value may be a single
webhook URL or multiple URLs separated by newlines or commas. This is
intentionally separate from the canary/nightly `SLACK_WEBHOOK_URL` so main CI
alerts can target dedicated channels.
When adding a new workflow that runs on `push` to `main`, add its workflow
`name:` to the watched list in `main-ci-slack-alerts.yml`.

## Known accepted gaps (deliberate, revisit as needed)

- **Windows clippy** (`code_style.yml` `clippy-windows`) runs on push only;
Expand Down
105 changes: 105 additions & 0 deletions .github/workflows/main-ci-slack-alerts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Main CI Slack Alerts

on:
workflow_run:
workflows:
- Code Style
- Tests (Reborn)
- Reborn E2E
- Platform & Compat
- Replay Snapshot Gate
- Code Coverage
- nearai-bench dispatcher tests
- Release-plz
branches:
- main
types:
- completed

permissions:
actions: read
contents: read

jobs:
alert:
name: Post Slack alert
if: >-
github.event.workflow_run.event == 'push' &&
contains(fromJSON('["failure","timed_out","action_required","startup_failure"]'), github.event.workflow_run.conclusion)
runs-on: ubuntu-latest
steps:
- name: Post main CI failure to Slack
env:
GH_TOKEN: ${{ github.token }}
RUN_ID: ${{ github.event.workflow_run.id }}
RUN_URL: ${{ github.event.workflow_run.html_url }}
WORKFLOW_NAME: ${{ github.event.workflow_run.name }}
CONCLUSION: ${{ github.event.workflow_run.conclusion }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
ACTOR: ${{ github.event.workflow_run.actor.login }}
MAIN_CI_SLACK_WEBHOOK_URLS: ${{ secrets.MAIN_CI_SLACK_WEBHOOK_URLS }}

@think-in-universe think-in-universe Jul 9, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAIN_CI_SLACK_WEBHOOK_URLS secret has been configured in the repo.

run: |
set -euo pipefail

short_sha="${HEAD_SHA:0:10}"
failed_jobs="$(gh api "repos/${GITHUB_REPOSITORY}/actions/runs/${RUN_ID}/jobs?per_page=100" \
--jq '[.jobs[] | select(.conclusion == "failure" or .conclusion == "timed_out" or .conclusion == "action_required" or .conclusion == "startup_failure") | "\(.name) (\(.conclusion))"] | .[0:12] | join(", ")' \
2>/dev/null || true)"
if [ -z "$failed_jobs" ]; then
failed_jobs="No failed jobs listed; inspect the workflow run for startup or workflow-level errors."
fi

text="Main branch CI failed: ${WORKFLOW_NAME} concluded ${CONCLUSION} on ${short_sha}"
payload="$(jq -n \
--arg text "$text" \
--arg workflow "$WORKFLOW_NAME" \
--arg conclusion "$CONCLUSION" \
--arg branch "$HEAD_BRANCH" \
--arg sha "$short_sha" \
--arg actor "$ACTOR" \
--arg failed_jobs "$failed_jobs" \
--arg url "$RUN_URL" \
'{
text: $text,
blocks: [
{
type: "header",
text: {type: "plain_text", text: "Main branch CI failed"}
},
{
type: "section",
text: {
type: "mrkdwn",
text: "*Workflow:* \($workflow)\n*Conclusion:* `\($conclusion)`\n*Branch:* `\($branch)`\n*Commit:* `\($sha)`\n*Actor:* `\($actor)`\n*Failed jobs:* \($failed_jobs)\n<\($url)|Open workflow run>"
}
}
]
}')"

webhooks="${MAIN_CI_SLACK_WEBHOOK_URLS:-}"
if [ -z "$webhooks" ]; then
echo "::error::Set MAIN_CI_SLACK_WEBHOOK_URLS to receive main CI failure alerts."
exit 1
fi

webhook_file="$(mktemp)"
trap 'rm -f "$webhook_file"' EXIT
printf '%s\n' "$webhooks" | tr ',' '\n' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//;/^$/d' > "$webhook_file"

posted=0
while IFS= read -r webhook; do
if curl -fsS --max-time 30 -X POST -H 'Content-type: application/json' \
--data "$payload" "$webhook" > /dev/null; then
posted=$((posted + 1))
else
echo "::warning::Failed to post alert to webhook (HTTP error or timeout)."
fi
done < "$webhook_file"
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

if [ "$posted" -eq 0 ]; then
echo "::error::Failed to post alert to any Slack webhook."
exit 1
fi

echo "Posted main CI failure alert to ${posted} Slack webhook(s)."
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
Loading