Coder Social home page Coder Social logo

8398a7 / action-slack Goto Github PK

View Code? Open in Web Editor NEW
582.0 5.0 131.0 6.37 MB

Provides the function of slack notification to GitHub Actions.

Home Page: https://action-slack.netlify.app/

License: MIT License

TypeScript 97.73% JavaScript 0.75% Shell 1.52%
github-actions slack typescript

action-slack's Introduction

action-slack

Netlify Status codecov

Quick Start

You can learn more about it here.

steps:
  - uses: 8398a7/action-slack@v3
    with:
      status: ${{ job.status }}
      fields: repo,message,commit,author,action,eventName,ref,workflow,job,took,pullRequest # selectable (default: repo,message)
    env:
      SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
    if: always() # Pick up events even if the job fails or is canceled.

success

Custom Formats of your choice

You can learn more about it here.

steps:
  - uses: 8398a7/action-slack@v3
  with:
    status: custom
    fields: workflow,job,commit,repo,ref,author,took
    custom_payload: |
      {
        attachments: [{
          color: '${{ job.status }}' === 'success' ? 'good' : '${{ job.status }}' === 'failure' ? 'danger' : 'warning',
          text: `${process.env.AS_WORKFLOW}\n${process.env.AS_JOB} (${process.env.AS_COMMIT}) of ${process.env.AS_REPO}@${process.env.AS_REF} by ${process.env.AS_AUTHOR} ${{ job.status }} in ${process.env.AS_TOOK}`,
        }]
      }
  env:
    SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
  if: always() # Pick up events even if the job fails or is canceled.

custom

For GitHub Enterprise

steps:
  - uses: 8398a7/action-slack@v3
    with:
      github_base_url: https://your.ghe.com # Specify your GHE
      status: ${{ job.status }}
      fields: repo,message,commit,author,action,eventName,ref,workflow,job,took,pullRequest
    env:
      SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
    if: always()

Require Permissions

If you are explicitly specifying permissions, must grant contents and actions.

permissions:
  contents: read
  actions: read

action-slack's People

Contributors

8398a7 avatar autopp avatar case avatar cruzmolina avatar dependabot[bot] avatar dimisjim avatar dyoshikawa avatar hwood-fg avatar ignigena avatar justanotherdev avatar kennysoft avatar masakinpo avatar nileshr avatar nowsprinting avatar roryabraham avatar sethuk07 avatar sethumadhav07 avatar simi avatar smknstd avatar tarumzu avatar tchssk avatar technote-space avatar teebu avatar triffer 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  avatar  avatar

action-slack's Issues

pull request の場合の action のリンク

概要

merge ref の sha が対象になっているため、スクリーンショットのようにアクションの結果が見れない

考えうる解決方法

head ref の sha を対象にする

スクリーンショット

merge ref

for v2

Check the value entered in status at fail / cancel.

Optional GITHUB_TOKEN

I'm using the custom status to create my own slack message. Since I'm doing that it doesn't need the GITHUB_TOKEN. Would it be possible to make it optional for custom messages?

default fields

To make it easier to understand, repo,commit is used as default fields

Compact format like travis

Ok, sad, but if you could add the time the job took and the compact (travis like) formatting I would be very happy.

Single quote in commit message causes an error

I got this error from a Slack integration that worked fine before:

##[error]Unexpected identifier

After a bit of digging, I realized that it was the fact that the first commit message of the branch had a single quote in it, which means the PR name also had it. It seems that action-slack doesn't escape the strings properly, and errors out.

This was on v2.

DeprecationWarning が発生する

概要

以下の Warning が発生する

[DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.

考えうる解決方法

色々調べてみましたが、原因は @slack/[email protected] が 使用している axios@^0.18.0 のようです。

axios/axios@787c808

先月修正されて 5.0.3 として公開されています。

slackapi/node-slack-sdk@47154eb

@slack/webhook を 5.0.3 に上げて確認しましたが、 Slackが正しく送信されることと Warning が発生しないことを確認しました。

no-warning

v3に向けて色々調整もあると思うので、様子を見てバージョンを上げてみてください。

(node:2623) [DEP0005] DeprecationWarning: Buffer() is deprecated

I'm using github actions with

    - uses: actions/[email protected]
      name: Installing packages
      with:
        node-version: '10.x'

Then I get this error:

Run 8398a7/[email protected]
  with:
    status: Success
    author_name: Build & Test
  env:
    GITHUB_TOKEN: ***
    SLACK_WEBHOOK_URL: ***
(node:2623) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
##[error]A request error occurred: connect ECONNREFUSED 127.0.0.1:80
##[error]Node run failed with exit code 1

support object path

It would be nice to be able to cut out the payload object as a separate file and read it at the time of custom notification

Setting Job Name in Action

Hi,

Firstly, thanks for the work here, it's awesome!

I wanted to ask about configuring the slack notification to add the name of the action that fails. I originally did the following:

      - if: 'failure()'
        name: Notify Slack
        uses: 8398a7/action-slack@v3
        with:
          text: ${{ job.name }}
          fields: repo,commit,author,action
          status: ${{ job.status }}

But that didn't print the test as part of the action.

Then I tried to override the author_name to be ${{ job.name }} but that hasn't worked either.

This is the final code I am working with right now:

      - if: 'failure()'
        name: Notify Slack
        uses: 8398a7/action-slack@v3
        with:
          author_name: ${{ job.name }}
          fields: repo,commit,author,action
          status: ${{ job.status }}

Any help here would be most appreciated

Thanks

Paul

Update npm modules

It's been a while since I updated the library.
The main goal is to make @actions/github v4 and make the context in the regular flow Getting.

refs: actions/toolkit#499

Breaking change in minor a update?

Why a breaking change was introduced in a minor update? This is very surprising, I was using the action field API but now it suddenly stopped working without me touching the major version of this action.
Minor versions should always be compatible with lower minor versions within the same major release.
Please refer to the semver spec item no 7. If you are not following the semver protocol, please state so explicitly in the docs.

The Took field is empty

I followed the steps from this link - action-slack but the overall build time (duration) is not visible in took field. What am I missing?

I tried adding MATRIX_CONTEXT: ${{ toJson(matrix) }} code but it didn't work as well. Maybe additional configurations for the matrix are not explained well. Is there a way to display it without using MATRIX_CONTEXT?

Screen Shot 2020-07-17 at 1 31 34 PM

Use variables inside payload

Hi,
How can I use the variables inside value from a custom notification?

I am trying to do something like this:

value: "deployed version GITHUB_SHA.",

What I am doing wrong?

Matrix seems to confuse action-slack...

For a workflow using a matrix like:

build:
strategy:
matrix:
os: [ubuntu-18.04, ubuntu-20.04]
runs-on: ${{ matrix.os }}

I get the fields AS_JOB and AS_TOOK undefined. See attached screenshot. Without matrix it all works fine.

Screen Shot 2020-06-29 at 10 05 20

Single notification for workflow

Is it possible to send a single notification for the entire workflow?

For example, if my workflow has multiple jobs running test suites and all of them fail, my Slack channel gets bombarded with notifications.

If my test suite fails, one notification is enough.

It would be nice for an option for something like "prevent sending if already sent".

payload conflict

action-slack can specify the payload in the with key.

- uses: 8398a7/action-slack@v2
  with:
    status: custom
    payload: {}

The payload was used only for status: custom, but in fact there was a value other than custom.
This seems to be the value that GitHub Actions automatically enters.

Since there are cases where you want to utilize the automatically inserted payload(#38), the action-slack needs to use the custom payload as an alias.
And action-slack needs v3 version to break compatibility.

Allow to mention user groups

According to Slack's documentation, in order to mention user group we need to follow the following syntax !subteam^ID.
I think this will be very easy to support, since mentioning special groups like here & channel is already supported. If we add check for subteam^ here, I think the rest should work fine.

I'm happy to take up this change if it seems okay.

Can do we do use mention with here or channel only, right?

I want to mention to a user in the channel

// example.yml
      - name: Notification to slack from QA checking code
        uses: 8398a7/action-slack@v2
        if: success() || failure()
        with:
          status: ${{ job.status }}
          author_name: ${{ github.repository }}
          mention: 'golf'
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

Legacy props are not working

When I use legacy props (like username, channel for example), theses options are not working.

As I see, you attach these property on attachments but as I know, they must be on the main root object :

author_name: this.with.author_name,

Get duration

Hi,
Would be great if I can show the duration time, is it possible?

Thanks!

Only send notification when build fail

Thank you for sharing your action-slack. I found it very simple to set up and meet our basic requirements.

I'm hoping for a bit more in a future release:
Can we have a way to selectively send notification - only send notification when build fails.

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.