Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sonots/slack-notice-action
Yet Another GitHub Action to notify slack
https://github.com/sonots/slack-notice-action
Last synced: about 2 months ago
JSON representation
Yet Another GitHub Action to notify slack
- Host: GitHub
- URL: https://github.com/sonots/slack-notice-action
- Owner: sonots
- License: mit
- Created: 2020-01-07T14:13:28.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-06-14T07:38:47.000Z (7 months ago)
- Last Synced: 2024-11-04T15:04:46.023Z (about 2 months ago)
- Language: TypeScript
- Homepage: https://github.com/marketplace/actions/slack-notice-action
- Size: 771 KB
- Stars: 28
- Watchers: 1
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Slack Notice Action
![](https://github.com/sonots/slack-notice-action/workflows/build-test/badge.svg)
![](https://github.com/sonots/slack-notice-action/workflows/Slack%20Mainline/badge.svg)
![](https://img.shields.io/github/license/sonots/slack-notice-action?color=brightgreen)
![](https://img.shields.io/github/v/release/sonots/slack-notice-action?color=brightgreen)
[![codecov](https://codecov.io/gh/sonots/slack-notice-action/branch/master/graph/badge.svg)](https://codecov.io/gh/sonots/slack-notice-action)Yet Another GitHub Action to notify slack.
## Quick Start
```yaml
- uses: sonots/slack-notice-action@v3
with:
status: ${{ job.status }}
only_mention_fail: 'channel'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Required, but this should be automatically supplied by GitHub.
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # Required. Legacy Incoming Webhook is also supported.
if: always() # Pick up events even if the job fails or is canceled.
```## Usage
### with Parameters
| key | value | default | description |
| ----------------- | ---------------------------------------------------------- | --------------------- | ------------------------------------------|
| status | `success` or `failure` or `cancelled` or `custom` | '' | Use `${{ job.status }}`. |
| text | any string | '' | `text` field |
| text_on_success | any string | '' | `text` field on success |
| text_on_fail | any string | '' | `text` field on failure |
| text_on_cancel | any string | '' | `text` field on cancellation |
| title | any string | workflow name | `title` field |
| mention | `here` or `channel` or user\_id such as `user_id,user_id2` | '' | Mention always if specified. The user ID should be an ID, such as `@U024BE7LH`. See [Mentioning Users](https://api.slack.com/reference/surfaces/formatting#mentioning-users) |
| only_mention_fail | `here` or `channel` or user\_id such as `user_id,user_id2` | '' | Mention only on failure if specified |Supported by only legacy incoming webhook.
| key | value | default | description |
| ----------------- | ----- | ---------| ----------------------------------------------------------------------------------------------------------- |
| username | | '' | override the legacy integration's default name. |
| icon_emoji | | '' | an [emoji code](https://www.webfx.com/tools/emoji-cheat-sheet/) string to use in place of the default icon. |
| icon_url | | '' | an icon image URL string to use in place of the default icon. |
| channel | | '' | override the legacy integration's default channel. This should be an ID, such as `C8UJ12P4P`. |Custom notification. See [Custom Notification](https://github.com/sonots/slack-notice-action#custom-notification) for details.
| key | value | default | description |
| ----------------- | ----- | ---------| ----------------------------------------------------------------------------------------------------------- |
| payload | | '' | Only available when status: custom. The payload format can pass javascript object. |## Example
Legacy Incoming Webhook Example:
```yaml
- uses: sonots/slack-notice-action@v3
with:
status: ${{ job.status }}
username: Custom Username
icon_emoji: ':octocat:'
channel: 'C8UJ12P4P'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Required, but this should be automatically supplied by GitHub.
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # Required. Legacy Incoming Webhook is also supported.
if: always() # Pick up events even if the job fails or is canceled.
```In case of success:
In case of failure:
In case of cancellation:
## Example: Custom Notification
Use `status: custom` if you want to send an arbitrary payload.
The payload format can pass javascript object.```yaml
- uses: sonots/slack-notice-action@v3
with:
status: custom
payload: |
{
text: "Custom Field Check",
attachments: [{
"author_name": "sonots@slack-notice-action", // json
fallback: 'fallback',
color: 'good',
title: 'CI Result',
text: 'Succeeded',
fields: [{
title: 'lower case',
value: 'LOWER CASE CHECK'.toLowerCase(),
short: true
},
{
title: 'reverse',
value: 'gnirts esrever'.split('').reverse().join(''),
short: true
},
{
title: 'long title1',
value: 'long value1',
short: false
}],
actions: [{
}]
}]
}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # optional
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
```See also:
- [Message Builder](https://api.slack.com/docs/messages/builder)
- [Reference: Message payloads](https://api.slack.com/reference/messaging/payload)## Special Thanks
This orginally started as a fork of https://github.com/8398a7/action-slack. Thanks!