From d718bfa2688426ebfb5564462272869cf8cfd462 Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Fri, 11 Oct 2024 12:07:35 +0200 Subject: [PATCH 01/11] ci(slackbot): clean up slack alerts --- .github/slack-templates/pipeline-failed.json | 53 +++++++++++--------- .github/workflows/action-run-k6-tests.yml | 36 ------------- .github/workflows/ci-cd-main.yml | 2 +- .github/workflows/ci-cd-prod.yml | 2 +- .github/workflows/ci-cd-staging.yml | 2 +- 5 files changed, 33 insertions(+), 62 deletions(-) diff --git a/.github/slack-templates/pipeline-failed.json b/.github/slack-templates/pipeline-failed.json index 3cf1a6703..d729c4e45 100644 --- a/.github/slack-templates/pipeline-failed.json +++ b/.github/slack-templates/pipeline-failed.json @@ -1,25 +1,32 @@ { - "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": "#f2c744", + "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": "${{ env.RUN_URL }}" + } + ] + } + ] + } + ] } \ No newline at end of file diff --git a/.github/workflows/action-run-k6-tests.yml b/.github/workflows/action-run-k6-tests.yml index 2d42ce58b..a866ab8c5 100644 --- a/.github/workflows/action-run-k6-tests.yml +++ b/.github/workflows/action-run-k6-tests.yml @@ -17,8 +17,6 @@ on: required: true TOKEN_GENERATOR_PASSWORD: required: true - SLACK_BOT_TOKEN: - required: true jobs: k6-test: @@ -57,37 +55,3 @@ jobs: action_fail: true files: | junit.xml - - - name: Send Slack message on K6 test failure - if: always() && failure() - uses: slackapi/slack-github-action@v1.27.0 - 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 }}" - } - ] - } - ] - } diff --git a/.github/workflows/ci-cd-main.yml b/.github/workflows/ci-cd-main.yml index 9e4b4a676..fc5649be9 100644 --- a/.github/workflows/ci-cd-main.yml +++ b/.github/workflows/ci-cd-main.yml @@ -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 @@ -164,6 +163,7 @@ jobs: env: SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} ENVIRONMENT: test + RUN_URL: ${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }} uses: slackapi/slack-github-action@v1.27.0 with: channel-id: ${{ secrets.SLACK_CHANNEL_ID_FOR_RELEASES }} diff --git a/.github/workflows/ci-cd-prod.yml b/.github/workflows/ci-cd-prod.yml index 338135178..3de307adc 100644 --- a/.github/workflows/ci-cd-prod.yml +++ b/.github/workflows/ci-cd-prod.yml @@ -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 @@ -149,6 +148,7 @@ jobs: env: SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} ENVIRONMENT: prod + RUN_URL: ${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }} uses: slackapi/slack-github-action@v1.27.0 with: channel-id: ${{ secrets.SLACK_CHANNEL_ID_FOR_RELEASES }} diff --git a/.github/workflows/ci-cd-staging.yml b/.github/workflows/ci-cd-staging.yml index b15b9a8d9..b07d0abeb 100644 --- a/.github/workflows/ci-cd-staging.yml +++ b/.github/workflows/ci-cd-staging.yml @@ -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 @@ -128,6 +127,7 @@ jobs: env: SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} ENVIRONMENT: staging + RUN_URL: ${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }} uses: slackapi/slack-github-action@v1.27.0 with: channel-id: ${{ secrets.SLACK_CHANNEL_ID_FOR_RELEASES }} From b75ef6de31b300679661dbe34732af98f80096d5 Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Fri, 11 Oct 2024 12:16:49 +0200 Subject: [PATCH 02/11] ci(slackbot): clean up slack alerts --- .github/slack-templates/pipeline-failed.json | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/slack-templates/pipeline-failed.json b/.github/slack-templates/pipeline-failed.json index d729c4e45..bff7aa822 100644 --- a/.github/slack-templates/pipeline-failed.json +++ b/.github/slack-templates/pipeline-failed.json @@ -1,13 +1,28 @@ { "attachments": [ { - "color": "#f2c744", + "color": "#FF0000", "blocks": [ + { + "type": "header", + "text": { + "type": "plain_text", + "text": "Github pipeline failing", + "emoji": true + } + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*Environment:* ${{ env.ENVIRONMENT }}" + } + }, { "type": "section", "text": { "type": "mrkdwn", - "text": ":rotating_light: Pipeline failing for *${{ env.ENVIRONMENT }}* :rotating_light:\n\nPlease check the workflow for more details." + "text": "Please check the workflow for more details." } }, { From 5b14db89939eed6728edfee415c91ac42b3c4d7b Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Fri, 11 Oct 2024 12:17:36 +0200 Subject: [PATCH 03/11] cleanup --- .github/slack-templates/pipeline-failed.json | 90 ++++++++++---------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/.github/slack-templates/pipeline-failed.json b/.github/slack-templates/pipeline-failed.json index bff7aa822..af0aaa8d7 100644 --- a/.github/slack-templates/pipeline-failed.json +++ b/.github/slack-templates/pipeline-failed.json @@ -1,47 +1,47 @@ { - "attachments": [ - { - "color": "#FF0000", - "blocks": [ - { - "type": "header", - "text": { - "type": "plain_text", - "text": "Github pipeline failing", - "emoji": true - } - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "*Environment:* ${{ env.ENVIRONMENT }}" - } - }, - { - "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 }}" - } - ] - } - ] - } - ] + "attachments": [ + { + "color": "#FF0000", + "blocks": [ + { + "type": "header", + "text": { + "type": "plain_text", + "text": "Github pipeline failing", + "emoji": true + } + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*Environment:* ${{ env.ENVIRONMENT }}" + } + }, + { + "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 }}" + } + ] + } + ] + } + ] } \ No newline at end of file From f8a61468e77cf92ab6c989cb1c739ee13c1c40fc Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Fri, 11 Oct 2024 14:04:10 +0200 Subject: [PATCH 04/11] refactor to use statuses --- .github/slack-templates/pipeline-failed.json | 9 +- ...action-send-ci-cd-status-slack-message.yml | 99 +++++++++++++++++++ .github/workflows/ci-cd-main.yml | 32 +++--- .github/workflows/ci-cd-prod.yml | 30 +++--- .github/workflows/ci-cd-staging.yml | 35 +++---- 5 files changed, 154 insertions(+), 51 deletions(-) create mode 100644 .github/workflows/action-send-ci-cd-status-slack-message.yml diff --git a/.github/slack-templates/pipeline-failed.json b/.github/slack-templates/pipeline-failed.json index af0aaa8d7..b8d80e6e9 100644 --- a/.github/slack-templates/pipeline-failed.json +++ b/.github/slack-templates/pipeline-failed.json @@ -7,7 +7,7 @@ "type": "header", "text": { "type": "plain_text", - "text": "Github pipeline failing", + "text": "Github pipeline status", "emoji": true } }, @@ -18,6 +18,13 @@ "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": { diff --git a/.github/workflows/action-send-ci-cd-status-slack-message.yml b/.github/workflows/action-send-ci-cd-status-slack-message.yml new file mode 100644 index 000000000..a1b4e23fe --- /dev/null +++ b/.github/workflows/action-send-ci-cd-status-slack-message.yml @@ -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 + +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 + + - 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/slack-github-action@v1.27.0 + with: + channel-id: ${{ secrets.SLACK_CHANNEL_ID_FOR_RELEASES }} + payload-file-path: "./.github/slack-templates/pipeline-failed.json" \ No newline at end of file diff --git a/.github/workflows/ci-cd-main.yml b/.github/workflows/ci-cd-main.yml index fc5649be9..23a247e54 100644 --- a/.github/workflows/ci-cd-main.yml +++ b/.github/workflows/ci-cd-main.yml @@ -151,20 +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 - RUN_URL: ${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }} - uses: slackapi/slack-github-action@v1.27.0 - 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 }} diff --git a/.github/workflows/ci-cd-prod.yml b/.github/workflows/ci-cd-prod.yml index 3de307adc..2f66aa1ba 100644 --- a/.github/workflows/ci-cd-prod.yml +++ b/.github/workflows/ci-cd-prod.yml @@ -136,20 +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 - RUN_URL: ${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }} - uses: slackapi/slack-github-action@v1.27.0 - 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 }} diff --git a/.github/workflows/ci-cd-staging.yml b/.github/workflows/ci-cd-staging.yml index b07d0abeb..f6d6ad9e9 100644 --- a/.github/workflows/ci-cd-staging.yml +++ b/.github/workflows/ci-cd-staging.yml @@ -9,6 +9,9 @@ on: concurrency: group: ${{ github.workflow }}-${{ github.ref_name }} +env: + ENVIRONMENT: staging + jobs: # Get changed files between previous tag and current tag: https://github.com/marketplace/actions/changed-files check-for-changes: @@ -115,20 +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 - RUN_URL: ${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }} - uses: slackapi/slack-github-action@v1.27.0 - 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 }} From 05a66c0189114c0f2958246051156b28de5c459e Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Fri, 11 Oct 2024 14:07:40 +0200 Subject: [PATCH 05/11] clean up the things --- .../action-send-ci-cd-status-slack-message.yml | 4 ++-- .github/workflows/ci-cd-main.yml | 2 +- .github/workflows/ci-cd-prod.yml | 2 +- .github/workflows/ci-cd-pull-request-title.yml | 13 +++++++++++++ .github/workflows/ci-cd-staging.yml | 2 +- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.github/workflows/action-send-ci-cd-status-slack-message.yml b/.github/workflows/action-send-ci-cd-status-slack-message.yml index a1b4e23fe..0cbfe2d5e 100644 --- a/.github/workflows/action-send-ci-cd-status-slack-message.yml +++ b/.github/workflows/action-send-ci-cd-status-slack-message.yml @@ -39,7 +39,7 @@ on: secrets: SLACK_BOT_TOKEN: required: true - SLACK_CHANNEL_ID_FOR_RELEASES: + SLACK_CHANNEL_ID: required: true jobs: @@ -95,5 +95,5 @@ jobs: PUBLISH_STATUS: "${{ steps.status-emojis.outputs.PUBLISH_EMOJI }}" uses: slackapi/slack-github-action@v1.27.0 with: - channel-id: ${{ secrets.SLACK_CHANNEL_ID_FOR_RELEASES }} + channel-id: ${{ secrets.SLACK_CHANNEL_ID }} payload-file-path: "./.github/slack-templates/pipeline-failed.json" \ No newline at end of file diff --git a/.github/workflows/ci-cd-main.yml b/.github/workflows/ci-cd-main.yml index 23a247e54..c5841ed22 100644 --- a/.github/workflows/ci-cd-main.yml +++ b/.github/workflows/ci-cd-main.yml @@ -165,4 +165,4 @@ jobs: publish_status: ${{ needs.publish.result }} secrets: SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} - SLACK_CHANNEL_ID_FOR_RELEASES: ${{ secrets.SLACK_CHANNEL_ID_FOR_RELEASES }} + SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID_FOR_CI_CD_STATUS }} diff --git a/.github/workflows/ci-cd-prod.yml b/.github/workflows/ci-cd-prod.yml index 2f66aa1ba..b218bf32e 100644 --- a/.github/workflows/ci-cd-prod.yml +++ b/.github/workflows/ci-cd-prod.yml @@ -150,4 +150,4 @@ jobs: publish_status: 'skipped' secrets: SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} - SLACK_CHANNEL_ID_FOR_RELEASES: ${{ secrets.SLACK_CHANNEL_ID_FOR_RELEASES }} + SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID_FOR_CI_CD_STATUS }} diff --git a/.github/workflows/ci-cd-pull-request-title.yml b/.github/workflows/ci-cd-pull-request-title.yml index cc3ec659a..2bbb30ce7 100644 --- a/.github/workflows/ci-cd-pull-request-title.yml +++ b/.github/workflows/ci-cd-pull-request-title.yml @@ -20,3 +20,16 @@ jobs: with: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} configuration_path: ".github/pr-title-checker-config.json" + send-slack-message: + uses: ./.github/workflows/action-send-ci-cd-status-slack-message.yml + with: + environment: ${{ github.event.repository.name }} + infra_status: 'success' + apps_status: 'failure' + slack_notifier_status: 'cancelled' + e2e_tests_status: 'skipped' + schema_npm_status: 'skipped' + publish_status: 'skipped' + secrets: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} + SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID_FOR_CI_CD_STATUS }} diff --git a/.github/workflows/ci-cd-staging.yml b/.github/workflows/ci-cd-staging.yml index f6d6ad9e9..8bea39c4e 100644 --- a/.github/workflows/ci-cd-staging.yml +++ b/.github/workflows/ci-cd-staging.yml @@ -132,4 +132,4 @@ jobs: publish_status: ${{ needs.publish.result }} secrets: SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} - SLACK_CHANNEL_ID_FOR_RELEASES: ${{ secrets.SLACK_CHANNEL_ID_FOR_RELEASES }} + SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID_FOR_CI_CD_STATUS }} From 5bd71c74c40771a182ea8064eb8df1eca455cf7c Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Fri, 11 Oct 2024 14:15:39 +0200 Subject: [PATCH 06/11] cleanup --- ...action-send-ci-cd-status-slack-message.yml | 48 +++++++------------ .github/workflows/ci-cd-staging.yml | 3 -- 2 files changed, 17 insertions(+), 34 deletions(-) diff --git a/.github/workflows/action-send-ci-cd-status-slack-message.yml b/.github/workflows/action-send-ci-cd-status-slack-message.yml index 0cbfe2d5e..a7108d0a5 100644 --- a/.github/workflows/action-send-ci-cd-status-slack-message.yml +++ b/.github/workflows/action-send-ci-cd-status-slack-message.yml @@ -7,32 +7,26 @@ on: 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" @@ -54,38 +48,30 @@ jobs: 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 + local -A emoji_map=( + [success]=":white_check_mark:" + [failure]=":x:" + [cancelled]=":warning:" + [skipped]=":heavy_minus_sign:" + ) + echo "${emoji_map[$1]:-Invalid status: $1}" } - 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 + + { + 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.event.repository.html_url }}/actions/runs/${{ github.run_id }} + 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 }}" diff --git a/.github/workflows/ci-cd-staging.yml b/.github/workflows/ci-cd-staging.yml index 8bea39c4e..a5f5176ad 100644 --- a/.github/workflows/ci-cd-staging.yml +++ b/.github/workflows/ci-cd-staging.yml @@ -9,9 +9,6 @@ on: concurrency: group: ${{ github.workflow }}-${{ github.ref_name }} -env: - ENVIRONMENT: staging - jobs: # Get changed files between previous tag and current tag: https://github.com/marketplace/actions/changed-files check-for-changes: From 0748c7cb643b59d9ddc03a2a9a9aa04dc9ff6bf7 Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Fri, 11 Oct 2024 14:18:42 +0200 Subject: [PATCH 07/11] cleanup --- .github/workflows/ci-cd-pull-request-title.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci-cd-pull-request-title.yml b/.github/workflows/ci-cd-pull-request-title.yml index 2bbb30ce7..48ef2f5bf 100644 --- a/.github/workflows/ci-cd-pull-request-title.yml +++ b/.github/workflows/ci-cd-pull-request-title.yml @@ -22,6 +22,7 @@ jobs: configuration_path: ".github/pr-title-checker-config.json" send-slack-message: uses: ./.github/workflows/action-send-ci-cd-status-slack-message.yml + needs: [validate] with: environment: ${{ github.event.repository.name }} infra_status: 'success' From a77f31759300e8e2eb8aa8641a7085b1890fb138 Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Fri, 11 Oct 2024 14:20:32 +0200 Subject: [PATCH 08/11] cleanup --- .github/workflows/ci-cd-pull-request-title.yml | 14 -------------- .github/workflows/ci-cd-pull-request.yml | 16 ++++++++++++++-- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci-cd-pull-request-title.yml b/.github/workflows/ci-cd-pull-request-title.yml index 48ef2f5bf..cc3ec659a 100644 --- a/.github/workflows/ci-cd-pull-request-title.yml +++ b/.github/workflows/ci-cd-pull-request-title.yml @@ -20,17 +20,3 @@ jobs: with: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} configuration_path: ".github/pr-title-checker-config.json" - send-slack-message: - uses: ./.github/workflows/action-send-ci-cd-status-slack-message.yml - needs: [validate] - with: - environment: ${{ github.event.repository.name }} - infra_status: 'success' - apps_status: 'failure' - slack_notifier_status: 'cancelled' - e2e_tests_status: 'skipped' - schema_npm_status: 'skipped' - publish_status: 'skipped' - secrets: - SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} - SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID_FOR_CI_CD_STATUS }} diff --git a/.github/workflows/ci-cd-pull-request.yml b/.github/workflows/ci-cd-pull-request.yml index 4512df8f0..59c663acb 100644 --- a/.github/workflows/ci-cd-pull-request.yml +++ b/.github/workflows/ci-cd-pull-request.yml @@ -25,6 +25,20 @@ jobs: needs: [check-for-changes] if: ${{ needs.check-for-changes.outputs.hasBackendChanges == 'true' || needs.check-for-changes.outputs.hasTestChanges == 'true' }} + send-slack-message: + uses: ./.github/workflows/action-send-ci-cd-status-slack-message.yml + with: + environment: ${{ github.event.repository.name }} + infra_status: 'success' + apps_status: 'failure' + slack_notifier_status: 'cancelled' + e2e_tests_status: 'skipped' + schema_npm_status: 'skipped' + publish_status: 'skipped' + secrets: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} + SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID_FOR_CI_CD_STATUS }} + build-infrastructure: uses: ./.github/workflows/action-build-infrastructure.yml needs: [check-for-changes] @@ -61,7 +75,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: @@ -90,7 +103,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 From 0331ee4b7e91de40c05daa544801d1fd3ece08d5 Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Fri, 11 Oct 2024 14:26:03 +0200 Subject: [PATCH 09/11] cleanup --- .github/workflows/action-send-ci-cd-status-slack-message.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/action-send-ci-cd-status-slack-message.yml b/.github/workflows/action-send-ci-cd-status-slack-message.yml index a7108d0a5..4c2e81c80 100644 --- a/.github/workflows/action-send-ci-cd-status-slack-message.yml +++ b/.github/workflows/action-send-ci-cd-status-slack-message.yml @@ -52,7 +52,7 @@ jobs: [success]=":white_check_mark:" [failure]=":x:" [cancelled]=":warning:" - [skipped]=":heavy_minus_sign:" + [skipped]=":ballot_box_with_check:" ) echo "${emoji_map[$1]:-Invalid status: $1}" } From 801a98f6f90a9275f45aaf115ad32fa2bc62b77c Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Fri, 11 Oct 2024 14:29:22 +0200 Subject: [PATCH 10/11] clean up the things --- .github/workflows/ci-cd-main.yml | 4 ++-- .github/workflows/ci-cd-prod.yml | 5 +---- .github/workflows/ci-cd-pull-request.yml | 14 -------------- .github/workflows/ci-cd-staging.yml | 2 +- 4 files changed, 4 insertions(+), 21 deletions(-) diff --git a/.github/workflows/ci-cd-main.yml b/.github/workflows/ci-cd-main.yml index c5841ed22..7d92984d2 100644 --- a/.github/workflows/ci-cd-main.yml +++ b/.github/workflows/ci-cd-main.yml @@ -150,10 +150,10 @@ jobs: checks: write pull-requests: write - send-slack-message: + send-slack-message-on-failure: 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()) }} + if: ${{ always() && failure() && !cancelled() }} uses: ./.github/workflows/action-send-ci-cd-status-slack-message.yml with: environment: test diff --git a/.github/workflows/ci-cd-prod.yml b/.github/workflows/ci-cd-prod.yml index b218bf32e..ce0c33491 100644 --- a/.github/workflows/ci-cd-prod.yml +++ b/.github/workflows/ci-cd-prod.yml @@ -138,16 +138,13 @@ jobs: send-slack-message: name: Send Slack message needs: [deploy-infra-prod, deploy-apps-prod, deploy-slack-notifier-prod] - if: ${{ always() && (failure() || success()) }} + if: ${{ always() && failure() && !cancelled() }} 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: ${{ secrets.SLACK_CHANNEL_ID_FOR_CI_CD_STATUS }} diff --git a/.github/workflows/ci-cd-pull-request.yml b/.github/workflows/ci-cd-pull-request.yml index 59c663acb..b6f80028c 100644 --- a/.github/workflows/ci-cd-pull-request.yml +++ b/.github/workflows/ci-cd-pull-request.yml @@ -25,20 +25,6 @@ jobs: needs: [check-for-changes] if: ${{ needs.check-for-changes.outputs.hasBackendChanges == 'true' || needs.check-for-changes.outputs.hasTestChanges == 'true' }} - send-slack-message: - uses: ./.github/workflows/action-send-ci-cd-status-slack-message.yml - with: - environment: ${{ github.event.repository.name }} - infra_status: 'success' - apps_status: 'failure' - slack_notifier_status: 'cancelled' - e2e_tests_status: 'skipped' - schema_npm_status: 'skipped' - publish_status: 'skipped' - secrets: - SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} - SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID_FOR_CI_CD_STATUS }} - build-infrastructure: uses: ./.github/workflows/action-build-infrastructure.yml needs: [check-for-changes] diff --git a/.github/workflows/ci-cd-staging.yml b/.github/workflows/ci-cd-staging.yml index a5f5176ad..178cb579b 100644 --- a/.github/workflows/ci-cd-staging.yml +++ b/.github/workflows/ci-cd-staging.yml @@ -117,7 +117,7 @@ jobs: send-slack-message: 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()) }} + if: ${{ always() && failure() && !cancelled() }} uses: ./.github/workflows/action-send-ci-cd-status-slack-message.yml with: environment: staging From 3184590cc8ede45de254f67aa9c37ea970821cad Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Fri, 11 Oct 2024 14:32:40 +0200 Subject: [PATCH 11/11] cleanup --- .github/workflows/ci-cd-main.yml | 2 +- .github/workflows/ci-cd-prod.yml | 4 ++-- .github/workflows/ci-cd-staging.yml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci-cd-main.yml b/.github/workflows/ci-cd-main.yml index 7d92984d2..672834a3b 100644 --- a/.github/workflows/ci-cd-main.yml +++ b/.github/workflows/ci-cd-main.yml @@ -151,7 +151,7 @@ jobs: pull-requests: write send-slack-message-on-failure: - name: 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, publish] if: ${{ always() && failure() && !cancelled() }} uses: ./.github/workflows/action-send-ci-cd-status-slack-message.yml diff --git a/.github/workflows/ci-cd-prod.yml b/.github/workflows/ci-cd-prod.yml index ce0c33491..a17822267 100644 --- a/.github/workflows/ci-cd-prod.yml +++ b/.github/workflows/ci-cd-prod.yml @@ -135,8 +135,8 @@ jobs: # checks: write # pull-requests: write - send-slack-message: - name: 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] if: ${{ always() && failure() && !cancelled() }} uses: ./.github/workflows/action-send-ci-cd-status-slack-message.yml diff --git a/.github/workflows/ci-cd-staging.yml b/.github/workflows/ci-cd-staging.yml index 178cb579b..904ceb33f 100644 --- a/.github/workflows/ci-cd-staging.yml +++ b/.github/workflows/ci-cd-staging.yml @@ -114,8 +114,8 @@ jobs: checks: write pull-requests: write - send-slack-message: - name: 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, publish] if: ${{ always() && failure() && !cancelled() }} uses: ./.github/workflows/action-send-ci-cd-status-slack-message.yml