Skip to content

Commit 6df84b5

Browse files
mathieudimdimajo
andauthored
feat: add on-failure-and-recovery notification type (#941)
Co-authored-by: mdimajo <[email protected]>
1 parent 935c17d commit 6df84b5

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
## How it works
77

88
At the end of a workflow, on success() and on failure(), call this action with the current status as a parameter (success/failure).
9+
10+
### If notification-type = release
11+
12+
This action will send a release notification with the current status (success or failure) whatever the current and previous workflow status.
13+
14+
### If notification-type = on-state-change
15+
916
This action will first check the previous workflow status and will send a Slack notification according to the current workflow status.
1017
Status is retrieved from cache if the current workflow has already run previously (from `re-run all jobs` button for example).
1118
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`.
@@ -22,6 +29,10 @@ It'll not send a notification to Slack if:
2229
- Current status is `success` and it's the first run.
2330
- Current status is `failure` and previous run status was `failure`.
2431

32+
### If notification-type = on-failure-and-recover
33+
34+
Same as on-state-change but will notify on each failure (so will also notify when current status is `failure` and previous run status was `failure`).
35+
2536
## Notes
2637

2738
You need to define this secret:
@@ -46,7 +57,7 @@ YOUR_SLACK_WEBHOOK: Webhook URL from Slack Incoming Webhook application
4657
# Required: true
4758
slack-webhook: ''
4859

49-
# Type of notification (on-state-change, release)
60+
# Type of notification (on-state-change, on-failure-and-recovery, release)
5061
#
5162
# Default: on-state-change
5263
notify-type: ''

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ inputs:
1010
required: true
1111
default: ''
1212
notify-type:
13-
description: 'Type of notification (on-state-change, release)'
13+
description: 'Type of notification (on-state-change, on-failure-and-recovery, release)'
1414
required: false
1515
default: 'on-state-change'
1616
github-token:

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async function pipeline(): Promise<void> {
6565
await sendSlackMessage(webhookUrl, message);
6666
} else if (
6767
currentStatus === 'failure' &&
68-
(lastStatus === 'completed/success' || lastStatus === '')
68+
(lastStatus === 'completed/success' || lastStatus === '' || notifyType === 'on-failure-and-recovery')
6969
) {
7070
core.info(`Failure notification`);
7171
const message = await prepareSlackNotification(

0 commit comments

Comments
 (0)