diff --git a/.github/slack-templates/pipeline-failed.json b/.github/slack-templates/pipeline-failed.json index 3cf1a6703..b8d80e6e9 100644 --- a/.github/slack-templates/pipeline-failed.json +++ b/.github/slack-templates/pipeline-failed.json @@ -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 }}" + } + ] + } + ] + } + ] } \ 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/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..4c2e81c80 --- /dev/null +++ b/.github/workflows/action-send-ci-cd-status-slack-message.yml @@ -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/slack-github-action@v1.27.0 + with: + 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 9e4b4a676..672834a3b 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 @@ -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/slack-github-action@v1.27.0 - 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 }} diff --git a/.github/workflows/ci-cd-prod.yml b/.github/workflows/ci-cd-prod.yml index 338135178..a17822267 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 @@ -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/slack-github-action@v1.27.0 - 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 }} diff --git a/.github/workflows/ci-cd-pull-request.yml b/.github/workflows/ci-cd-pull-request.yml index 4512df8f0..b6f80028c 100644 --- a/.github/workflows/ci-cd-pull-request.yml +++ b/.github/workflows/ci-cd-pull-request.yml @@ -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: @@ -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 diff --git a/.github/workflows/ci-cd-staging.yml b/.github/workflows/ci-cd-staging.yml index b15b9a8d9..904ceb33f 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 @@ -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/slack-github-action@v1.27.0 - 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 }}