Giter Site home page Giter Site logo

act10ns / slack Goto Github PK

View Code? Open in Web Editor NEW
190.0 3.0 57.0 4.04 MB

Slack messages for GitHub Action workflows, jobs and steps

Home Page: https://github.com/marketplace/actions/slack-github-actions-slack-integration

License: MIT License

TypeScript 98.46% JavaScript 0.36% Makefile 1.18%

slack's Introduction

build-test

Slack messages for GitHub Actions workflows, jobs and steps

A simple and flexible Slack integration with GitHub Actions.

Features

  • Advanced users can use a configuration file and Handlebars templates to configure every aspect of the Slack message.

  • In addition to "legacy" attachments, rich messages can be created using layout blocks for flexible message visualisation and interactivity.

Configuration

Environment Variables (env)

SLACK_WEBHOOK_URL (required)

Create a Slack Webhook URL using either the Incoming Webhooks App (preferred) or by attaching an incoming webhook to an existing Slack App (beware, channel override not possible when using a Slack App):

env:
  SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

Input Parameters (with)

webhook-url (optional)

Only required if the SLACK_WEBHOOK_URL environment variable is not set.

  with:
    webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}

status (required)

The status must be defined. It can either be the current job status using:

  with:
    status: ${{ job.status }}

or a hardcoded custom status such as "starting" or "in progress":

  with:
    status: in progress

steps (optional)

The individual status of job steps can be included in the Slack message using:

  with:
    status: ${{ job.status }}
    steps: ${{ toJson(steps) }}

Note: Only steps that have a "step id" will be reported on. See example below.

matrix (optional)

Parameters for matrix jobs can be included in Slack messages:

  with:
    status: ${{ job.status }}
    matrix: ${{ toJson(matrix) }}

channel (optional)

To override the channel or to send the Slack message to an individual use:

  with:
    status: ${{ job.status }}
    channel: '#workflows'

Note: To override the channel the Slack webhook URL must be an Incoming Webhook URL. See https://api.slack.com/faq#incoming_webhooks

message (optional)

To override the slack message use:

  with:
    status: ${{ job.status }}
    channel: '#workflows'
    message: Deploying {{ env.GITHUB_REF_NAME }} branch

config (optional)

A configuration file can be used to customise the following Slack message fields:

  • username
  • icon_url
  • pretext
  • title and title_link
  • text
  • fallback plain text summary used for dumb clients and notifications
  • fields title, value and short/long
  • blocks including actions, context, divider, file, header, image, input and section blocks
  • message footer
  • border colors based job status success, failure, cancelled. valid colors are good (green), warning (yellow), danger (red) or any hex color code eg. #439FE0
  • icons for step status success, failure, cancelled, skipped, and a default

Default: .github/slack.yml

  with:
    status: ${{ job.status }}
    config: .github/config/slack.yml

The following Slack message fields and block layouts support templating using Handlebars.js format:

  • pretext
  • title
  • text and message
  • fallback
  • fields title and value
  • blocks

Supported Template variables

env.*, payload.*, jobName, jobStatus, jobSteps, jobMatrix, eventName, workflow, workflowUrl, workflowRunUrl, repositoryName, repositoryUrl, runId, runNumber, sha, shortSha, branch, actor, action, ref, refType, refUrl, diffRef, diffUrl, description, sender

Helper Functions

Apart from the standard helper functions such as #if and #each there are also a few custom ones:

  • icon converts a job status into an icon eg. {{icon jobStatus}}

  • json dumps the value as a JSON string eg. {{json payload.commits}}

  • truncate cuts the string at the limit eg. {{truncate sha 8}}

  • default allows a alternative or default value eg. {{default headRef "master"}}

  • pluralize outputs different text based on item count eg. {{pluralize requested_reviewers "reviewer" "reviewers"}} (if only singular form is given plural is derived by adding an "s")

  • eq, neq, not, and, and or can be used as logical operators eg. {{#if (and (not has_issues) (or has_pages has_wiki))}}yes{{else}}no{{/if}}

  • #ifeq and #ifneq test for variable equality or not eg. {{#ifneq event_name "create"}}yes{{else}}no{{/ifneq}}

Example Using Config File

To generate the message format below use the slack.yml configuration file that follows.

Example Configuration File: slack.yml

username: GitHub-CI
icon_url: https://octodex.github.com/images/mona-the-rivetertocat.png

pretext: Triggered via {{eventName}} by {{actor}} {{or action "action"}} {{ref}} `{{diffRef}}`
title: GitHub Actions
title_link: https://support.github.com

text: |
  *<{{workflowRunUrl}}|Workflow _{{workflow}}_ job _{{jobName}}_ triggered by _{{eventName}}_ is _{{jobStatus}}_>* for <{{refUrl}}|`{{ref}}`>
  {{#if description}}<{{diffUrl}}|`{{diffRef}}`> - {{description}}{{/if}}
  {{#if payload.commits}}
  *Commits*
  {{#each payload.commits}}
  <{{this.url}}|`{{truncate this.id 8}}`> - {{this.message}}
  {{/each}}
  {{/if}}

fallback: |-
  [GitHub] {{workflow}} #{{runNumber}} {{jobName}} is {{jobStatus}}

fields:
  - title: Job Steps
    value: "{{#each jobSteps}}{{icon this.outcome}} {{@key}}\n{{/each}}"
    short: false
  - title: Job Matrix
    value: "{{#each jobMatrix}}{{@key}}: {{this}}\n{{/each}}"
    short: false
  - title: Workflow
    value: "<{{workflowUrl}}|{{workflow}}>"
    short: true
  - title: Git Ref
    value: "{{ref}} ({{refType}})"
    short: true
  - title: Run ID
    value: |-
      <{{workflowRunUrl}}|{{runId}}>
    short: true
  - title: Run Number
    value: "{{runNumber}}"
    short: true
  - title: Actor
    value: "{{actor}}"
    short: true
  - title: Job Status
    value: "{{jobStatus}}"
    short: true

footer: >-
  <{{repositoryUrl}}|{{repositoryName}}> {{workflow}} #{{runNumber}}

colors:
  success: '#5DADE2'
  failure: '#884EA0'
  cancelled: '#A569BD'
  default: '#7D3C98'

icons:
  success: ':white_check_mark:'
  failure: ':grimacing:'
  cancelled: ':x:'
  skipped: ':heavy_minus_sign:'
  default: ':interrobang:'

Notes:

  • If template expressions occur at the start of a string the string must be double-quoted eg. pretext: "{{eventName}} triggered by {{actor}}"
  • Use YAML multiline string formats |, >, |- and >- or double-quotes "\n" to control new lines
  • Use ~ (tilde) character to control whitepace when looping see Whitespace control

Conditionals (if)

To ensure the Slack message is sent even if the job fails add the always() function:

if: always()

or use a specific status function to only run when the job status matches. All possible status check functions are:

  • success() (default)
  • always()
  • cancelled()
  • failure()

Examples

To send a Slack message when a workflow job has completed add the following as the last step of the job:

- uses: act10ns/slack@v2
  with: 
    status: ${{ job.status }}
  if: always()

To include statuses for each Job Step in the message include the steps input (making sure to use the toJSON function):

- uses: act10ns/slack@v2
  with: 
    status: ${{ job.status }}
    steps: ${{ toJson(steps) }}
  if: always()

Only steps that have a "step id" assigned to them will be reported on:

- name: Build
  id: build
  run: |
    npm install
    npm run build

The default Slack channel for the configured webhook can be overridden using either another channel name #channel or a username @username.

- uses: act10ns/slack@v2
  with: 
    status: ${{ job.status }}
    channel: '#workflows'

or

- uses: act10ns/slack@v2
  with: 
    status: ${{ job.status }}
    channel: '@nick'

Complete example

name: Docker Build and Push

on:
  push:
    branches: [ master, release/* ]

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      REPOSITORY_URL: docker.pkg.github.com
      IMAGE_NAME: ${{ github.repository }}/alerta-cli
      SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
    steps:
      - uses: act10ns/slack@v2
        with:
          status: starting
          channel: '#workflows'
          message: Starting Docker Build and Push...
        if: always()
      - name: Checkout
        uses: actions/checkout@v4
      - name: Variables
        id: vars
        run: echo "::set-output name=SHORT_COMMIT_ID::$(git rev-parse --short HEAD)"
      - name: Build image
        id: docker-build
        run: >-
          docker build
          -t $IMAGE_NAME
          -t $REPOSITORY_URL/$IMAGE_NAME:${{ steps.vars.outputs.SHORT_COMMIT_ID }}
          -t $REPOSITORY_URL/$IMAGE_NAME:latest .
      - name: Docker Login
        env:
          DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
          DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
        run: docker login $REPOSITORY_URL --username "$DOCKER_USERNAME" --password "$DOCKER_PASSWORD"
      - name: Publish Image
        id: docker-push
        run: docker push $REPOSITORY_URL/$IMAGE_NAME

      - uses: act10ns/slack@v2
        with:
          status: ${{ job.status }}
          steps: ${{ toJson(steps) }}
          channel: '#workflows'
        if: always()

The above "Docker Build and Push" workflow will appear in Slack as:

Troubleshooting

To enable runner diagnostic logging set the ACTIONS_RUNNER_DEBUG secret to true.

To enable step debug logging set the ACTIONS_STEP_DEBUG secret to true.

See https://docs.github.com/en/free-pro-team@latest/actions/managing-workflow-runs/enabling-debug-logging

References

License

Copyright (c) 2020-2024 Nick Satterly. Available under the MIT License.

slack's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar jamesking56 avatar molayadev avatar pftg avatar samuelcabralcruz avatar satterly avatar sue445 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

slack's Issues

Feature Request - Multiple Notifications Channels

Is your feature request related to a problem? Please describe.
No, not a problem :)

Describe the solution you'd like
Something like this will be helpful

    - uses: act10ns/slack0
      with:
        channels: '#channel1 #channel2'

Describe alternatives you've considered
Use another step with a different channel

if: always () with another if condition

Is your feature request related to a problem? Please describe.
This is more of a question as It could be lack of YAML knowledge on my end. However, I'm having a hard time getting if: always () to work, because I have an if: statement already being used to identify which environment we're using.

This works just fine, without if: always ()

Example (modified for randomness)

name: SomeTest

on:
 repository_dispatch:
    types: [SomeTest]

jobs:
  build:

    runs-on: ubuntu-latest
    env:
      ENV: ${{ github.event.client_payload.env }}
      A_CICD_JOB: ${{ github.event.client_payload.repo_name }}
      BRANCH_NAME: ${{ github.event.client_payload.branch_name }}

    steps:
      - uses: actions/checkout@v2
      - name: Set up JDK XX
      <BUILD SOME STUFF>
     ...
     ...
     ...

      - name: Slack Notify Status UAT
        uses: act10ns/slack@v1
        if: ${{ env.ENV  }} == 'uat'
        with:
          webhook-url: ${{ secrets.UAT_SOMETEST_SLACK_WEBHOOK_URL }}
          status: ${{ job.status }}
          channel: '#uat-somechannel'
          message: GitHub some test result "${{ job.status }}" on ${{ env.A_CICD_JOB }} - ${{ env.BRANCH_NAME }}
   
      - name: Slack Notify Status Staging
        uses: act10ns/slack@v1
        if: ${{ env.ENV }} == 'staging'
        with:
           webhook-url: ${{ secrets.STAGING_SOMETEST_SLACK_WEBHOOK_URL }}
           status: ${{ job.status }}
           channel: '#staging-somechannel'
           message: GitHub some test result "${{ job.status }}" on ${{ env.A_CICD_JOB }} - ${{ env.BRANCH_NAME }}

I've tried various combinations, like so (same for 'staging'):

  • which gets no failure notifications, and posts in both slack channels above, during success
        uses: act10ns/slack@v1
        if: |
          always() &&
          ${{ env.ENV  }} == 'uat'
        with:

I've also tried a simple always() && ${{ env.ENV }} == 'uat' however, same results as directly above.

Describe the solution you'd like
I think I may just be missing something, if not:

  • can we have another way to report statuses besides success that don't require if:?

Describe alternatives you've considered
I can just create two workflow files, however I wanted to check here first as a last option before duplicating that much code.

Additional context
I am using web hooks, not slack apps.

Thank you very much!

Add run duration message

Hello, I just found your great GitHub Action yesterday and integrated it into our builds. It's exactly what I was looking for.

Coming from Azure Pipelines, the only thing I'm really missing is an indication of the Duration. Here's a stock screenshot of some of their output:

image

I'd like to suggest a formatting change for improved readability... I tried to recreate what it would look like with formatting below:


(usericon) linkedusername
Workflow run Integration Build succeeded
Branch
develop
Trigger
Push
Job
main-job
Duration
00:34:32


Where the Branch/Trigger/Job/Duration are done using the grid kind of format where they default to showing in two columns.

Slack action just stopped working in the last hour or so

I cannot say it is related to the version bump but it just changed, and this stopped working...

2020-11-16T21:39:53.2810382Z ##[error]TypeError: Cannot read property 'timestamp' of undefined
at Object. (/home/runner/work/_actions/act10ns/slack/v1/dist/index.js:9356:50)
at Generator.next ()
at /home/runner/work/_actions/act10ns/slack/v1/dist/index.js:9281:71
at new Promise ()
at module.exports.570.__awaiter (/home/runner/work/_actions/act10ns/slack/v1/dist/index.js:9277:12)
at Object.send [as default] (/home/runner/work/_actions/act10ns/slack/v1/dist/index.js:9309:12)
at /home/runner/work/_actions/act10ns/slack/v1/dist/index.js:3306:34
at Generator.next ()
at /home/runner/work/_actions/act10ns/slack/v1/dist/index.js:3281:71
at new Promise ()

Message is not correctly formatted for a scheduled action

We have a repo that has some long running system tests. We run these on a schedule and they are run on a self-hosted runner.

Failure messages look like this:

image

I'm not familiar with what gets supplied in the context and if it's any different for a self-hosted runner. I can see where the message is formatted in the code, so creating a P/R shouldn't be difficult once I can get my head around those details.

I'll be able to circle back to this in a couple weeks, but I might have time to run an experiment or two if you have time to look at it before then.

Add a custom message

It would be nice to be able to add a completely custom message to the action that can be sent to the Slack card template. This would enable sending much richer information into Slack such as download links for newly created builds or just additional metadata about the workflow.

One could have a custom message which could be configured as part of the action like so:

- name: slack notification
	uses: act10ns/slack@v1
    env:
    	SLACK_WEBHOOK_URL: ${{secrets.SLACK_WEBHOOK_URL}}
   	with:
    	status: ${{job.status}}
		custom_message: "New beta on channel ${{github.event.inputs.channel}} ready to test at the following link ${{some_output_link}}"
	if: success()

Video Tutorial on how to use the configuration files i.e config.yaml

Is your feature request related to a problem? Please describe.
I am finding it extremely difficult to successfully setup the advanced slack notifications using the config.yaml file

Describe the solution you'd like
I think a detailed tutorial video about how to use and setup the config.yaml file would be really helpful

I think this tutorial snippets would really help to reduce confusion.
I really want to appreciate you for your efforts and innovation in making this project work.

Slack app token support

Incoming Webhooks are considered legacy now and app webhooks only allow you to post to a single channel, so adding support for app tokens would be awesome!

Allow only block messages

I'm trying to send a message using only blocks, but the action don't accept this. Have an default to fields, text, title, footer and authors.

The message structure don't allow the blocks inside the message, always the blocks push at the end of the message.

slack/src/slack.ts

Lines 229 to 269 in c97e3fd

const pretextTemplate = Handlebars.compile(opts?.pretext || '')
const titleTemplate = Handlebars.compile(opts?.title || '')
const defaultText = `${
'*<{{{workflowUrl}}}|Workflow _{{workflow}}_ ' +
'job _{{jobName}}_ triggered by _{{eventName}}_ is _{{jobStatus}}_>* ' +
'for <{{refUrl}}|`{{ref}}`>\n'
}${description ? '<{{diffUrl}}|`{{diffRef}}`> - {{{description}}}' : ''}`
const textTemplate = Handlebars.compile(message || opts?.text || defaultText)
const defaultFallback = `[GitHub]: [{{repositoryName}}] {{workflow}} {{eventName}} ${
action ? '{{action}} ' : ''
}{{jobStatus}}`
const fallbackTemplate = Handlebars.compile(opts?.fallback || defaultFallback)
const defaultFields = Object.entries(jobSteps).length
? [
{
title: 'Job Steps',
value: '{{#each jobSteps}}{{icon this.outcome}} {{@key}}\n{{~/each}}',
short: false,
if: 'always()'
}
]
: []
const filteredFields: object[] = []
for (const field of opts?.fields || defaultFields) {
const field_if = field?.if || 'always()'
if (field_if === 'always()' || field_if.startsWith(jobStatus.toLowerCase())) {
filteredFields.push({
title: field.title,
value: field.value,
short: JSON.parse(field.short.toString())
})
}
}
const fieldsTemplate = Handlebars.compile(JSON.stringify(filteredFields))
const defaultFooter = '<{{repositoryUrl}}|{{repositoryName}}> #{{runNumber}}'
const footerTemplate = Handlebars.compile(opts?.footer || defaultFooter)

slack/src/slack.ts

Lines 334 to 359 in c97e3fd

const attachments: MessageAttachment[] = [
{
mrkdwn_in: ['pretext' as const, 'text' as const, 'fields' as const],
color: jobColor(jobStatus, opts?.colors),
pretext,
author_name: sender?.login,
author_link: sender?.html_url,
author_icon: sender?.avatar_url,
title,
title_link: opts?.title_link,
text,
fields,
fallback,
footer,
footer_icon: DEFAULT_FOOTER_ICON,
ts: ts.toString()
}
]
if (opts?.blocks) {
attachments.push({
color: jobColor(jobStatus, opts?.colors),
fallback,
blocks
})
}

The feature i propose is omit the default values and only build the message with blocks.

Github actions has depricated Node 12 support, please upgrade to node 16

Is your feature request related to a problem? Please describe.
Github action workflows have started outputting messaging around actions that are still Node 12 which fell out of support in April 2022.

image

In this blog post github outlines their plan to deprecate and remove Node 12 support
https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/

Describe the solution you'd like
I'd like to see the slack action upgraded to node 16 so these warnings go away

How to send notification on matrix runs

At the moment the matrix runs are triggering a notification for each run and the steps: ${{ toJson(steps) }} ends up having many steps marked ๐Ÿšซ and only the specific matrix run with โœ”๏ธ

image

Any idea how to filter and only report the current path in the slack notification.

name: Build packages

on:
  workflow_dispatch:
  push:
    tags:
      - '*'

jobs:

  build-packages:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        image-name:
          - cake-api
          - frontend
          - chatapp
          - landing
          - nginx-proxy

    env:
      IMAGE_NAME: ${{ matrix.image-name }}
      SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

    steps:
    - uses: actions/checkout@v2

    - name: Build frontend
      id: build-frontend
      if: ${{ matrix.image-name == 'frontend' }}
      run: docker build ./web/frontend/ --file ./web/frontend/Dockerfile

    - name: Build chatapp
      id: build-chatapp
      if: ${{ matrix.image-name == 'chatapp' }}
      run: docker build ./web/chatapp/ --file ./web/chatapp/Dockerfile

#   ...

    - name: Push image to GitHub Container Registry
      id: push-images-container-registry
      run: 

    - uses: act10ns/slack@v1
      with:
        status: ${{ job.status }}
        steps: ${{ toJson(steps) }}
      if: always()

Handle Slack errors

Hello,

One of our jobs has this as the last step:

    - uses: act10ns/slack@v1
      with:
        status: ${{ job.status }}
        channel: '#build-notifications'
      if: always()

In one build, this step failed with a following error:

Error: A request error occurred: read ECONNRESET
Error: Error: A request error occurred: read ECONNRESET
    at Object.requestErrorWithOriginal (/home/runner/work/_actions/act10ns/slack/v1/dist/index.js:2694:33)
    at IncomingWebhook.send (/home/runner/work/_actions/act10ns/slack/v1/dist/index.js:2584:32)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

As a result:

  • Our deployment has actually finished okay
  • This job failed
  • We haven't received a notification about either of those

I do understand that this particular error is caused by the Slack API, but the outcome is so confusing that I decided to create this issue anyway. Looking at your code, there is no error handling around IncomingWebhook.send call. I don't know if that would help, but maybe you know a way to prevent this from happening.

The best thing which comes to my mind is some basic retry strategy, which is only triggered whenever network errors like this one occur (ignoring the normal Slack errors). Something like promise-retry may be helpful.

Not able to send the notification with "blocks" data from YML file

use the YML file with both blocks and fields as slack message template. Integrate this with github actions. Only, receiving the message with fields.

To Reproduce
use https://github.com/act10ns/slack/blob/master/__tests__/fixtures/slack-blocks.yml as a slack message template while integrate with the github.
Expected behavior
need to receive two massages, one with fields and second with blocks

FYI:
This is working as expected with unit test cases

message workflow status

Is your feature request related to a problem?

at this moment the messaging is covering single job steps and talking about its status. I am wondering if it would be possible (and if it is even possible now so pls add an example) over on a higher level and repost on the success of particular jobs in the workflow.

Describe the solution you'd like

We have some Release workflow which consists of several jobs which can be depending internally...
image
It would be great to have a single slack message that would summarise the workflow status when it ends

Describe alternatives you've considered

Additional context

Add an alternative for env.SLACK_WEBHOOK_URL for reusable workflows

Is your feature request related to a problem? Please describe.

I was trying to break down long github workflow using reusable workflow. However, act10ns/slack does only support env.SLACK_WEBHOOK_URL as environment variable while reusable workflow is missing that context and has only inputs & secrets.

Describe the solution you'd like

If possible to have an alternative way to set SLACK_WEBHOOK_URL using secrets which kind of common or through direct parameter with:

Describe alternatives you've considered

Currently, no workaround it. I just keep single file for whole process.

Additional context

No

Config file (slack.yml) not apply the layout message

Describe the bug
When I used the example above, I got the same template default of actions inside the slack, so I try to set the config example for testing and custom issues, some like slack.yml in the readme page. In the example bellow, Im tested this code.

      - name: Report Status
        uses: act10ns/[email protected]
        with: 
          status: ${{ job.status }}
          steps: ${{ toJson(steps) }}
          config: .github/config/slack.yml
        if: always()
        env:
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_ACTIONS_WEBHOOK }}
          ACTIONS_RUNNER_DEBUG: true
          ACTIONS_STEP_DEBUG: true

the slack.yml

username: GitHub-CI
icon_url: https://octodex.github.com/images/mona-the-rivetertocat.png

pretext: Triggered via {{eventName}} by {{actor}} {{default action "action"}} {{ref}} `{{diffRef}}`
title: GitHub Actions
title_link: https://support.github.com

text: &text |
  *<{{workflowRunUrl}}|Workflow _{{workflow}}_ job _{{jobName}}_ triggered by _{{eventName}}_ is _{{jobStatus}}_>* for <{{refUrl}}|`{{ref}}`>
  {{#if description}}<{{diffUrl}}|`{{diffRef}}`> - {{{description}}}{{/if}}
  {{#if payload.commits}}
  *Commits*
  {{#each payload.commits}}
  <{{this.url}}|`{{truncate this.id 8}}`> - {{this.message}}
  {{/each}}
  {{/if}}

fallback: |-
  [GitHub] {{workflow}} #{{runNumber}} {{jobName}} is {{jobStatus}}

fields:
  - title: Job Steps
    value: |-
      {{#each jobSteps}}{{#ifneq this.outcome 'skipped'}}{{icon this.outcome}} {{@key}}
      {{/ifneq}}{{/each}}
    short: false

blocks:
  # author
  - type: context
    elements:
    - type: image
      image_url: '{{{sender.avatar_url}}}'
      alt_text: '{{sender.login}}'
    - type: mrkdwn
      text: "*<{{sender.html_url}}|{{sender.login}}>*"

  # title
  - type: section
    text:
      type: mrkdwn
      text: |
        *<{{title_link}}|{{title}}>*

  # text
  - type: section
    text:
      type: mrkdwn
      text: *text

  # fields
  - type: section
    fields:
    - type: mrkdwn
      text: |-
        *Job Steps*
        {{#each jobSteps}}{{#ifneq this.outcome 'skipped'}}{{icon this.outcome}} {{@key}}
        {{/ifneq}}{{/each}}
  - type: section
    fields:
    - type: mrkdwn
      text: "*Workflow*\n<{{{workflowUrl}}}|{{workflow}}>"
    - type: mrkdwn
      text: "*Git Ref*\n{{ref}} ({{refType}})"
    - type: mrkdwn
      text: |-
        *Run ID*
        <{{workflowRunUrl}}|{{runId}}>
    - type: mrkdwn
      text: "*Run Number*\n{{runNumber}}"
    - type: mrkdwn
      text: "*Actor*\n{{actor}}"
    - type: mrkdwn
      text: "*Job Status*\n{{jobStatus}}"

  # footer
  - type: context
    elements:
    - type: image
      image_url: '{{footer_icon}}'
      alt_text: satterly
    - type: mrkdwn
      text: '{{{footer}}} | <!date^{{ts}}^{date_short_pretty} at {time}|{{ts}}>'

footer: >-
  <{{repositoryUrl}}|{{repositoryName}}> {{workflow}} #{{runNumber}}

colors:
  success: '#5DADE2'
  failure: '#884EA0'
  cancelled: '#A569BD'
  default: '#7D3C98'

icons:
  success: ':white_check_mark:'
  failure: ':grimacing:'
  cancelled: ':x:'
  skipped: ':heavy_minus_sign:'
  default: ':interrobang:'

Screenshots
If applicable, add screenshots to help explain your problem.
slack_result_text

Add commit messages

It may be a nice enhancement to add the commit messages into the slack notification.

Loading slack.yml config file from .github/config directory

Describe the bug

The problem is that the action cannot load the configuration file from any directory outside of .github/workflows. Consequently, when the configuration file is placed within the 'workflows' directory, it triggers an error within GitHub actions due to a deviation from the expected workflow syntax.
No event triggers defined in "on"

To Reproduce

  1. Create a 'slack.yml' configuration file and locate it within the .github/config directory.
  2. Attempt to utilize the configuration file with the associated action.

Expected behavior

Ideally, users should have the flexibility to position the configuration file outside of the 'workflows' directory without encountering any issues.

Screenshots

In the following screenshots, you can observe the contrast between placing the configuration file in directories other than .github/workflows and adhering to the 'workflows' directory:

By putting the config file in any directory other than the .github/workflows, the action can not read config template!

      # Step 14: Post breaking changes to a Slack channel
      - name: Post breaking changes to a Slack channel
        env:
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
        uses: act10ns/slack@v1
        with:
          status: complete
          channel: "#sci-design-system-breaking-changes"
          config: .github/config/slack.yml
        if: contains(toJson(github.event.commits.*.message), 'BREAKING CHANGE')
Screenshot 2023-09-01 at 9 31 33 PM

The message is constructed based on the template by putting the config file in the .github/workflows directory.

      # Step 14: Post breaking changes to a Slack channel
      - name: Post breaking changes to a Slack channel
        env:
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
        uses: act10ns/slack@v1
        with:
          status: complete
          channel: "#sci-design-system-breaking-changes"
          config: .github/workflows/slack.yml
        if: contains(toJson(github.event.commits.*.message), 'BREAKING CHANGE')
Screenshot 2023-09-01 at 9 32 36 PM

Desktop (please complete the following information):

  • OS: macOS Ventura 13.5.1
  • Browser: Chrome
  • Version: 116.0.5845.110 (Official Build) (arm64)

I appreciate your attention to this matter and kindly request assistance in resolving this issue to enhance the functionality and usability of the package.

Always Questionmark

There is always a question mark in front independent of the state of the step.
Do I do anything wrong if I just copy the example code, and give every step an id?

image

An HTTP error occured: statusCode = 500

Describe the bug
Build fails when trying to run this action, even though i get slack notifications for the build, it was working fine yesterday but suddenly stopped working. I'm not using a custom slack.yml config, but the action is trying to find one anyways.
To Reproduce
Steps to reproduce the behavior:

Start a deployment build

Expected behavior
The slack notification should be shown and the build should continue to other actions

Screenshots
image

Desktop (please complete the following information):

  • OS: Ubuntu 20.04
  • Browser N/A
  • Version: tested on v1 and v1.5.0

Smartphone (please complete the following information):

  • Device: N/A
  • OS: N/A
  • Browser N/A
  • Version: N/A

Additional context
Was working fine till yesterday, stopped working without any changes to configuration today.

error when running locally with act

Just added this to my workflow and running it locally with act and I got this error:

TypeError: Cannot read property 'replace' of undefined%0A    at Object.<anonymous> (/run/act/actions/[email protected]/dist/index.js:6832:35)%0A    at Generator.next (<anonymous>)%0A    at /run/act/actions/[email protected]/dist/index.js:6760:71%0A    at new Promise (<anonymous>)%0A    at module.exports.570.__awaiter (/run/act/actions/[email protected]/dist/index.js:6756:12)%0A    at Object.send [as default] (/run/act/actions/[email protected]/dist/index.js:6788:12)%0A    at /run/act/actions/[email protected]/dist/index.js:1427:38%0A    at Generator.next (<anonymous>)%0A    at /run/act/actions/[email protected]/dist/index.js:1401:71%0A    at new Promise (<anonymous>)

Which seems to point to this: https://github.com/act10ns/slack/blob/master/dist/index.js#L6832

Broken link in Slack message

Describe the bug
The message posted to Slack when my workflow finishes links to a URL of the following form:

https://github.com/<owner>/<repo>/actions?query=<workflow-name>

However, it appears that Github have changed its URLs for actions such that the appropriate URL is now:

https://github.com/<owner>/<repo>/actions/workflows/<workflow-filename>.yml

To Reproduce
Steps to reproduce the behavior:

  1. Run a workflow using act10ns/slack@v1.
  2. Click on the link in the message posted to Slack.

Expected behavior
I expect to be taken to a page listing recent runs of the appropriate workflow. (I'd prefer to be taken to the run that triggered the message, but that's a separate feature request.)

Screenshots
N/A

Desktop (please complete the following information):
N/A

Smartphone (please complete the following information):
N/A

Additional context
None.

As node 16 is deprecated, can you upgrade to node 20?

Is your feature request related to a problem? Please describe.
The package currently emites deprecation message during CI

Describe the solution you'd like
Update to use node 20

Describe alternatives you've considered
None.

can't able to tag users or user groups in alerts

Describe the bug
We want to tag users and user groups in every git-hub action failure alert , but couldn't able to do it , even tried with custom flags , not working ,
Please help on this .

To Reproduce
Steps to reproduce the behavior:

  1. create yml file under workflow ex- test.yml
  2. Use below sample code for failure alert
  3. Push changes to git

name: Test

on:
push:
branches:
- test-branch

jobs:
Test:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.18
uses: actions/setup-go@v2
with:
go-version: 1.181

  - name: Notify slack in case of failure
    if: failure()
    env:
      SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
    uses: act10ns/slack@v1
    with:
      channel: '#test-slack'
      status: ${{ job.status }}
      steps: ${{ toJson(steps) }}
      color: danger

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Custom message not working

Hi,
I tried using latest version as follows

      - uses: act10ns/slack@master
        with:
          channel: "#cloud-builds"
          status: ${{ job.status }}
          message: Successfully deployed to ${{ env.ENVIRONMENT }}!
        if: always()

But I don't get the message as expected
image

Github action output:
image

What is the correct formatting for `actions` blocks?

I'm trying to add a button to my message utilizing the actions block, like so:

blocks:
  - type: actions
    elements:
      - type: button
        text:
          type: plain_text
          emoji: true
          text: ":github: View"

However, when I add this, my action fails with a An HTTP protocol error occurred: statusCode = 400 error. I assume something about the formatting here is what's causing the action to fail (and the message to not be sent), but since your docs do not specify the formatting for blocks, I'm left to guess based on your slack.yml file in this repository (which doesn't demonstrate actions blocks).

Steps coming out ugly

I've added your lovely plugin to our build as advised in the readme, but we're seeing something a bit disappointing in the "steps" output in Slack:

image

Any idea what we're doing wrong?

Provide status for multiple jobs with steps

Is your feature request related to a problem? Please describe.
It seems that this action allows to send status only for steps. This might create noise in the chat history

Describe the solution you'd like
I want to have the following yml configuration and send the message to slack once when all jobs have been finished with failure or success

jobs:
  format:
     steps:
  test:
     steps:
  build:
     steps:
  notify:
    needs: [format, test, build]
    steps:
      send status message to slack preferably including the artifact links generated during the build step
      instead of the status of steps provide the status of jobs
      eg
      format - ok
      test - fail
      build - fail

Describe alternatives you've considered
https://github.com/technote-space/workflow-conclusion-action
It does what I'm asking for but no longer maintained

How to retrieve the `outcome` from previous (or target specific) steps ID

Is your feature request related to a problem? Please describe.
Is it possible to retrieve the outcome steps inside .github/slack.yml

Describe the solution you'd like

    - type: section
    fields:
      - type: mrkdwn
        text: "${{ fromJson(steps.get-step-detail.outputs.result).name }}" # how to retrieve it w/o having to looping(?)
      - type: mrkdwn
        text: 'URL: ${{ steps.build-and-publish.outputs.internal-sharing-app-url }}' # similar

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

[FEATURE/IMPROVEMENT] display the step name instead of id

**Is your feature request related to a problem? **

Here my workflow :

  build:
    runs-on: ubuntu-latest
    steps:
      - name: ๐Ÿ”„ Checkout ๐Ÿ”„
        uses: actions/[email protected]
        id: checkout
      - name: ๐Ÿšง Setup JDK 11 ๐Ÿšง
        id: setup_jdk11
        uses: actions/setup-java@v3
        with:
          java-version: '11'
          distribution: 'adopt'ion for gradlew
      - name: ๐Ÿ”ง Build ๐Ÿ”ง
        id: gradle_build
        run: ./gradlew build jacocoTestReport sonar --info
      - name: ๐Ÿ“ฃ Report to slack ๐Ÿ“ฃ
        uses: act10ns/slack@v2
        with:
          status: ${{ job.status }}
          steps: ${{ toJson(steps) }}
        if: always()

Then the results in slack
image

As you can see it's displaying the task id which have some limitations because it's an id

Describe the solution you'd like

Displaying the name of the task will be nicer and allow me more customization (emoji ...)

Can't use env in config file

Describe the bug
Can't not use env in slack.yml

To Reproduce

  1. Add env to action https://github.com/darwinia-network/apps-lite/blob/915e6b2a0333e75a8f9e33cd6326c1ce1f7a772c/.github/workflows/deploy-dev.yml#L54
  2. Read env from slack.yml https://github.com/darwinia-network/apps-lite/blob/915e6b2a0333e75a8f9e33cd6326c1ce1f7a772c/.github/config/slack-vercel.yml#L88
  3. https://github.com/darwinia-network/apps-lite/runs/4824566165?check_suite_focus=true#step:9:10

Expected behavior
Can read this env from slack.yml

Screenshots
image

Additional context
I'm tested use default slack.yml it works, read from env happened this error.

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.