If you have a team and if there are many people in the team pushing to GitHub then it might be hard sometimes to check the build status of an active project. The slack notification GitHub action will notify the team regarding the build status.
My Workflow
To enable the slack notifications, I searched for the marketplace for one such action and found this:
Slack messages for GitHub Actions workflows, jobs and steps
A simple and flexible Slack integration with GitHub Actions.
Features
-
Advanced users can use a configuration file and Handlebars templates to configure every aspect of the Slack message.
-
In addition to "legacy" attachments, rich messages can be created using layout blocks for flexible message visualisation and interactivity.
Configuration
Environment Variables (env
)
SLACK_WEBHOOK_URL
(required)
Create a Slack Webhook URL using either the Incoming Webhooks App (preferred) or by attaching an incoming webhook to an existing Slack App (beware, channel override not possible when using a Slack App):
env
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
Input Parameters (with
)
status
(required)
The status
must be defined. It can either be the current job status
using:
with:
status: ${{ job.status }}
or a hardcoded custom status such as "starting" or "in progress":
with:
status: in progress
steps
(optional)
The individual status of jobโฆ
I used this action in my django project by adding some lines of code in .github/workflows/django.yml
.
name: Django CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.6]
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
steps:
- uses: act10ns/slack@v1
with:
status: starting
channel: '#build-notifications'
if: always()
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run Tests
run: |
python manage.py test shop -v 2
- name: Slack Notification
uses: act10ns/slack@v1
with:
status: ${{ job.status }}
steps: ${{ toJson(steps) }}
channel: '#build-notifications'
if: always()
This is my .yml
workflow file. You can add these lines to your workflow file and get the job done.
Observe that I have used act10ns/slack@v1
which is the github action responsible for all this.
Here secret is similar to an environment variable that can be added by going to settings > secrets >
. Add key as SLACK_WEBHOOK_URL
and pair as a webhook URL that can be obtained from Incoming Webhooks App to generate slack messages
Submission Category:
DIY Deployments
Yaml File
Link to Code
revanth-reddy / Raitubazaar
Platform between fruits&vegetable vendors(farmers) and end-users
RaituBazaar
Follow me @Additional Resources
Slack GitHub Actions
Slack GitHub Actions Repo
PS: I have implemented the Slack Notification GitHub Action in one of my existing projects. You can add it to your existing projects too.
Keep Exploring !!!
Top comments (0)