All Projects → edge → simple-slack-notify

edge / simple-slack-notify

Licence: MIT License
Slack notification action that just works

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to simple-slack-notify

pr-reviews-reminder-action
A GitHub Action to send Slack/Teams notification for Pull Request that are waiting for reviewers.
Stars: ✭ 18 (-21.74%)
Mutual labels:  slack, notification, github-actions
Yii2 Slack Log
Pretty Slack log target for Yii 2
Stars: ✭ 24 (+4.35%)
Mutual labels:  slack, notification
website-change-monitor
Monitor a website and get email and Slack notifications when specific changes are detected
Stars: ✭ 104 (+352.17%)
Mutual labels:  slack, notification
apprise-ga
GitHub Action to send a dynamic push notification to every single platform thanks to the Apprise library
Stars: ✭ 18 (-21.74%)
Mutual labels:  notification, github-actions
Fredy
❤️ Fredy - [F]ind [R]eal [E]states [D]amn Eas[y] - Let the robot do the work...
Stars: ✭ 29 (+26.09%)
Mutual labels:  slack, notification
slatify
Slack Notification for GitHub Actions 🔔
Stars: ✭ 132 (+473.91%)
Mutual labels:  slack, github-actions
Taut
An ambitious Slack JSON export viewer.
Stars: ✭ 22 (-4.35%)
Mutual labels:  slack
django-security-check
Helps you continuously monitor and fix common security vulnerabilities in your Django application.
Stars: ✭ 69 (+200%)
Mutual labels:  github-actions
setup-task
GitHub Actions action to make Task available for use in your workflow
Stars: ✭ 14 (-39.13%)
Mutual labels:  github-actions
slack.cr
Slack Real Time Messaging API in Crystal
Stars: ✭ 17 (-26.09%)
Mutual labels:  slack
action
📦📊 GitHub Action to reports on the size of your npm package
Stars: ✭ 36 (+56.52%)
Mutual labels:  github-actions
deno notify
Send desktop notifications on all platforms in Deno
Stars: ✭ 27 (+17.39%)
Mutual labels:  notification
slack-status-based-on-wifi-name
Set your status on Slack based on the WiFi network you are connected to.
Stars: ✭ 30 (+30.43%)
Mutual labels:  slack
actions-readme-feed
Display RSS feed in your GitHub Profile README
Stars: ✭ 26 (+13.04%)
Mutual labels:  github-actions
gSlack
Get Slack notifications from Google Cloud Platform
Stars: ✭ 69 (+200%)
Mutual labels:  slack
karmabot
upvotes and downvotes for slack
Stars: ✭ 24 (+4.35%)
Mutual labels:  slack
npm-update-check-action
npm new package version check action for GitHub Actions.
Stars: ✭ 17 (-26.09%)
Mutual labels:  github-actions
chalice-extended-action
Automated deployment of your Chalice application via Github Actions
Stars: ✭ 18 (-21.74%)
Mutual labels:  github-actions
auto-card-labeler
GitHub actions to auto label a pull request or an issue based on project card move
Stars: ✭ 33 (+43.48%)
Mutual labels:  github-actions
lambda-action
GitHub Action for Deploying Lambda code to an existing function
Stars: ✭ 197 (+756.52%)
Mutual labels:  github-actions

Simple Slack Notify

GitHub release (latest by date) GitHub Release Date License js-standard-style

Slack notification action that just works

No longer maintained

Please note that this project is no longer maintained, and has been archived.

Introduction

We've attempted to use a few of the Slack notification actions that are currently available, but they all seem to have limitations or be quite verbose, so we set out to create a simple yet effective action that just does what you need and nothing else. In the examples below, we'll show a few different variations of how the action could be used.

The main features are:

  • Status based messages meaning one step handles job successes, failures, and cancellations
  • JavaScript strings for embedding environment variables or custom logic into notification strings
  • Easy to add fields based on standard Slack JSON inputs

Be sure that you set the SLACK_WEBHOOK_URL environment variable, either in the job or in the step like this:

- uses: edge/simple-slack-notify@master
  env:
    SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

Example usage

The simplest use would consist of relying on the webhook's defaults and simply providing some text.

- name: Simple notification
  uses: edge/simple-slack-notify@master
  with:
    text: 'This is the simplest notification'

Overriding the channel is sometimes needed, such as to separate out builds, deployments, and alerts perhaps.

- name: Channel specific notification
  uses: edge/simple-slack-notify@master
  with:
    channel: '#alerts'
    text: 'Something is happening and someone should probably panic'

The above works well, but what would really make someone panic is if we make the alert red, right?

You can use danger, warning, good, or a hex code such as #d90000.

- name: Panic inducing notification
  uses: edge/simple-slack-notify@master
  with:
    channel: '#alerts'
    text: 'Something is happening and someone should probably panic'
    color: 'danger'

Perhaps you also want to change the username?

- name: Panic Bot notification
  uses: edge/simple-slack-notify@master
  with:
    channel: '#alerts'
    username: 'Panic Bot'
    text: 'Something is happening and someone should probably panic'
    color: 'danger'

The action also supports fields, but due to the limitations of GitHub actions only passing in inputs as strings, we can't use yaml arrays. So, this is how you'd specify a field:

- name: Specifying what to panic about notification
  uses: edge/simple-slack-notify@master
  with:
    channel: '#alerts'
    username: 'Panic Bot'
    text: 'Something is happening and someone should probably panic'
    color: 'danger'
    fields: |
      [{ "title": "Reason to panic", "value": "Deployed failed halfway through" }]

If there were multiple reasons to panic, you'd add more objects to the fields array:

- name: Specifying what to panic about notification
  uses: edge/simple-slack-notify@master
  with:
    channel: '#alerts'
    username: 'Panic Bot'
    text: 'Something is happening and someone should probably panic'
    color: 'danger'
    fields: |
      [{ "title": "Reason to panic", "value": "Deployed failed halfway through", "short": true },
       { "title": "Timestamp", "value": "${Date.now()}", "short": true }]

Did you notice that some JavaScript snook in? Input strings are evaluated as a JavaScript strings, which means you can put environment variables into your messages, such as the GITHUB_WORKFLOW variable or GITHUB_RUN_NUMBER etc. The environment is stored within the env variable so to access environment variables in your strings, you simply use ${env.GITHUB_REPOSITORY} etc. Here's an example:

- name: Environment variable notification
  uses: edge/simple-slack-notify@master
  with:
    channel: '#example'
    text: '${env.GITHUB_WORKFLOW} (${env.GITHUB_RUN_NUMBER}) has finished'
    fields: |
      [{ "title": "Repository", "value": "${env.GITHUB_REPOSITORY}", "short": true },
       { "title": "Branch", "value": "${env.BRANCH}", "short": true }]

Now, each job has a status, which can be success, failed, or cancelled. Most other notification plugins use multiple blocks with if: success() and if: failed() etc but we don't need to do that. We can simply pass in the status and set status specific text. We use if: always() so that it runs regardless of whether the job is successful or not.

- name: Build notification
  if: always()
  uses: edge/simple-slack-notify@master
  with:
    channel: '#builds'
    status: ${{ job.status }}
    success_text: '${env.GITHUB_WORKFLOW} (${env.GITHUB_RUN_NUMBER}) build completed successfully'
    failure_text: '${env.GITHUB_WORKFLOW} (${env.GITHUB_RUN_NUMBER}) build failed'
    cancelled_text: '${env.GITHUB_WORKFLOW} (${env.GITHUB_RUN_NUMBER}) build was cancelled'
    fields: |
      [{ "title": "Repository", "value": "${env.GITHUB_REPOSITORY}", "short": true },
       { "title": "Branch", "value": "${env.BRANCH}", "short": true }]

There are likely other ways you can use this action, so please submit a pull request if you want to add your useful example to this list. I hope this is as useful for you as it is for me.

Extracting GitHub branch

Note: the BRANCH variable isn't standard. To get that, use the following:

- name: Extract branch name
  shell: bash
  run: echo "::set-env name=BRANCH::$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g')"

This won't work for actions initiated by a pull request though.

Link to run

If you want to link to the run, that's super easy. Just add the following string either to a field or to the message.

${env.GITHUB_SERVER_URL}/${env.GITHUB_REPOSITORY}/actions/runs/${env.GITHUB_RUN_ID}

So for a field you'd have:

{ "title": "Action URL", "value": "${env.GITHUB_SERVER_URL}/${env.GITHUB_REPOSITORY}/actions/runs/${env.GITHUB_RUN_ID}"}

Inputs

Input Details Example/possible values
cancelled_text The message to send if status is cancelled
channel The channel you want to send to #general
color The color you want to use "good", "danger", "warning" or a hex code
disable_eval Disable JS string evaluation. False by default false
failure_text The message to send if status is failure
fields JSON string containing an array of fields to attach to the notification
status Pass the job status through and omit color for status based color
success_text The message to send if status is success
text The message that you want to send regardless of status
username Used to override the default username

License

MIT License

Copyright (c) 2020 Adam K Dean <[email protected]>
                   Edge Network Technologies Ltd <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].