GitHub Action
Workflow Status Action
v4.1
Latest version
Use this action to trigger events such as notifications or alerts at the end of your workflow. This makes it possible to send catch-all notifications.
status
- Returns eithersuccess
,cancelled
orfailure
.
permissions:
actions: read
Simply add a job to the end of your workflow and list the last job as dependency using needs
. Then add a step within that job including a condition to trigger an event like a Slack notification or similar.
...
notification:
name: Notify
runs-on: ubuntu-latest
needs: [build]
if: always()
steps:
- uses: martialonline/workflow-status@v3
id: check
- run: echo "Workflow failed"
if: steps.check.outputs.status == 'failure'
- run: echo "Workflow was cancelled"
if: steps.check.outputs.status == 'cancelled'
- run: echo "Workflow was successful"
if: steps.check.outputs.status == 'success'
This is a full example using the Workflow Status Action to trigger a Slack notification at the end of the run. The condition is optional, which in this case triggers a Slack nofication for either success
, failure
or cancelled
status.
name: Slack Example
on:
push:
branches:
- master
permissions:
actions: read
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Unit Tests
run: go test ./...
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Build
run: docker build -t example:latest .
notification:
name: Notify
runs-on: ubuntu-latest
needs: [build]
if: always()
steps:
- uses: martialonline/workflow-status@v3
id: check
- uses: 8398a7/action-slack@v3
with:
status: ${{ steps.check.outputs.status }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
The Dockerfile and associated scripts and documentation in this project are released under the MIT.