Skip to content

Add Slack build notification action#432

Merged
bschwedler merged 8 commits into
mainfrom
worktree-slack-build-notify
Apr 9, 2026
Merged

Add Slack build notification action#432
bschwedler merged 8 commits into
mainfrom
worktree-slack-build-notify

Conversation

@bschwedler
Copy link
Copy Markdown
Contributor

@bschwedler bschwedler commented Apr 8, 2026

Summary

Adds a reusable composite action at .github/actions/slack-build-notify/ that sends Slack notifications on build state transitions on main:

  • Failure: notifies when a previously-passing workflow starts failing, with failed job/step details and links
  • Recovery: notifies when a previously-failing workflow recovers, with consecutive failure count

Designed for use in the CI meta-job across product image repos (images-connect, images-package-manager, images-workbench).

Design decisions

  • Uses actions/github-script for pre-authenticated GitHub API access
  • Compares the previous run's CI job conclusion (not workflow conclusion) to avoid false notifications from clean-job flaps
  • Graceful failure: try/catch + continue-on-error in callers so notification issues never block CI
  • Restricted to posit-dev/ repos via github.repository_owner guard
  • Slack Block Kit messages with text fallback for notification previews

Required setup

Each product repo needs a SLACK_WEBHOOK_URL repository secret pointing at the #platform-builds-images channel webhook.

Test plan

  • Add SLACK_WEBHOOK_URL secret to a test repo
  • Trigger a failure on main and verify Slack message appears
  • Trigger a recovery and verify consecutive failure count is correct
  • Verify no notification fires when state doesn't change
  • Verify no notification fires on PR branches

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 8, 2026

Test Results

1 268 tests  ±0   1 268 ✅ ±0   9m 3s ⏱️ +20s
    1 suites ±0       0 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit caebe93. ± Comparison against base commit 9e8e2db.

♻️ This comment has been updated with latest results.

Composite action that sends Slack notifications on build state
transitions on main. Detects when a previously-passing workflow
starts failing, and when a previously-failing workflow recovers.

- Queries GitHub API for previous workflow run conclusions
- Skips cancelled runs when determining state transitions
- Failure messages include failed job/step names with links
- Recovery messages include consecutive failure count and date
- Uses Slack Block Kit for structured messages
- Wrap entire script in try/catch, warning on error
- Add text fallback to Slack payload for notification previews
- Handle empty failure details with informative fallback
- Increase job listing page size to 100 for large matrices
- Add github.repository_owner == 'posit-dev' guard so the
  notification only fires in posit-dev repos
- Document the state comparison mismatch between alls-green
  (build-only) and workflow conclusion (all jobs including clean)
Query the previous run's jobs and compare the CI meta-job's
conclusion instead of the workflow-level conclusion. This
prevents clean-job flaps from triggering false recovery
notifications. Falls back to workflow conclusion if no CI
job is found.
Sanitize &, <, > in commit message text before inserting
into Slack Block Kit mrkdwn to prevent injection of
mentions like <!here> or formatting breakage.
Show at most 5 failed jobs with an "… and N more" summary
when there are many failures (e.g. content image matrix).
Include total failed job count in the header line.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new reusable composite GitHub Action to post Slack notifications when CI transitions between passing and failing states, intended for use by image repos’ CI meta-job on main.

Changes:

  • Introduces .github/actions/slack-build-notify/ composite action using actions/github-script to compare current vs previous run state.
  • Sends Slack Block Kit messages for “failure” (with failed job/step details) and “recovery” (with consecutive failure count).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/actions/slack-build-notify/action.yml
Comment thread .github/actions/slack-build-notify/action.yml
Comment thread .github/actions/slack-build-notify/action.yml Outdated
Comment thread .github/actions/slack-build-notify/action.yml Outdated
Comment thread .github/actions/slack-build-notify/action.yml Outdated
Copy link
Copy Markdown
Contributor

@ianpittwood ianpittwood left a comment

Choose a reason for hiding this comment

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

LGTM but some of the Copilot feedback may be actionable

Include timed_out and action_required conclusions in the
failed job list, not just failure. A timed-out job would
otherwise show "No individual job failures identified."
Extract previousConclusion variable so the log message
reflects the CI job conclusion when available, matching
the value actually used for state transition comparison.
@bschwedler bschwedler added this pull request to the merge queue Apr 9, 2026
Merged via the queue into main with commit b515c94 Apr 9, 2026
16 checks passed
@bschwedler bschwedler deleted the worktree-slack-build-notify branch April 9, 2026 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants