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.
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 wassuccess
. - Current status is
success
and previous run status wasfailure
.
It'll not send a notification to Slack if:
- Current status is
success
and previous run status wassuccess
. - Current status is
success
and it's the first run. - Current status is
failure
and previous run status wasfailure
.
You need to define this secret: YOUR_SLACK_WEBHOOK: Webhook URL from Slack Incoming Webhook application
- 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: ''
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/checkout@v2.3.4
- uses: reside-eng/workflow-status-notification-action@v1.0.7
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/checkout@v2.3.4
- uses: reside-eng/workflow-status-notification-action@v1.0.7
with:
current-status: "failure"
slack-webhook: "${{ secrets.YOUR_SLACK_WEBHOOK }}"
github-token: "${{ secrets.GITHUB_TOKEN }}"
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 !
The scripts and documentation in this project are released under the MIT License.