GithubHelp home page GithubHelp logo

isabella232 / slack-action Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ledgerhq/slack-action

0.0 0.0 0.0 901 KB

Send fully custom slack messages

License: MIT License

JavaScript 1.03% TypeScript 98.97%

slack-action's Introduction

slack-action

Build

Send custom slack messages given a slack block template

Usage

- uses: Brymastr/slack-action@v1
  name: Slack notification
  env:
    SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
  with:
    template: './template.json'
    example_key1: example value 1
    job_status: ${{ job.status }}

template.json

{
  "blocks": [
    {
      "type": "section",
      "text": {
        "type": "mrkdwn",
        "text": "Example: {{ example_key1 }} and {{ job_status }}"
      }
    }
  ]
}

Use of this action requires a GitHub secret called SLACK_WEBHOOK. The value should include the channel id and look something like one of these:

  • https://hooks.slack.com/services/11111ZZZZ/22222XXXX/1a2B3c4e5F6G7h8I9j0k
  • 11111ZZZZ/22222XXXX/1a2B3c4e5F6G7h8I9j0k

See Creating and using encrypted secrets for assistance with GitHub Secrets.

See Sending messages using Incoming Webhooks for assistance with Slack Webhooks.

Required Arguments

  • SLACK_WEBHOOK - provided as an env variable, this is the full webhook url for your bot channel.
  • template - provided in the with args, is the path to the message template json file. This path should be relative from the project root.

Optional Arguments

Any other custom arguments can be provided and will be included in the template. From the example above all occurrences of {{ example_key1 }} in the template.json file will be replace with example value 1.
NOTE: template names in the json file must be lower case.

Default and Computed Properties

Most github context properties are included by default without needing to pass them in through a with argument. Some properties have been renamed to make a bit more sense. See Contexts for more info.

Property Name Replacement Variable
github.sha commit
github.repository repo
github.ref ref
github.ref_name ref_name
github.head_ref head_ref
github.base_ref base_ref
github.actor actor
github.event_name event
github.workflow workflow

In addition to these github context properties there are 5 computed properties that could be useful

Replacement Variable Description
repo_url the URL of the github repo
branch_url the URL of the github repo with branch
actions_url the URL of the github actions workflow run for the commit
run_url the URL of the github actions workflow run
title Notification title

Notes

Check out the examples directory for some examples

Try the Slack Block Kit Builder for message template inspiration

Motivation

Slack notifications are a common feature in automated build pipelines. There are already a few existing GitHub Actions that send slack messages but most use a predetermined format and only allow for title or subject customization. This action allows for full block customization. I would like this action to serve as a simple, solid, and customizable slack notification action with as few dependencies as possible.

Alternatives

slack-action's People

Contributors

brymastr avatar pavlogs avatar ypolishchuk-ledger avatar dependabot[bot] avatar

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.