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 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
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 }}"
}
]
}
]
}
85 changes: 85 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,85 @@
name: Send CI/CD Status Slack Message

on:
workflow_call:
inputs:
environment:
required: true
type: string
infra_status:
type: string
description: "Status of the infrastructure deployment job"
default: "skipped"
apps_status:
type: string
description: "Status of the apps deployment job"
default: "skipped"
slack_notifier_status:
type: string
description: "Status of the Slack notifier deployment job"
default: "skipped"
e2e_tests_status:
type: string
description: "Status of the end-to-end tests job"
default: "skipped"
schema_npm_status:
type: string
description: "Status of the schema npm publishing job"
default: "skipped"
publish_status:
type: string
description: "Status of the docker image publishing job"
default: "skipped"
secrets:
SLACK_BOT_TOKEN:
required: true
SLACK_CHANNEL_ID:
required: true

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() {
local -A emoji_map=(
[success]=":white_check_mark:"
[failure]=":x:"
[cancelled]=":warning:"
[skipped]=":ballot_box_with_check:"
)
echo "${emoji_map[$1]:-Invalid status: $1}"
}

{
echo "INFRA_EMOJI=$(determine_emoji "${{ inputs.infra_status }}")"
echo "APPS_EMOJI=$(determine_emoji "${{ inputs.apps_status }}")"
echo "SLACK_NOTIFIER_EMOJI=$(determine_emoji "${{ inputs.slack_notifier_status }}")"
echo "E2E_TESTS_EMOJI=$(determine_emoji "${{ inputs.e2e_tests_status }}")"
echo "SCHEMA_NPM_EMOJI=$(determine_emoji "${{ inputs.schema_npm_status }}")"
echo "PUBLISH_EMOJI=$(determine_emoji "${{ inputs.publish_status }}")"
} >> "$GITHUB_OUTPUT"

- name: Send GitHub slack message
id: slack
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
ENVIRONMENT: ${{ inputs.environment }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/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 }}
payload-file-path: "./.github/slack-templates/pipeline-failed.json"
30 changes: 14 additions & 16 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 @@ -151,20 +150,19 @@ jobs:
checks: write
pull-requests: write

send-slack-message:
send-slack-message-on-failure:
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
needs: [deploy-infra-test, deploy-apps-test, deploy-slack-notifier-test, run-e2e-tests, publish-schema-npm, publish]
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"
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: ${{ secrets.SLACK_CHANNEL_ID_FOR_CI_CD_STATUS }}
25 changes: 10 additions & 15 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 @@ -136,20 +135,16 @@ jobs:
# checks: write
# pull-requests: write

send-slack-message:
send-slack-message-on-failure:
name: Send Slack message on failure
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"
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 }}
secrets:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID_FOR_CI_CD_STATUS }}
2 changes: 0 additions & 2 deletions .github/workflows/ci-cd-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ jobs:
dryRun: true
version: ${{ needs.get-current-version.outputs.version }}-${{ needs.generate-git-short-sha.outputs.gitShortSha }}


dry-run-deploy-apps:
name: Dry run deploy apps
needs:
Expand Down Expand Up @@ -90,7 +89,6 @@ jobs:
runMigration: ${{ needs.check-for-changes.outputs.hasMigrationChanges == 'true' }}
dryRun: true


delete-github-deployments:
name: Delete GitHub deployments
uses: ./.github/workflows/action-delete-deployments.yml
Expand Down
30 changes: 14 additions & 16 deletions .github/workflows/ci-cd-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,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 @@ -115,20 +114,19 @@ jobs:
checks: write
pull-requests: write

send-slack-message:
send-slack-message-on-failure:
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
needs: [deploy-infra-staging, deploy-apps-staging, deploy-slack-notifier-staging, run-e2e-tests, publish-schema-npm, publish]
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"
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: ${{ secrets.SLACK_CHANNEL_ID_FOR_CI_CD_STATUS }}
Loading