Skip to content

A github action that tells if I need to send a slack notification. It avoids spamming your notification channels with successful builds.

License

Notifications You must be signed in to change notification settings

Jimdo/should-i-notify-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Should I notify?

A GitHub action to decide if a status message should be pushed to slack for this build

WARNING: This action sends NO notification!

How it makes the decision

  1. If the current build failed, then it will recommend sending the message
  2. If the current build succeeded, and the previous one failed, then it will recommend sending the message
  3. If the current build succeeded, and the previous one succeeded, then it will recommend NOT sending the message

Inputs

needs_context

required json representation of the needs object in your context (toJson(needs))

branch

required The branch to get the status from

github_token

required A github token (secrets.GITHUB_TOKEN will suffice)

Outputs

should_send_message

yes|no depending on if the message should be sent

How to use

In this case, the action will take into account the result of job1 and job2 for builds only for the main branch.

job1:
  runs-on: ubuntu-latest
  steps:
    - uses: actions/checkout@v2
    - name: Run the script
      run: ./script1.sh
job2:
  runs-on: ubuntu-latest
  steps:
    - uses: actions/checkout@v2
    - name: Run the script
      run: ./script2.sh
      
slack-workflow-status:
  name: Post workflow status To Slack
  needs:
    - job1
    - job2
  if: always() && github.ref == 'refs/heads/main'
  runs-on: ubuntu-latest
  permissions:
    actions: read
  steps:
    - name: Determine if we need to notify
      uses: Jimdo/should-i-notify-action@main
      id: should_notify
      with:
        branch: main
        needs_context: ${{ toJson(needs) }}
        github_token: ${{ secrets.GITHUB_TOKEN }}

    - name: Slack workflow notification
      if: steps.should_notify.outputs.should_send_message == 'yes'
      uses: Gamesight/slack-workflow-status@master
      with:
        repo_token: ${{secrets.GITHUB_TOKEN}}
        slack_webhook_url: 'https://hooks.slack.com/services/...'
        channel: 'notifications-slack-channel'
        name: 'Your great build bot'

INFO: The documentation of slack-workflow-status action states that the action needs action: read permissions.

About

A github action that tells if I need to send a slack notification. It avoids spamming your notification channels with successful builds.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •