Skip to content

Commit c5e8a49

Browse files
authored
Send alert msgs to the dev team's slack channel. (#427)
Updated github workflows to send alert msgs to the dev team's slack channel, similar to redhat-best-practices-for-k8s/certsuite#1929
1 parent 9672cf5 commit c5e8a49

File tree

3 files changed

+42
-18
lines changed

3 files changed

+42
-18
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: slack-webhook-sender
2+
description: 'Sends a slack message plus some more workflow job related fields to a slack webhook endpoint.'
3+
inputs:
4+
message:
5+
description: 'Text that will be send in the json .message field.'
6+
required: true
7+
default: 'Hello, world!'
8+
slack_webhook:
9+
description: 'Slack webhook where the data will be posted.'
10+
required: true
11+
default: ''
12+
13+
runs:
14+
using: 'composite'
15+
steps:
16+
- name: Post message data to slack's webhook url.
17+
shell: bash
18+
env:
19+
MESSAGE: ${{ inputs.message }}
20+
REPO_URL: 'https://github.com/${{ github.repository }}'
21+
COMMIT_URL: 'https://github.com/${{ github.repository }}/commit/${{ github.sha }}'
22+
JOB_URL: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}'
23+
ATTEMPT: ${{ github.run_attempt }}
24+
run: |
25+
data="{ \
26+
\"message\" : \"${MESSAGE}\", \
27+
\"repo_url\" : \"${REPO_URL}\", \
28+
\"job_url\" : \"${JOB_URL}\", \
29+
\"commit_url\": \"${COMMIT_URL}\", \
30+
\"attempt\" : \"${ATTEMPT}\" \
31+
}"
32+
33+
echo "Sending alert message data to slack webhook: $(echo $data | jq)"
34+
curl -X POST --data "${data}" -H 'Content-type: application/json; charset=UTF-8' '${{ inputs.slack_webhook }}'

.github/workflows/cnf-test-partner-image.yaml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,7 @@ jobs:
7777

7878
- name: If failed to create the image, send alert msg to dev team.
7979
if: ${{ failure() }}
80-
env:
81-
COMMIT_SHA: ${{ github.sha }}
82-
JOB_RUN_ID: ${{ github.run_id }}
83-
JOB_RUN_ATTEMPT: ${{ github.run_attempt }}
84-
GITHUB_REPO: 'https://github.com/${{ github.repository }}'
85-
run: |
86-
curl -X POST --data "{
87-
\"text\": \"🚨⚠️ Failed to create partner image version \`$IMAGE_TAG\` from commit \<$GITHUB_REPO/commit/$COMMIT_SHA|$COMMIT_SHA\>, job ID \<$GITHUB_REPO/actions/runs/$JOB_RUN_ID/attempts/$JOB_RUN_ATTEMPT|$JOB_RUN_ID\> \"
88-
}" -H 'Content-type: application/json; charset=UTF-8' '${{ secrets.GCHAT_WEBHOOK_URL }}'
80+
uses: ./.github/actions/slack-webhook-sender
81+
with:
82+
message: 'Failed to create debug parter image version ${{ env.IMAGE_TAG }}'
83+
slack_webhook: '${{ secrets.SLACK_ALERT_WEBHOOK_URL }}'

.github/workflows/debug-partner-image.yaml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,7 @@ jobs:
8787

8888
- name: If failed to create the image, send alert msg to dev team.
8989
if: ${{ failure() }}
90-
env:
91-
COMMIT_SHA: ${{ github.sha }}
92-
JOB_RUN_ID: ${{ github.run_id }}
93-
JOB_RUN_ATTEMPT: ${{ github.run_attempt }}
94-
GITHUB_REPO: 'https://github.com/${{ github.repository }}'
95-
run: |
96-
curl -X POST --data "{
97-
\"text\": \"🚨⚠️ Failed to create debug parter image version \`$IMAGE_TAG\` from commit \<$GITHUB_REPO/commit/$COMMIT_SHA|$COMMIT_SHA\>, job ID \<$GITHUB_REPO/actions/runs/$JOB_RUN_ID/attempts/$JOB_RUN_ATTEMPT|$JOB_RUN_ID\> \"
98-
}" -H 'Content-type: application/json; charset=UTF-8' '${{ secrets.GCHAT_WEBHOOK_URL }}'
90+
uses: ./.github/actions/slack-webhook-sender
91+
with:
92+
message: 'Failed to create debug parter image version ${{ env.IMAGE_TAG }}'
93+
slack_webhook: '${{ secrets.SLACK_ALERT_WEBHOOK_URL }}'

0 commit comments

Comments
 (0)