1- # Notify Slack on Failure Action
1+ # Notify Slack Action
22
3- This GitHub Action sends a Slack notification summarizing failed jobs in a workflow run when used with an ` if: failure() ` condition.
3+ This GitHub Action sends a Slack notification. It supports two modes:
4+ - ** Failure mode** (default): summarizes failed jobs in a workflow run, intended for use with ` if: failure() ` .
5+ - ** Custom message mode** : sends a free-text message directly, useful for informational notifications such as PR creation alerts.
46
57## Description
68
7- The action posts a concise message to a Slack channel containing:
8- 1 . A link to the failed GitHub Actions run
9- 2 . A list of failed jobs provided by the workflow
10- 3 . A custom project-branded username and icon
11-
12- It is intended to be used as the last step (or in a dedicated job) guarded by ` if: failure() ` so that it only triggers on failures.
9+ The action posts a message to a Slack channel containing either:
10+ - A link to the failed GitHub Actions run and a list of failed jobs (failure mode), or
11+ - A custom message provided by the caller (custom message mode).
1312
1413## Dependencies
1514
@@ -19,22 +18,22 @@ This action depends on:
1918
2019## Inputs
2120
22- | Input | Description | Required | Default |
23- | -----------------| ------------------------------------------------------------------------| ----------| -----------|
24- | ` project-name ` | The display name of the project; used in the Slack username. | Yes | - |
25- | ` icon ` | Emoji icon for the Slack message (Slack emoji code). | No | ` :alert: ` |
26- | ` slack-channel ` | Slack channel (without ` # ` ) to post the notification into. | Yes | - |
27- | ` jobs ` | Comma-separated list of job names to report as failed (provided by you). | Yes | - |
28-
29- Note: The list of failed jobs must be provided via the ` jobs ` input by your workflow logic.
21+ | Input | Description | Required | Default |
22+ | -----------------| -------------------------------------------------------------------------------------------------------- | ----------| -----------|
23+ | ` project-name ` | The display name of the project; used in the Slack username. | Yes | - |
24+ | ` icon ` | Emoji icon for the Slack message (Slack emoji code). | No | ` :alert: ` |
25+ | ` slack-channel ` | Slack channel (without ` # ` ) to post the notification into. | Yes | - |
26+ | ` jobs ` | A GitHub needs-like object string of jobs and their results (e.g., from ` toJSON(needs) ` ). Required when ` message ` is not set. | No | - |
27+ | ` message ` | A custom free-text Slack message. When provided, skips job-failure parsing and sends this message directly. | No | - |
28+ | ` color ` | Slack attachment color ( ` good ` , ` danger ` , ` warning ` , or a hex code). | No | ` danger ` |
3029
3130## Outputs
3231
3332No outputs are produced by this action.
3433
3534## Usage
3635
37- ### Basic usage (in a dedicated failure notification job)
36+ ### Failure notification (in a dedicated failure notification job)
3837
3938``` yaml
4039jobs :
@@ -53,18 +52,21 @@ jobs:
5352 jobs : ${{ toJSON(needs) }}
5453` ` `
5554
56- ### Minimal usage (only required inputs )
55+ ### Custom message (e.g. PR ready for review )
5756
5857` ` ` yaml
5958- uses : SonarSource/release-github-actions/notify-slack@v1
60- if : failure()
6159 with :
6260 project-name : ' My Project'
63- slack-channel : ' engineering-alerts'
64- jobs : ' build, test'
61+ slack-channel : ' team-channel'
62+ icon : ' :memo:'
63+ color : good
64+ message : |
65+ *my-repo* rule metadata PR is ready for review:
66+ https://github.com/org/my-repo/pull/42
6567` ` `
6668
67- ### Custom icon
69+ ### Custom icon (failure mode)
6870
6971` ` ` yaml
7072- uses : SonarSource/release-github-actions/notify-slack@v1
@@ -73,18 +75,18 @@ jobs:
7375 project-name : ' My Project'
7476 slack-channel : ' engineering-alerts'
7577 icon : ' :rocket:'
76- jobs : ' build, test '
78+ jobs : ${{ toJSON(needs) }}
7779` ` `
7880
7981## Implementation Details
8082
8183The action is a composite action that:
8284- Fetches ` SLACK_TOKEN` from Vault path `development/kv/data/slack` using `vault-action-wrapper`
83- - Uses a workflow-provided `jobs` input (comma-separated string) to populate the "Failed Jobs" section
84- - Constructs a Slack message with run URL and the provided failed jobs list
85- - Uses `rtCamp/action-slack-notify` to send a minimal styled message (no title/footer) with danger color
85+ - When `message` is not set : parses the `jobs` JSON input to extract failed job names and constructs a message with the run URL
86+ - When `message` is set : sends the provided message directly, skipping job-failure parsing
87+ - Uses `rtCamp/action-slack-notify` to send a minimal styled message (no title/footer)
88+ - Sets the attachment color from the `color` input (defaults to `danger`)
8689- Sets Slack username to : ` <project-name> CI Notifier`
87- - If the `jobs` list is empty or not provided, the "Failed Jobs" line will be blank
8890
8991# # Prerequisites
9092
@@ -94,8 +96,6 @@ The action is a composite action that:
9496
9597# # Notes
9698
97- - Use `if : failure()` on the step or job; otherwise it will also fire on success.
98- - ` project-name` , `slack-channel`, and `jobs` are required inputs (no defaults).
99+ - For failure notifications, use `if : failure()` on the step or job; otherwise it will also fire on success.
99100- Do not prefix the channel with `#`.
100101- Message formatting is intentionally minimal for quick triage in alert-focused channels.
101- - How you compute the failed jobs list is up to your workflow; you can use prior steps to gather job results and pass them to this action via `jobs`.
0 commit comments