PullNotifier Logo
Published on

How to create reusable Github Actions in 2025 (with Slack notify workflow example)

Authors

How to create reusable Github Actions in 2025 (with Slack notify workflow example)

GitHub has introduced reusable workflows, making our coding lives easier. But why should we use them? It's simple: reusable workflows allow multiple repositories to share the same GitHub action, making it easier to manage everything in one place.

In this blog post, we'll walk you through how to set this up!

As an example, we'll create a Github action that sends pull request notifications to Slack.

Bonus: Stick around until the end for a bonus app that will enhance your development workflow ✨

Let's get started

First of all, let's list down all the steps we need to make this work.

  1. Create a repository for all shared Gtihub Action
  2. Reference the shared Github Action on another repository
  3. Configure an internal Slack Bot, copy the token and set it as a Github Secret
  4. Test the setup

1. Create a repository for all shared Github Actions

  • On your Github org, create a new repository called github-actions (or whatever you want).
  • On this new repository, create the file: .github/workflows/slack_notify_pull_request.yml
    • The .github/workflows/ path allows Github to recognize that this is a Github action.
    • On the slack_notify_pull_request.yml file, add the contents below:
name: PR Slack Notification

on:
  workflow_call:

jobs:
  slack-notify:
    name: Slack Notify
    runs-on: ubuntu-latest
    timeout-minutes: 2
    steps:
      - name: PR Slack Notification
        run: |
          PR_LINK="https://github.com/your-org-here/$REPO_NAME/pull/$PR_NUMBER"
          SUBJECT="New Pull Request on \`$REPO_NAME\`"
          BODY="[<$PR_LINK|#${PR_NUMBER}>] \`$PR_TITLE\` (*$USER_NAME*)"
          MESSAGE="{
            \"attachments\": [
              {
                \"title\": \"$SUBJECT\",
                \"text\": \"$BODY\"
              }
            ]
          }"
          echo $MESSAGE
          curl -X POST -H "Content-type: application/json" --data "$MESSAGE" $WEBHOOK
        shell: bash
        env:
          BRANCH_NAME: ${{ github.head_ref }}
          PR_NUMBER: ${{ github.event.number }}
          REPO_NAME: ${{ github.event.repository.name }}
          USER_NAME: ${{ github.actor }}
          PR_TITLE: ${{ github.event.pull_request.title }}
          WEBHOOK: ${{ secrets.SLACK_WEBHOOK_DEVELOPMENT }}
          REVIEWERS: ${{ join(github.event.pull_request.requested_reviewers, ', ') }}
  • That's it for now! This file is basically a Github Action that gets triggered on workflow_call, this means it gets triggered whenever you reference this on another Github Action
  • Tip: think of this as a reusable function. The context of the file here is set to whatever repo is calling it. So the variable ${{ github.event.repository.name }} above is referencing the Repository that actually uses this Reusable Github Action.
  • Important note: make sure to substitude the your-org-here above to your actual org's name

2. Reference the shared Github Action on another repository

  • So we've already addded a reusable workflow, time to to actually use that!
  • Go to the Github repository of your choice (where you want this Github Action to run).
  • Create the file: .github/workflows/slack_notify.yml
    • The .github/workflows/ path allows Github to recognize that this is a Github action.
    • On the slack_notify_pull_request.yml file, add the contents below:
name: PR Slack Notification

on:
  pull_request:
    types: [review_requested]

jobs:
  notify:
    uses: your-org-here/github-actions/.github/workflows/slack_notify_pull_request.yml@main
    secrets: inherit
  • Important note: make sure to substitude the your-org-here above to your actual org's name
  • And that's all! You're basically using the
  • The secrets: inherit part is important here because If we don't add this line, the reusable action will not have access to the secrets variable.

3. Create an Internal Slack app.

Slack makes it very easy for us to create "bots" or Slack apps that make our lives easier.

  • All you need to do is go to this link: https://api.slack.com/apps/ .You need to be logged in your Slack account in order to account is.

    • Click on Create New App → A popup should show up
    • On the popup
      • Add your app's name e.g. "PR Bot"
      • Choose your slack workspace
      • Click on Create App
    • Once the app is created, clicko Incoming Webhooks on the Sidebar
    • Click on the toggle to activate Incoming Webhooks
    • After that, you will be able to Add new Webhook to Workspace
    • After you've chosen a target Slack channel. Copy the webhook URL and save it for later :)
  • Once we have the webhook URL - we're going to add it as a Github Secret so that our Github action can reference it.

  • Go to your repository on the Github site. The URL would look something like: github.com/{org_name}/{repo_name}

  • Go the the Settings page

  • On the security section, go to Secrets and variables and go to Actions

  • Click on New repository secret

  • Add the following details:

    • Name: SLACK_WEBHOOK_DEVELOPMENT
    • Value: Input the Webhook URL that we got from step 1 above
  • Click on *Add secret**

One more additional thing: Go to your Slack workspace - and on the slack channel you're targetting, make sure that you've invited the app to that channel. You can do so by typing /invite and you should be shown a list of apps.

✨ And that should do it!

4. Test the setup

  • Now comes the easy part - testing the setup!
  • Go to your repository and create a new pull request
  • ✨ And that should do it! Enjoy the sweet sweet ding from those Slack notifications 😁

Bonus section ⭐️:

You can skip all of the steps above and just install this free Slack app called PullNotifier.

All you need to do is:

  1. Install it in the Slack app marketplace on the Slack UI or just log in through their website directly.
  2. Connect Github & Slack
  3. And boom 💥! You now have slack notifications for all pull requests on ALL of your repos.

The cool thing is you can also configure different Slack channels for each repository you have (very useful for large teams).

Here's a video on what PullNotifier does:

  That's it for today! Hope you found the content here useful ❤️