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

ci(slackbot): clean up slack alerts #1272

Merged
merged 11 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
73 changes: 51 additions & 22 deletions .github/slack-templates/pipeline-failed.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,54 @@
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*:rotating_light: Pipeline failing for *${{ env.ENVIRONMENT }}* :rotating_light:*\n\nPlease check the workflow for more details."
}
},
{ "type": "divider" },
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Run"
},
"url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
"attachments": [
{
"color": "#FF0000",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "Github pipeline status",
"emoji": true
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Environment:* ${{ env.ENVIRONMENT }}"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Job Status:*\n• Infrastructure: ${{ env.INFRA_STATUS }}\n• Apps: ${{ env.APPS_STATUS }}\n• Slack Notifier: ${{ env.SLACK_NOTIFIER_STATUS }}\n• E2E Tests: ${{ env.E2E_TESTS_STATUS }}\n• Schema NPM: ${{ env.SCHEMA_NPM_STATUS }}\n• Publish: ${{ env.PUBLISH_STATUS }}"
}
]
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Please check the workflow for more details."
}
},
{
"type": "divider"
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Run"
},
"url": "${{ env.RUN_URL }}"
}
]
}
]
}
]
}
36 changes: 0 additions & 36 deletions .github/workflows/action-run-k6-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ on:
required: true
TOKEN_GENERATOR_PASSWORD:
required: true
SLACK_BOT_TOKEN:
required: true

jobs:
k6-test:
Expand Down Expand Up @@ -57,37 +55,3 @@ jobs:
action_fail: true
files: |
junit.xml

- name: Send Slack message on K6 test failure
if: always() && failure()
uses: slackapi/[email protected]
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID_FOR_K6_TESTS }}
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*:rotating_light: K6 Tests Failed for environment *${{ inputs.environment }}* :rotating_light:*\n\nPlease check the workflow for more details."
}
},
{ "type": "divider" },
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Run"
},
"url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
]
}
]
}
99 changes: 99 additions & 0 deletions .github/workflows/action-send-ci-cd-status-slack-message.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Send CI/CD Status Slack Message

on:
workflow_call:
inputs:
environment:
required: true
type: string
infra_status:
required: true
type: string
description: "Status of the infrastructure deployment job"
default: "skipped"
apps_status:
required: true
type: string
description: "Status of the apps deployment job"
default: "skipped"
slack_notifier_status:
required: true
type: string
description: "Status of the Slack notifier deployment job"
default: "skipped"
e2e_tests_status:
required: true
type: string
description: "Status of the end-to-end tests job"
default: "skipped"
schema_npm_status:
required: true
type: string
description: "Status of the schema npm publishing job"
default: "skipped"
publish_status:
required: true
type: string
description: "Status of the docker image publishing job"
default: "skipped"
secrets:
SLACK_BOT_TOKEN:
required: true
SLACK_CHANNEL_ID_FOR_RELEASES:
required: true
arealmaas marked this conversation as resolved.
Show resolved Hide resolved

jobs:
send-slack-message:
name: Send Slack message
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Determine status emojis
id: status-emojis
run: |
determine_emoji() {
case "$1" in
success)
echo ":white_check_mark:"
;;
failure)
echo ":x:"
;;
cancelled)
echo ":warning:"
;;
skipped)
echo ":heavy_minus_sign:"
;;
*)
echo "Invalid status: $1"
exit 1
;;
esac
}
echo "INFRA_EMOJI=$(determine_emoji '${{ inputs.infra_status }}')" >> $GITHUB_OUTPUT
echo "APPS_EMOJI=$(determine_emoji '${{ inputs.apps_status }}')" >> $GITHUB_OUTPUT
echo "SLACK_NOTIFIER_EMOJI=$(determine_emoji '${{ inputs.slack_notifier_status }}')" >> $GITHUB_OUTPUT
echo "E2E_TESTS_EMOJI=$(determine_emoji '${{ inputs.e2e_tests_status }}')" >> $GITHUB_OUTPUT
echo "SCHEMA_NPM_EMOJI=$(determine_emoji '${{ inputs.schema_npm_status }}')" >> $GITHUB_OUTPUT
echo "PUBLISH_EMOJI=$(determine_emoji '${{ inputs.publish_status }}')" >> $GITHUB_OUTPUT

arealmaas marked this conversation as resolved.
Show resolved Hide resolved
- name: Send GitHub slack message
id: slack
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
ENVIRONMENT: ${{ inputs.environment }}
RUN_URL: ${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}
# statuses
INFRA_STATUS: "${{ steps.status-emojis.outputs.INFRA_EMOJI }}"
APPS_STATUS: "${{ steps.status-emojis.outputs.APPS_EMOJI }}"
SLACK_NOTIFIER_STATUS: "${{ steps.status-emojis.outputs.SLACK_NOTIFIER_EMOJI }}"
E2E_TESTS_STATUS: "${{ steps.status-emojis.outputs.E2E_TESTS_EMOJI }}"
SCHEMA_NPM_STATUS: "${{ steps.status-emojis.outputs.SCHEMA_NPM_EMOJI }}"
PUBLISH_STATUS: "${{ steps.status-emojis.outputs.PUBLISH_EMOJI }}"
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID_FOR_RELEASES }}
payload-file-path: "./.github/slack-templates/pipeline-failed.json"
arealmaas marked this conversation as resolved.
Show resolved Hide resolved
32 changes: 15 additions & 17 deletions .github/workflows/ci-cd-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ jobs:
secrets:
TOKEN_GENERATOR_USERNAME: ${{ secrets.TOKEN_GENERATOR_USERNAME }}
TOKEN_GENERATOR_PASSWORD: ${{ secrets.TOKEN_GENERATOR_PASSWORD }}
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
with:
environment: test
apiVersion: v1
Expand All @@ -152,19 +151,18 @@ jobs:
pull-requests: write

send-slack-message:
name: Send Slack message on failure
needs: [deploy-infra-test, deploy-apps-test, deploy-slack-notifier-test, run-e2e-tests, publish-schema-npm]
runs-on: ubuntu-latest
if: ${{ always() && failure() && !cancelled() }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Send GitHub slack message
id: slack
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
ENVIRONMENT: test
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID_FOR_RELEASES }}
payload-file-path: "./.github/slack-templates/pipeline-failed.json"
name: Send Slack message
needs: [deploy-infra-test, deploy-apps-test, deploy-slack-notifier-test, run-e2e-tests, publish-schema-npm, publish]
if: ${{ always() && (failure() || success()) }}
uses: ./.github/workflows/action-send-ci-cd-status-slack-message.yml
with:
environment: test
infra_status: ${{ needs.deploy-infra-test.result }}
apps_status: ${{ needs.deploy-apps-test.result }}
slack_notifier_status: ${{ needs.deploy-slack-notifier-test.result }}
e2e_tests_status: ${{ needs.run-e2e-tests.result }}
schema_npm_status: ${{ needs.publish-schema-npm.result }}
publish_status: ${{ needs.publish.result }}
secrets:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_CHANNEL_ID_FOR_RELEASES: ${{ secrets.SLACK_CHANNEL_ID_FOR_RELEASES }}
30 changes: 14 additions & 16 deletions .github/workflows/ci-cd-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ jobs:
# secrets:
# TOKEN_GENERATOR_USERNAME: ${{ secrets.TOKEN_GENERATOR_USERNAME }}
# TOKEN_GENERATOR_PASSWORD: ${{ secrets.TOKEN_GENERATOR_PASSWORD }}
# SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
# with:
# environment: prod
# apiVersion: v1
Expand All @@ -137,19 +136,18 @@ jobs:
# pull-requests: write

send-slack-message:
name: Send Slack message on failure
name: Send Slack message
needs: [deploy-infra-prod, deploy-apps-prod, deploy-slack-notifier-prod]
runs-on: ubuntu-latest
if: ${{ always() && failure() && !cancelled() }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Send GitHub slack message
id: slack
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
ENVIRONMENT: prod
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID_FOR_RELEASES }}
payload-file-path: "./.github/slack-templates/pipeline-failed.json"
if: ${{ always() && (failure() || success()) }}
uses: ./.github/workflows/action-send-ci-cd-status-slack-message.yml
with:
environment: prod
infra_status: ${{ needs.deploy-infra-prod.result }}
apps_status: ${{ needs.deploy-apps-prod.result }}
slack_notifier_status: ${{ needs.deploy-slack-notifier-prod.result }}
e2e_tests_status: 'skipped'
schema_npm_status: 'skipped'
publish_status: 'skipped'
secrets:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_CHANNEL_ID_FOR_RELEASES: ${{ secrets.SLACK_CHANNEL_ID_FOR_RELEASES }}
arealmaas marked this conversation as resolved.
Show resolved Hide resolved
35 changes: 18 additions & 17 deletions .github/workflows/ci-cd-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}

env:
ENVIRONMENT: staging

arealmaas marked this conversation as resolved.
Show resolved Hide resolved
jobs:
# Get changed files between previous tag and current tag: https://github.com/marketplace/actions/changed-files
check-for-changes:
Expand Down Expand Up @@ -106,7 +109,6 @@ jobs:
secrets:
TOKEN_GENERATOR_USERNAME: ${{ secrets.TOKEN_GENERATOR_USERNAME }}
TOKEN_GENERATOR_PASSWORD: ${{ secrets.TOKEN_GENERATOR_PASSWORD }}
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
with:
environment: staging
apiVersion: v1
Expand All @@ -116,19 +118,18 @@ jobs:
pull-requests: write

send-slack-message:
name: Send Slack message on failure
needs: [deploy-infra-staging, deploy-apps-staging, deploy-slack-notifier-staging, run-e2e-tests, publish-schema-npm]
runs-on: ubuntu-latest
if: ${{ always() && failure() && !cancelled() }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Send GitHub slack message
id: slack
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
ENVIRONMENT: staging
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID_FOR_RELEASES }}
payload-file-path: "./.github/slack-templates/pipeline-failed.json"
name: Send Slack message
needs: [deploy-infra-staging, deploy-apps-staging, deploy-slack-notifier-staging, run-e2e-tests, publish-schema-npm, publish]
if: ${{ always() && (failure() || success()) }}
uses: ./.github/workflows/action-send-ci-cd-status-slack-message.yml
with:
environment: staging
infra_status: ${{ needs.deploy-infra-staging.result }}
apps_status: ${{ needs.deploy-apps-staging.result }}
slack_notifier_status: ${{ needs.deploy-slack-notifier-staging.result }}
e2e_tests_status: ${{ needs.run-e2e-tests.result }}
schema_npm_status: ${{ needs.publish-schema-npm.result }}
publish_status: ${{ needs.publish.result }}
secrets:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_CHANNEL_ID_FOR_RELEASES: ${{ secrets.SLACK_CHANNEL_ID_FOR_RELEASES }}
Loading