Coder Social home page Coder Social logo

adjust / github-actions-slack Goto Github PK

View Code? Open in Web Editor NEW

This project forked from act10ns/slack

0.0 2.0 1.0 1.75 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 97.04% JavaScript 0.90% Makefile 2.06%
automate github-actions

github-actions-slack's Introduction

build-test

Slack messages for GitHub Action workflows, jobs and steps

A simple and flexible Slack integration with GitHub Actions.

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)

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.

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

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@v1
  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@v1
  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@v1
  with: 
    status: ${{ job.status }}
    channel: '#workflows'

or

- uses: act10ns/slack@v1
  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@v1
        with:
          status: starting
          channel: '#workflows'
        if: always()
      - name: Checkout
        uses: actions/checkout@v2
      - 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@v1
        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 Nick Satterly. Available under the MIT License.

github-actions-slack's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar qlimaxx avatar satterly avatar

Watchers

 avatar  avatar

Forkers

isabella232

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.