Giter Club home page Giter Club logo

action-slack-notify's Introduction

This action is a part of GitHub Actions Library created by rtCamp.

Slack Notify - GitHub Action

Project Status: Active โ€“ The project has reached a stable, usable state and is being actively developed.

A GitHub Action to send a message to a Slack channel.

Screenshot

action-slack-notify-rtcamp

The Site and SSH Host details are only available if this action is run after Deploy WordPress GitHub action.

Usage

You can use this action after any other action. Here is an example setup of this action:

  1. Create a .github/workflows/slack-notify.yml file in your GitHub repo.
  2. Add the following code to the slack-notify.yml file.
on: push
name: Slack Notification Demo
jobs:
  slackNotification:
    name: Slack Notification
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Slack Notification
      uses: rtCamp/action-slack-notify@v2
      env:
        SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
  1. Create SLACK_WEBHOOK secret using GitHub Action's Secret. You can generate a Slack incoming webhook token from here.

Environment Variables

By default, action is designed to run with minimal configuration but you can alter Slack notification using following environment variables:

Variable Default Purpose
SLACK_CHANNEL Set during Slack webhook creation Specify Slack channel in which message needs to be sent
SLACK_USERNAME rtBot Custom Slack Username sending the message. Does not need to be a "real" username.
SLACK_MSG_AUTHOR $GITHUB_ACTOR (The person who triggered action). GitHub username of the person who has triggered the action. In case you want to modify it, please specify corrent GitHub username.
SLACK_ICON rtBot Avatar User/Bot icon shown with Slack message. It uses the URL supplied to this env variable to display the icon in slack message.
SLACK_ICON_EMOJI - User/Bot icon shown with Slack message, in case you do not wish to add a URL for slack icon as above, you can set slack emoji in this env variable. Example value: :bell: or any other valid slack emoji.
SLACK_COLOR good (green) You can pass ${{ job.status }} for automatic coloring or an RGB value like #efefef which would change color on left side vertical line of Slack message. Other valid values for this field are: success, cancelled or failure.
SLACK_LINK_NAMES - If set to true, enable mention in Slack message.
SLACK_MESSAGE Generated from git commit message. The main Slack message in attachment. It is advised not to override this.
SLACK_TITLE Message Title to use before main Slack message.
SLACK_FOOTER Powered By rtCamp's GitHub Actions Library Slack message footer.
MSG_MINIMAL - If set to true, removes: Ref, Event, Actions URL and Commit from the message. You can optionally whitelist any of these 4 removed values by passing it comma separated to the variable instead of true. (ex: MSG_MINIMAL: event or MSG_MINIMAL: ref,actions url, etc.)
SLACKIFY_MARKDOWN - If set to true, it will convert markdown to slack format. (ex: *bold* to bold) Note: This only works for custom messages and not for the default message generated by the action. Credits: slackify-markdown-action
SLACK_THREAD_TS - If you want to send message in a thread, you can pass the timestamp of the parent message to this variable. You can get the timestamp of the parent message from the message URL in Slack. (ex: SLACK_THREAD_TS: 1586130833.000100)
SLACK_TOKEN - If you want to send message to a channel using a slack token. You will need to pass a channel in order to send messages using token, requiring a value for SLACK_CHANNEL. Note that in case both webhook url and token are provided, webhook url will be prioritized.
SLACK_MESSAGE_ON_SUCCESS - If set, will send the provided message instead of the default message when the passed status (through SLACK_COLOR) is success.
SLACK_MESSAGE_ON_FAILURE - If set, will send the provided message instead of the default message when the passed status (through SLACK_COLOR) is failure.
SLACK_MESSAGE_ON_CANCEL - If set, will send the provided message instead of the default message when the passed status (through SLACK_COLOR) is cancelled.
SLACK_CUSTOM_PAYLOAD - If you want to send a custom payload to slack, you can pass it as a string to this variable. This will override all other variables and send the custom payload to slack. Example: SLACK_CUSTOM_PAYLOAD: '{"text": "Hello, World!"}', Note: This payload should be in JSON format, and is not validated by the action.
SLACK_FILE_UPLOAD - If you want to upload a file to slack, you can pass the file path to this variable. Example: SLACK_FILE_UPLOAD: /path/to/file.txt. Note: This file should be present in the repository, or github workspace. Otherwise, should be accessable in the container the action is running in.
ENABLE_ESCAPES - If set to true, will enable backslash escape sequences such as \n, \t, etc. in the message. Note: This only works for custom messages and not for the default message generated by the action.

You can see the action block with all variables as below:

    - name: Slack Notification
      uses: rtCamp/action-slack-notify@v2
      env:
        SLACK_CHANNEL: general
        SLACK_COLOR: ${{ job.status }} # or a specific color like 'good' or '#ff00ff'
        SLACK_ICON: https://github.com/rtCamp.png?size=48
        SLACK_MESSAGE: 'Post Content :rocket:'
        SLACK_TITLE: Post Title
        SLACK_USERNAME: rtCamp
        SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}

Below screenshot help you visualize message part controlled by different variables:

Screenshot_2019-03-26_at_5_56_05_PM

The Site and SSH Host details are only available if this action is run after Deploy WordPress GitHub action.

Hashicorp Vault (Optional) (Deprecated)

This GitHub action supports Hashicorp Vault.

To enable Hashicorp Vault support, please define following GitHub secrets:

Variable Purpose Example Vaule
VAULT_ADDR Vault server address https://example.com:8200
VAULT_TOKEN Vault token s.gIX5MKov9TUp7iiIqhrP1HgN

You will need to change secrets line in slack-notify.yml file to look like below.

on: push
name: Slack Notification Demo
jobs:
  slackNotification:
    name: Slack Notification
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Slack Notification
      uses: rtCamp/action-slack-notify@v2
      env:
        VAULT_ADDR: ${{ secrets.VAULT_ADDR }}
        VAULT_TOKEN: ${{ secrets.VAULT_TOKEN }}

GitHub action uses VAULT_TOKEN to connect to VAULT_ADDR to retrieve slack webhook from Vault.

In the Vault, the Slack webhook should be setup as field webhook on path secret/slack.

Credits

Source: technosophos/slack-notify

License

MIT ยฉ 2022 rtCamp

Does this interest you?

Join us at rtCamp, we specialize in providing high performance enterprise WordPress solutions

action-slack-notify's People

Contributors

0x2b3bfa0 avatar bogaertg avatar chenrui333 avatar devsibwarra avatar dhsathiya avatar hrithikdalal avatar kirtangajjar avatar l0rd-zer0 avatar lukasz-mitka avatar maitreyie-chavan avatar mbtamuli avatar mochetts avatar modalkonform avatar mrrobot47 avatar nuhkoca avatar ohbarye avatar paulsearcy avatar pradeep910 avatar rahul286 avatar topikito avatar vitorsavedra avatar yakkun avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.