Skip to content

Commit

Permalink
feat(CI-SLACK): add slack notification if tests crash
Browse files Browse the repository at this point in the history
  • Loading branch information
KristenPire committed Mar 15, 2022
1 parent 2b711b8 commit b78d794
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
30 changes: 30 additions & 0 deletions .github/slack/failed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"channel": "${SLACK_CHANNEL}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":red_circle: *${GITHUB_WORKFLOW} failed*"
}
},

{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "*Started by:* ${GITHUB_ACTOR}"
},
{
"type": "mrkdwn",
"text": "*Commit:* ${GITHUB_REF} @ ${GITHUB_SHA}"
},
{
"type": "mrkdwn",
"text": "*Details at:* ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
}
]
}
]
}
24 changes: 23 additions & 1 deletion .github/workflows/testOnPush.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Test on Push
on: [push]

jobs:
build:
test:
runs-on: ubuntu-latest

steps:
Expand All @@ -21,3 +21,25 @@ jobs:

- name: Run test
run: make ci-test

notify:
name: Notify Slack on failure
needs: [test]
if: ${{ failure() }}
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: envsubst
uses: mshick/fast-envsubst@v1
with:
in-file: .github/slack/failed.json
out-file: payload.json

- name: Send slack message
env:
TOKEN: ${{ secrets.SLACK_TOKEN }}
run: |
curl -H "Authorization: Bearer $TOKEN" -H "Content-type: application/json" -d @payload.json -XPOST https://slack.com/api/chat.postMessage

0 comments on commit b78d794

Please sign in to comment.