How to Integrate GitHub with Slack (rtcamp/action-slack-notify@v2 webhook)

shaked-askayo
shaked-askayo

When it comes to developer productivity, both GitHub Actions and Slack are very important tools. GitHub Actions is a popular choice as a software pipeline service while Slack is an almost ubiquitous collaboration tool used by many of the same teams that use GitHub Actions. 

However, one challenge developers face is the constant context switching between GitHub and Slack, which can hinder developer productivity. In this post, we look at how to integrate these two services for a unified, smoother developer experience.

Why integrate GitHub Actions & Slack

By integrating GitHub Actions and Slack, your teams gain immediate visibility into every change made to the software delivery pipeline. The idea behind integrating these two platforms is that whenever a GitHub Action is initiated you get a notification in Slack. This is useful to keep an eye on changes to your clusters, to leverage Slack’s powerful search capabilities to triage issues, and to collaborate around releases. Now, let’s look at how to set up this integration.

Steps to integrate GitHub Actions & Slack

We'll be using the Slack Notify action created by rtCamp for this tutorial. There are other options available, but this is a quick and easy way to get the job done.

A. Identify/create your GitHub Actions file in GitHub

1. Create a repository, or identify the repository you’d like to integrate with Slack.

2. Create .github/workflows directory in the repo.

3. In this repository, create your GitHub Actions YAML file and paste the following code into it:

name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions
on: [push]
jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v3
- run: echo "The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "This job's status is ${{ job.status }}."

4. Make sure to merge the changes after creating the file. More detailed instructions for this section are available in the GitHub Docs.

B. Create Slack-webhook file in GitHub

1. In the same ‘workflows’ directory in GitHub, create a new file titled ‘slack-notify.yml’, and add the following code to it:

on: push
name: Slack Notification Demo
jobs:
slackNotification:
name: Slack Notification
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}

2. Merge the changes. You can find more detailed steps for this part here.

You’ll notice that the last field in the script above requires a webhook. Let’s create it next.

C. Create an incoming webhook URL in Slack

For this step, we’ll be using the ‘Incoming WebHooks’ app that was created by Slack.

1. Sign into your Slack account, and click the ‘Add to Slack’ button to add the app to your Slack Workspace

Sign in to Slack's Incoming WebHooks app.

 

2. On the next page, select which Slack channel you’d like to send the notifications to, and click ‘Add Incoming WebHooks Integration.’

3. You’ll see a page with a list of options to customize the webhook’s payload and more. Once you’ve made any customizations, click ‘Save changes’ at the bottom of the page.

4. Now, copy the webhook URL and save it for the next step, to be used in GitHub.

D. Create webhook secret in GitHub

1. Now, head back to your GitHub repository, and click on Settings → Secrets → Actions → ‘New repository secret.’

Create webhook secret in Github

2. In the ‘Name’ field, enter a name for your new webhook, and in the ‘Secret’ field, paste the webhook URL created in the previous section. Then, click ‘Add secret.’

add secret in github

E. Test if the integration works

  • Now, for the last step - testing if the integration works. Go to your Git repository and make any change (it could be as simple as adding a new line or space in one of the files).
  • Merge the change.
  • Now, you should notice an update in Slack that looks like this:
Slack update that indicates integration works.

That’s it! You’ve integrated GitHub Actions with Slack, and will now receive notifications on any changes made in your GitHub repository directly in Slack.

You can customize the contents of this message by going back to section C, step 3. 

Integrate Github Actions and Slack with Kubiya

While the integration described above between GitHub Actions and Slack does the job, there are more powerful options available. 

For example, Kubiya empowers you to use Slack for far more than just notifications and alerts. You can make changes to your Git repository, create and manage resources on cloud providers like AWS, GCP and Azure and much more, all without ever leaving Slack. 

Manage GitHub Actions from Slack using Kubiya

Get started for free with Kubiya today!

shaked-askayo
shaked-askayo

Delegation is the
new Automation

AI teammates that speed up time to automation through a simple conversation.

Onboard a teammate today

Related posts

Learn more about the future of developer and infrastructure operations

Kubiya: The Future of Platform Engineering, Recognized by Gartner

Kubiya AI has been recognized by Gartner as a Cool Vendor in Platform Engineering, highlighting the paradigm shift occurring in the world of platform engineering thanks to AI.

The Kubiya Manifesto

Shift from automation to delegation with AI Teammates in DevOps. Free human talent for innovation and strategic growth by letting AI handle routine tasks, driving efficiency and business success.

The Time-to-Automation Paradox

Simplifying automation with AI Teammates can break the Time-to-Automate Paradox, freeing teams for strategic innovation.