Skip to content

Latest commit

 

History

History
129 lines (89 loc) · 6.54 KB

README.md

File metadata and controls

129 lines (89 loc) · 6.54 KB

Action Slack Notify

(Forked from rtCamp/action-slack-notify)

This repo builds a Go binary based on this image and then starts it with a shell script. This avoids unnecessary usage of Docker. It can even be used in the same way as the original. Some things have been ripped out of the shell scripts since we provide those environment variables already and wanted to avoid installing extra dependencies.

How to build

Install UPX (for packing binary)

sudo apt install upx

NOTE: All builds are expected to target Linux.

From POSIX:

env GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o bin/slack-notify main.go
sudo upx --brute ./bin/slack-notify

From Windows (PowerShell 7+):

$Env:GOOS = "linux"; $Env:GOARCH = "amd64"; go build -ldflags="-s -w" -o bin/slack-notify main.go
wsl bash -c -i "sudo upx --brute ./bin/slack-notify"

You may need to update permissions for Linux on Windows. You can do this with
git update-index --chmod=+x ./bin/slack-notify


README

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.
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 - 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.)

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.

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