Performing code checks with GitHub actions & sending results to slack

What is a GitHub Action ?

Lets create an action which performs linting checks on a new pull request.

on: pull_request

jobs:
lint-code:
runs-on: ubuntu-latest
name: Perform Checks
steps:
- name: Checkout
uses: actions/checkout@v2

- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.29

Sending alerts

on: pull_request

# Get values from github secrets of slack token and target channels and set the variables.
# we can set these within the action block as well for pass/fail.
env:
SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }}
SLACK_CHANNESL: ${{ secrets.SLACK_CHANNELS }}

jobs:
lint-code:
runs-on: ubunut-latest
name: Perform Checks
steps:
- name: Checkout
uses: actions/checkout@v2
# We want to perform checks and see if the code is properly linted.
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.29

- name: Alert when checks fail
uses: kha7iq/pingme-action@v1
# This action will only run if checks failed.
if: failure()
env:
SLACK_MSG_TITLE: '🟢 New Request: ${{ github.ref }}'
SLACK_MESSAGE: 'Event is triggerd by ${{ github.event_name }} Checks ❌ ${{ job.status }}'
with:
service: slack

- name: Alert when checks pass
uses: kha7iq/pingme-action@v1
# This action will only run if checks are successfull.
if: success()
# Message and Title are string values, you can create custome message or title.
env:
SLACK_MSG_TITLE: '🟢 New Request: ${{ github.ref }}'
SLACK_MESSAGE: 'Event is triggerd by ${{ github.event_name }} Checks ✅ ${{ job.status }}'
with:
service: slack
Screenshot passed checks
Screenshot passed checks
screenshot failed tests
screenshot failed tests

You can see this workflow in action here.

kha7iq/pingme

https://github.com/kha7iq/pingme
https://github.com/kha7iq/pingme