diff --git a/.github/slack/failed.json b/.github/slack/failed.json new file mode 100644 index 0000000..620d91c --- /dev/null +++ b/.github/slack/failed.json @@ -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}" + } + ] + } + ] +} diff --git a/.github/workflows/testOnPush.yml b/.github/workflows/testOnPush.yml index 30ecd1e..2f08ec1 100644 --- a/.github/workflows/testOnPush.yml +++ b/.github/workflows/testOnPush.yml @@ -3,7 +3,7 @@ name: Test on Push on: [push] jobs: - build: + test: runs-on: ubuntu-latest steps: @@ -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