Skip to content

Latest commit

 

History

History
163 lines (111 loc) · 4.34 KB

README.md

File metadata and controls

163 lines (111 loc) · 4.34 KB

Slack Github Actions

A no-config GitHub action that notifies slack of the status of your GitHub actions

Demo

Supported Triggers

We currently support:

  • pull_request
  • release
  • push (tags, commits)
  • schedule
  • create (branch)
  • delete (branch)

Messages

All event messages will have these elements:

Base Image

  1. Build Indicator - Will be green for successful, red for failed, yellow for cancelled
  2. Author Github Profile and User - This is also a link their profile page
  3. Workflow Name - Also a link to the run
  4. Repository Name - Also a link
  5. Timestamp

Pull Requests

Pull Request

  1. Commit Hash - Also a link showing the changes between the base and ref
  2. Pull Request Number and Title - Also a link to the Pull Request

Releases

Release

  1. Commit Hash - Also a link showing all changes in the release
  2. Release Title - Also a link to the release and notes. If the release doesn't have a title the tag name will be used.

Tags

Tag

  1. Commit Hash - Also a link showing all changes since this tag and master
  2. Tag name - Also a link to the tag

Commits

Commits

  1. Commit Hash - Also a link showing combined changes of all commits for the push
  2. Head Commit name - Name of last commit in the batch (can push multiple commits). Also a link to that commit.

Schedule

Schedule

Note that Schedule does not have the user as there's no commit information.

Create

Create

  1. Branch Name - Also link to the branch.

Delete

Delete

  1. Branch Name

Usage

You can use this action after any other action, however I recommend you put it as the last one. Here is an example setup of this action for a pull request:

  1. Create a .github/workflows/test.yml file in your GitHub repo.
  2. Add the following code to the test.yml file.
name: Test

on:
  pull_request:
    branches:
      - master

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - run: npm install
      - run: npm test

      - uses: iRoachie/[email protected]
        env:
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
        with:
          status: ${{ job.status }}
        if: ${{ always() }}
  1. Create SLACK_WEBHOOK_URL secret using GitHub Action's Secret. You can generate a Slack incoming webhook token from here.

Advanced Usage

Here's an example with jobs that run in parallel.

It does a few things:

  • Lets us know when a status check didn't succeed
  • If all jobs were successful, we'll send a message at the end

Note that the status variable is omitted here.

name: Test

on:
  pull_request:
    branches:
      - master

jobs:
  test:
    name: Jest
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - run: yarn
      - run: yarn test

  lint:
    name: Eslint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - run: yarn
      - run: yarn lint

  notify:
    Name: Slack
    needs: [test, lint] # We only check after the others jobs have run
    if: always() # Always runs even if one of the builds fails
    runs-on: ubuntu-latest
    steps:
      - uses: iRoachie/[email protected]
        env:
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}