Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve a series of existing issues #162

Merged
merged 23 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8372d24
Add escape sequences using ``echo -e``
L0RD-ZER0 Mar 11, 2024
e3ca71d
Add better logging for unexpected exits
L0RD-ZER0 Mar 11, 2024
1e0e65b
Add ability to supply custom payloads
L0RD-ZER0 Mar 11, 2024
6a1429e
Add markdown formatting for messages
L0RD-ZER0 Mar 11, 2024
bcd3df7
Allow custom messages for different statuses
L0RD-ZER0 Mar 11, 2024
0690a95
Add ability to send messages in threads
L0RD-ZER0 Mar 11, 2024
a9aa265
Update footer to link the run message was sent from
L0RD-ZER0 Mar 11, 2024
9500ab2
Merge pull request #1 from L0RD-ZER0/feature/build
L0RD-ZER0 Mar 11, 2024
a711749
Merge pull request #2 from L0RD-ZER0/enhancement/escapes
L0RD-ZER0 Mar 11, 2024
903f0fc
Merge pull request #3 from L0RD-ZER0/enhancement/footer
L0RD-ZER0 Mar 11, 2024
d77f151
Merge branch 'master' into enhancement/logging
L0RD-ZER0 Mar 11, 2024
d4df9c8
Merge pull request #4 from L0RD-ZER0/enhancement/logging
L0RD-ZER0 Mar 11, 2024
62ca9f0
Merge pull request #5 from L0RD-ZER0/feature/build
L0RD-ZER0 Mar 11, 2024
4d8aaaf
Merge branch 'master' into feature/custom-status
L0RD-ZER0 Mar 11, 2024
057d058
Merge pull request #6 from L0RD-ZER0/feature/custom-status
L0RD-ZER0 Mar 11, 2024
eb50c62
Merge branch 'master' into feature/threads
L0RD-ZER0 Mar 11, 2024
9902697
Merge pull request #7 from L0RD-ZER0/feature/threads
L0RD-ZER0 Mar 11, 2024
ab67f67
Merge branch 'master' into feature/markdown
L0RD-ZER0 Mar 11, 2024
45b2a0a
Merge pull request #8 from L0RD-ZER0/feature/markdown
L0RD-ZER0 Mar 11, 2024
3d84059
Merge with master
L0RD-ZER0 Mar 11, 2024
68c7b1c
Merge pull request #9 from L0RD-ZER0/feature/custom-payload
L0RD-ZER0 Mar 11, 2024
233da9b
Fix main.sh for correct binary location
L0RD-ZER0 Mar 11, 2024
9af2bfc
Update go version and prepare for Pull Requesting
L0RD-ZER0 Mar 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.14-alpine3.11@sha256:6578dc0c1bde86ccef90e23da3cdaa77fe9208d23c1bb31d942c8b663a519fa5 AS builder
FROM golang:1.22-alpine3.19@sha256:5a99b4049412cd34ad6b4e0c9527ae6beb9ae82d787b4bf3f4eff7aa13fc577a AS builder

LABEL "com.github.actions.icon"="bell"
LABEL "com.github.actions.color"="yellow"
Expand All @@ -15,8 +15,8 @@ ENV GOOS linux
RUN go get -v ./...
RUN go build -a -installsuffix cgo -ldflags '-w -extldflags "-static"' -o /go/bin/slack-notify .

# alpine:latest at 2023-08-23T11:48:25.468623934UTC
FROM alpine@sha256:7144f7bab3d4c2648d7e59409f15ec52a18006a128c733fcff20d3a4a54ba44a
# alpine:latest as of 2024-03-11
FROM alpine@sha256:6457d53fb065d6f250e1504b9bc42d5b6c65941d57532c072d929dd0628977d0

COPY --from=builder /go/bin/slack-notify /usr/bin/slack-notify

Expand Down
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,25 @@ jobs:

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](https://github.com/rtBot.png?size=32) | 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 | 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.)
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](https://github.com/rtBot.png?size=32) | 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 | 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](https://github.com/marketplace/actions/slack-markdown-converter)
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_ON_SUCCESS | - | If set, will send the provided message instead of the default message when the passed status (through ``SLACK_COLOR``) is `success`.
SLACK_ON_FAILURE | - | If set, will send the provided message instead of the default message when the passed status (through ``SLACK_COLOR``) is `failure`.
SLACK_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.

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

Expand Down
26 changes: 23 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,28 @@ name: 'Slack Notify'
description: 'This action will send a notification to Slack'
author: 'rtCamp'
runs:
using: 'docker'
image: 'docker://ghcr.io/rtcamp/action-slack-notify:v2.2.1'
using: 'composite'
steps:
- name: "Slack-Markdown Conversion"
if: env.SLACKIFY_MARKDOWN == 'true'
id: slackify
uses: LoveToKnow/[email protected]
with:
text: ${{ env.SLACK_MESSAGE }}

- name: "Slack Notification (Formatted)"
if: env.SLACKIFY_MARKDOWN == 'true'
env:
SLACK_MESSAGE: "${{ steps.slackify.outputs.text }}"
GITHUB_RUN: "${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}"
ENABLE_ESCAPES: "true"
uses: "docker://ghcr.io/rtcamp/action-slack-notify:v2.2.1"

- name: "Slack Notification (Unformatted)"
if: env.SLACKIFY_MARKDOWN != 'true'
uses: "docker://ghcr.io/rtcamp/action-slack-notify:v2.2.1"
env:
GITHUB_RUN: "${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}"
branding:
icon: 'bell'
color: 'yellow'
color: 'yellow'
Loading