Skip to content

hnarimiya/slack-notice-action

 
 

Repository files navigation

Slack Notice Action

codecov

Yet Another GitHub Action to notify slack.

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
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 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 for details.

key value default description
payload '' Only available when status: custom. The payload format can pass javascript object.

Notification

success

- uses: sonots/slack-notice-action@v3
  with:
    status: ${{ job.status }}
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required, but GitHub should automatically supply
    SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
  if: always() # Pick up events even if the job fails or is canceled.

In case of failure or cancellation, you will be notified as follows.

failure

canceled

Legacy Incoming Webhooks

Legacy incoming webhooks are also supported. The secrets.SLACK_WEBHOOK_URL must be legacy one.

- uses: sonots/slack-notice-action@v3
  with:
    status: ${{ job.status }}
    username: Custom Username
    icon_emoji: ':octocat:'
    channel: '#integration-test'
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required
    SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required

Custom Notification

Use status: custom if you want to send an arbitrary payload. The payload format can pass javascript object.

- 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:

Special Thanks

This orginally started as a fork of https://github.com/8398a7/action-slack. Thanks!

About

Yet Another GitHub Action to notify slack

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 98.3%
  • JavaScript 1.7%