Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 29, 2021 07:15 pm GMT

Performing code checks with GitHub actions & sending results to slack

What is a GitHub Action ?

A GitHub action is an element of your custom workflow that is triggered when a push or pull request is created and performs some action such as checking code, sending a message or deploying the application.

The most important concept of GitHub actions is their composability. You can assemble actions as building blocks and build a workflow that matches your needs.

In this article we would like to explore how we can put certain actions together and perform different steps based on outcome.

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

on: pull_requestjobs:  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

Next we want to get a notification on slack if these checks passed or failed.

We will use PingMe Action to send these 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
  • Passed
    Alt Text

  • Failed
    Alt Text

You can see this workflow in action here.

GitHub logo kha7iq / pingme

PingMe is a CLI tool which provides the ability to send messages or alerts to multiple messaging platforms & email.


PingMe CLI

Release Go Report Card Build GitHub issues License Go Version Go Dev Reference

Documentation Supported Services Install Github Action Configuration Contributing Show Your Support

About

PingMe is a personal project to satisfy my needs of having alerts, most major platforms have integration to send alertsbut its not always useful, either you are stuck with one particular platform, or you have to do alot of integrations. I needed a small appwhich i can just call from my backup scripts, cron jobs, CI/CD pipelines or from anywhere to send a message with particular informationAnd i can ship it everywhere with ease.Hence, the birth of PingMe.

Everything is configurable via environment variables, and you can simply export the logs or messages to a variable which will be sentas message, and most of all this serves as a swiss army knife sort of tool which supports multiple platforms.

Supported services

  • Discord
  • Email
  • Microsoft Teams

Original Link: https://dev.to/kha7iq/performing-code-checks-with-github-actions-sending-results-to-slack-m6l

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To