Skip to content

Commit

Permalink
testing slack notification (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
MSevey committed Jul 31, 2023
1 parent 84d7d3c commit a2697f6
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/ci_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,35 @@ jobs:
# docker_password: ${{ secrets.DOCKER_PASSWORD}}
# docker_repository: <update>
# semver_version: ${{ needs.release.outputs.new_version }}

# notify-slack-on-failure will send a message to slack if the workflow fails.
# This shows how to use the reusable workflow. Below is how to call it directly.
notify-slack-on-failure:
needs: [yamllint, markdown-lint]
# Always run, regardless of job failures, only run on main/master branches.
if: always() && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main')
secrets: inherit
uses: ./.github/workflows/reusable_notify_slack.yml

# Option for directly calling the workflow
# notify-slack-on-failure:
# needs: [yamllint, markdown-lint]
# if: always()
# # if: always() && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main')
# runs-on: ubuntu-latest
# steps:
# # run this action to get the workflow conclusion
# # You can get the conclusion via env (env.WORKFLOW_CONCLUSION)
# - uses: technote-space/workflow-conclusion-action@v3

# - name: Notify Slack On Failure
# uses: ravsamhq/notify-slack-action@v2
# with:
# status: ${{ env.WORKFLOW_CONCLUSION }}
# token: ${{ secrets.GITHUB_TOKEN }}
# notification_title: "{workflow} has {status_message}"
# message_format: "{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}> : <{run_url}|View Run Results>"
# footer: ""
# notify_when: "failure"
# env:
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_RELEASE_CHANNEL }}
36 changes: 36 additions & 0 deletions .github/workflows/reusable_notify_slack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: "Notify Slack"
on:
workflow_call:

# This is a reuable workflow instead of a composite action so that we can
# inherit secrets and reduce the inputs to zero.

jobs:
stale:
runs-on: ubuntu-latest
steps:
# run this action to get the workflow conclusion
# You can get the conclusion via env (env.WORKFLOW_CONCLUSION)
#
# NOTE: it is important that we use the workflow conclusion, otherwise the
# job status will always be successful since it is just the job of notifying
# slack.
- uses: technote-space/workflow-conclusion-action@v3

- name: Notify Slack On Failure
uses: ravsamhq/notify-slack-action@v2
with:
status: ${{ env.WORKFLOW_CONCLUSION }}
token: ${{ secrets.GITHUB_TOKEN }}
# These fields could be updated to be inputs, but that might make the
# reuseable action less useful since it there wouldn't be much
# refactored.
notification_title: "{workflow} has {status_message}"
message_format: "{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}> : <{run_url}|View Run Results>"
footer: ""
notify_when: "failure"
env:
# This could be updated to a more generic name that repos could set as a
# way to customize which channel they are reporting to. Currently this
# is an org level secret.
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_RELEASE_CHANNEL }}

0 comments on commit a2697f6

Please sign in to comment.