GitHub Actions notifications in Slack

05 Sep 2023 in Tech

I recently learned that GitHub can send you reminders on Slack at a regularly scheduled interval. What I didn’t know is that GitHub can also send you notifications on Slack in real-time when events that you’re interested in occur. In my case, that’s when a GitHub Actions build fails.

Ever since GitHub Actions launched, people have been reaching for prebuilt actions (usually Slack Notify) to send updates to Slack. It works great, but there are a couple of downsides to this approach:

  1. You need your Slack admin to generate a webhook URL for you
  2. Notification logic leaks in to your GitHub Actions builds
  3. You can only notify a single channel at a time

In December 2022, GitHub launched support for GitHub Actions workflow notifications in Slack and Microsoft Teams, which allows you to configure Slack as a webhook receiver for GitHub Actions workflow notifications.

Notifications are configured on a per-channel basis using the /github subscribe command in Slack. To get started:

  1. Invite @github to the channel you’d like to receive notifications in
  2. Run /github subscribe owner/repo

Real World Usage

Here’s a real world example that we use to be notified about our scheduled broken links checker, which runs once per week:

/github subscribe Kong/ workflows:{name:"Scheduled Broken Links Checker"}
✅ Subscribed to Kong/ This channel will receive notifications for
issues, pulls, commits, releases, deployments, workflows:{name:"Scheduled Broken Links Checker"}

That’s all! As you can see, you’ll get notifications for issues, pulls, commits (only on the default branch), releases and deployments by default. That’s a bit too much for me, and I unsubscribe from all of these notifications using the following:

/github unsubscribe Kong/ issues pulls commits releases deployments

Now the channel will only receive notifications for the named workflow:

This channel will receive notifications from Kong/ for:
workflows:{name:"Scheduled Broken Links Checker"}

You can filter the notifications by workflow name, the event on which the workflow is triggered, the person that triggered the workflow (useful to review your CEO’s pull requests quickly! 😉), or the branch on which the workflow is running. For a full set of documentation, see the GitHub workflow notification filters docs.

I feed these notifications in to a personal, private channel so that they don’t impact the rest of the team. I couldn’t do that as easily if we were using notify-slack directly in the pipeline.

Pull Request Notifications

Our main use case for the GitHub notifications in Slack is for workflow success/failure, but there is one other trick we use that I’d like to share.

We use labels heavily to categorise pull requests and control CI checks (including making labels required). Here are a couple of filters I use to make sure that I don’t miss anything:

  • /github subscribe Kong/ +label:"review:tech" - Makes sure that I see any docs platform code changes
  • /github subscribe Kong/ +label:"review:sme" - These are usually really interesting docs to read and learn from. If a topic needs SME (subject matter expert) review, there’s something for me to learn.
  • /github subscribe Kong/ +label:"ci:manual-approve:linting" - Alert whenever the linting CI check is skipped. We have multiple manual-approve labels and I subscribe to all of them. You can see how we override workflows manually using labels in the linting workflow.

Give it a go

The GitHub Slack integration is pretty great. Whether you’re looking for GitHub Actions notifications, to be alerted when pull requests have a specific label or just to be reminded about PRs that need your review, I recommend trying them out to see what works for you.