From e083b163eb8c12a214de20cabb3d3f314c6db371 Mon Sep 17 00:00:00 2001 From: Gaetan BOGAERT Date: Tue, 16 Mar 2021 15:27:56 +0100 Subject: [PATCH 1/2] Update main.go Update main.go Update main.go Update action.yml Update main.go Update main.go up --- action.yml | 3 ++- main.go | 2 ++ main.sh | 9 ++++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index a8a7519..2ec9523 100644 --- a/action.yml +++ b/action.yml @@ -3,7 +3,8 @@ description: 'This action will send a notification to Slack' author: 'rtCamp' runs: using: 'docker' - image: 'docker://ghcr.io/rtcamp/action-slack-notify:v2.1.3' +# image: 'docker://ghcr.io/rtcamp/action-slack-notify:v2.1.3' + image: 'Dockerfile' branding: icon: 'bell' color: 'yellow' diff --git a/main.go b/main.go index 0f02b1a..0d3b169 100644 --- a/main.go +++ b/main.go @@ -31,6 +31,7 @@ type Webhook struct { IconURL string `json:"icon_url,omitempty"` IconEmoji string `json:"icon_emoji,omitempty"` Channel string `json:"channel,omitempty"` + LinkNames int `json:"link_names,omitempty"` UnfurlLinks bool `json:"unfurl_links"` Attachments []Attachment `json:"attachments,omitempty"` } @@ -195,6 +196,7 @@ func main() { IconURL: os.Getenv(EnvSlackIcon), IconEmoji: os.Getenv(EnvSlackIconEmoji), Channel: os.Getenv(EnvSlackChannel), + LinkNames: 1, Attachments: []Attachment{ { Fallback: envOr(EnvSlackMessage, "GITHUB_ACTION="+os.Getenv("GITHUB_ACTION")+" \n GITHUB_ACTOR="+os.Getenv("GITHUB_ACTOR")+" \n GITHUB_EVENT_NAME="+os.Getenv("GITHUB_EVENT_NAME")+" \n GITHUB_REF="+os.Getenv("GITHUB_REF")+" \n GITHUB_REPOSITORY="+os.Getenv("GITHUB_REPOSITORY")+" \n GITHUB_WORKFLOW="+os.Getenv("GITHUB_WORKFLOW")), diff --git a/main.sh b/main.sh index 5c98992..a14bbe4 100644 --- a/main.sh +++ b/main.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash export GITHUB_BRANCH=${GITHUB_REF##*heads/} -export SLACK_ICON=${SLACK_ICON:-"https://avatars0.githubusercontent.com/u/43742164"} -export SLACK_USERNAME=${SLACK_USERNAME:-"rtBot"} +export SLACK_ICON=${SLACK_ICON} +export SLACK_USERNAME=${SLACK_USERNAME} export CI_SCRIPT_OPTIONS="ci_script_options" export SLACK_TITLE=${SLACK_TITLE:-"Message"} export COMMIT_MESSAGE=$(cat "$GITHUB_EVENT_PATH" | jq -r '.commits[-1].message') @@ -31,7 +31,10 @@ if [[ -n "$VAULT_GITHUB_TOKEN" ]] || [[ -n "$VAULT_TOKEN" ]]; then fi if [[ -f "$hosts_file" ]]; then - hostname=$(cat "$hosts_file" | shyaml get-value "$GITHUB_BRANCH.hostname") + hostname=$(cat "$hosts_file" | shyaml get-value "$ + + + .hostname") user=$(cat "$hosts_file" | shyaml get-value "$GITHUB_BRANCH.user") export HOST_NAME="\`$user@$hostname\`" export DEPLOY_PATH=$(cat "$hosts_file" | shyaml get-value "$GITHUB_BRANCH.deploy_path") From 4c41b90248d39d2cdcbc4123995c3545e1fa184a Mon Sep 17 00:00:00 2001 From: Gaetan BOGAERT Date: Tue, 16 Mar 2021 16:40:04 +0100 Subject: [PATCH 2/2] feat: add enable slack link_names --- README.md | 1 + action.yml | 3 +-- main.go | 5 +++-- main.sh | 9 +++------ 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index cfab213..f8f2f8e 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ SLACK_MSG_AUTHOR | `$GITHUB_ACTOR` (The person who triggered action). | GitH 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. diff --git a/action.yml b/action.yml index 2ec9523..a8a7519 100644 --- a/action.yml +++ b/action.yml @@ -3,8 +3,7 @@ description: 'This action will send a notification to Slack' author: 'rtCamp' runs: using: 'docker' -# image: 'docker://ghcr.io/rtcamp/action-slack-notify:v2.1.3' - image: 'Dockerfile' + image: 'docker://ghcr.io/rtcamp/action-slack-notify:v2.1.3' branding: icon: 'bell' color: 'yellow' diff --git a/main.go b/main.go index 0d3b169..77a62ad 100644 --- a/main.go +++ b/main.go @@ -23,6 +23,7 @@ const ( EnvSiteName = "SITE_NAME" EnvHostName = "HOST_NAME" EnvMinimal = "MSG_MINIMAL" + EnvSlackLinkNames = "SLACK_LINK_NAMES" ) type Webhook struct { @@ -31,7 +32,7 @@ type Webhook struct { IconURL string `json:"icon_url,omitempty"` IconEmoji string `json:"icon_emoji,omitempty"` Channel string `json:"channel,omitempty"` - LinkNames int `json:"link_names,omitempty"` + LinkNames string `json:"link_names,omitempty"` UnfurlLinks bool `json:"unfurl_links"` Attachments []Attachment `json:"attachments,omitempty"` } @@ -196,7 +197,7 @@ func main() { IconURL: os.Getenv(EnvSlackIcon), IconEmoji: os.Getenv(EnvSlackIconEmoji), Channel: os.Getenv(EnvSlackChannel), - LinkNames: 1, + LinkNames: os.Getenv(EnvSlackLinkNames), Attachments: []Attachment{ { Fallback: envOr(EnvSlackMessage, "GITHUB_ACTION="+os.Getenv("GITHUB_ACTION")+" \n GITHUB_ACTOR="+os.Getenv("GITHUB_ACTOR")+" \n GITHUB_EVENT_NAME="+os.Getenv("GITHUB_EVENT_NAME")+" \n GITHUB_REF="+os.Getenv("GITHUB_REF")+" \n GITHUB_REPOSITORY="+os.Getenv("GITHUB_REPOSITORY")+" \n GITHUB_WORKFLOW="+os.Getenv("GITHUB_WORKFLOW")), diff --git a/main.sh b/main.sh index a14bbe4..5c98992 100644 --- a/main.sh +++ b/main.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash export GITHUB_BRANCH=${GITHUB_REF##*heads/} -export SLACK_ICON=${SLACK_ICON} -export SLACK_USERNAME=${SLACK_USERNAME} +export SLACK_ICON=${SLACK_ICON:-"https://avatars0.githubusercontent.com/u/43742164"} +export SLACK_USERNAME=${SLACK_USERNAME:-"rtBot"} export CI_SCRIPT_OPTIONS="ci_script_options" export SLACK_TITLE=${SLACK_TITLE:-"Message"} export COMMIT_MESSAGE=$(cat "$GITHUB_EVENT_PATH" | jq -r '.commits[-1].message') @@ -31,10 +31,7 @@ if [[ -n "$VAULT_GITHUB_TOKEN" ]] || [[ -n "$VAULT_TOKEN" ]]; then fi if [[ -f "$hosts_file" ]]; then - hostname=$(cat "$hosts_file" | shyaml get-value "$ - - - .hostname") + hostname=$(cat "$hosts_file" | shyaml get-value "$GITHUB_BRANCH.hostname") user=$(cat "$hosts_file" | shyaml get-value "$GITHUB_BRANCH.user") export HOST_NAME="\`$user@$hostname\`" export DEPLOY_PATH=$(cat "$hosts_file" | shyaml get-value "$GITHUB_BRANCH.deploy_path")