Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed alert msg to be sent to a slack webhook. #1929

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/actions/slack-webhook-sender/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: slack-webhook-sender
description: 'Sends a slack message plus some more workflow job related fields to a slack webhook endpoint.'
inputs:
message:
description: 'Text that will be send in the json .message field.'
required: true
default: 'Hello, world!'
slack_webhook:
description: 'Slack webhook where the data will be posted.'
required: true
default: ''

runs:
using: 'composite'
steps:
- name: Post message data to slack's webhook url.
shell: bash
env:
MESSAGE: ${{ inputs.message }}
REPO_URL: 'https://github.com/${{ github.repository }}'
COMMIT_URL: 'https://github.com/${{ github.repository }}/commit/${{ github.sha }}'
JOB_URL: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}'
ATTEMPT: ${{ github.run_attempt }}
run: |
data="{ \
\"message\" : \"${MESSAGE}\", \
\"repo_url\" : \"${REPO_URL}\", \
\"job_url\" : \"${JOB_URL}\", \
\"commit_url\": \"${COMMIT_URL}\", \
\"attempt\" : \"${ATTEMPT}\" \
}"

echo "Sending alert message data to slack webhook: $(echo $data | jq)"
curl -X POST --data "${data}" -H 'Content-type: application/json; charset=UTF-8' '${{ inputs.slack_webhook }}'
13 changes: 4 additions & 9 deletions .github/workflows/pre-main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -467,15 +467,10 @@ jobs:

- name: (if on main and upstream) Send chat msg to dev team if failed to create container image.
if: ${{ failure() && github.ref == 'refs/heads/main' && github.repository_owner == 'test-network-function' }}
env:
COMMIT_SHA: ${{ github.sha }}
JOB_RUN_ID: ${{ github.run_id }}
JOB_RUN_ATTEMPT: ${{ github.run_attempt }}
GITHUB_REPO: https://github.com/test-network-function/cnf-certification-test
run: |
curl -X POST --data "{
\"text\": \"🚨⚠️ Failed to create \`unstable\` container image 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\> \"
}" -H 'Content-type: application/json; charset=UTF-8' '${{ secrets.GCHAT_WEBHOOK_URL }}'
uses: ./.github/actions/slack-webhook-sender
with:
message: 'Failed to create the *unstable* container image'
slack_webhook: '${{ secrets.SLACK_ALERT_WEBHOOK_URL }}'

# Push the new unstable TNF image to Quay.io.
- name: (if on main and upstream) Authenticate against Quay.io
Expand Down
13 changes: 4 additions & 9 deletions .github/workflows/tnf-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,7 @@ jobs:

- name: If failed to create the image, send alert msg to dev team.
if: ${{ failure() }}
env:
COMMIT_SHA: ${{ github.sha }}
JOB_RUN_ID: ${{ github.run_id }}
JOB_RUN_ATTEMPT: ${{ github.run_attempt }}
GITHUB_REPO: 'https://github.com/${{ github.repository }}'
run: |
curl -X POST --data "{
\"text\": \"🚨⚠️ Failed to create container image version \`$TNF_VERSION\` 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\> \"
}" -H 'Content-type: application/json; charset=UTF-8' '${{ secrets.GCHAT_WEBHOOK_URL }}'
uses: ./.github/actions/slack-webhook-sender
with:
message: 'Failed to create official container image version ${{ env.TNF_VERSION }}'
slack_webhook: '${{ secrets.SLACK_ALERT_WEBHOOK_URL }}'
Loading