Skip to content

This composite action keep tracks and retrieve previous workflows status for the same workflow and determines if a notification should be sent according to success/failure.

License

Notifications You must be signed in to change notification settings

fabiobo2005/workflow-status-notification-action

 
 

Repository files navigation

Workflow Status Slack Notification Action

Github action that keeps track and retrieves previous workflow runs status for the same workflow on the same branch. According to current and previous runs status, it will send a notification to a Slack channel using an Incoming webhook app.

How it works

At the end of a workflow, on success() and on failure(), call this action with the current status as a parameter (success/failure). This action will first check the previous workflow status and will send a Slack notification according to the current workflow status. Status is retrieved from cache if the current workflow has already run previously (from re-run all jobs button for example). If it's the first time this workflow runs, this action will retrieve previous workflow status on the same branch with gh cli using provided github-token.

It'll compare last/current workflow status and will send a notification to Slack if:

  • Current status is failure and it's the first time this workflow runs for the current branch.
  • Current status is failure and previous run status was success.
  • Current status is success and previous run status was failure.

It'll not send a notification to Slack if:

  • Current status is success and previous run status was success.
  • Current status is success and it's the first run.
  • Current status is failure and previous run status was failure.

Notes

You need to define this secret: YOUR_SLACK_WEBHOOK: Webhook URL from Slack Incoming Webhook application

Usage

- uses: reside-eng/workflow-status-notification-action@v1
  with:
    # Status of the current run
    #
    # Default: failure
    # Required: true
    current-status: ''

    # Webhook URL with token for notifications
    #
    # Required: true
    slack-webhook: ''

    # Status of the current run
    #
    # Required: true
    github-token: ''

Examples

Basic

name: Build

on:
  pull_request:
    branches:
      - main

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

      # Your steps...

  success-notification:
    if: success()
    name: success-notification
    needs: [build]
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/[email protected]

      - uses: reside-eng/[email protected]
        with:
          current-status: "success"
          slack-webhook: "${{ secrets.YOUR_SLACK_WEBHOOK }}"
          github-token: "${{ secrets.GITHUB_TOKEN }}"

  failure-notification:
    if: failure()
    name: failure-notification
    needs: [build]
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/[email protected]

      - uses: reside-eng/[email protected]
        with:
          current-status: "failure"
          slack-webhook: "${{ secrets.YOUR_SLACK_WEBHOOK }}"
          github-token: "${{ secrets.GITHUB_TOKEN }}"

Local development

Please install gh CLI: https://github.com/cli/cli#installation

In order to run the jest tests, you'll need to configure authentication using your gh CLI:

gh auth refresh

You'll be prompted with a one-time code, copy this one. Then click on enter, a web page will open in your browser. Paste the code previously copied. Click on Authorize github You're all set !

License

The scripts and documentation in this project are released under the MIT License.

About

This composite action keep tracks and retrieve previous workflows status for the same workflow and determines if a notification should be sent according to success/failure.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 95.1%
  • JavaScript 4.3%
  • Shell 0.6%