From a9089eaca0ec94aeb2427e5699d1ffcd5b36697a Mon Sep 17 00:00:00 2001 From: Oriol Date: Fri, 22 Mar 2024 17:22:41 +0100 Subject: [PATCH] chore: Send Slack message for Terraform Compatibility Matrix is executed (#2052) * schedule compatibility matrix first day of month * WIP: test if status can be retrieved * test * test echo job status * change * Revert "change" This reverts commit 4b0e49ebda89ff667f6459b304ecaadae1a42a84. * Revert "test echo job status" This reverts commit 4a83862e32ffd95b4d3ea52f1a44f59e6d5696e9. * test getting outputs of matrix * result * send slack * checkout step * fix name * correct json * formating * Revert "formating" This reverts commit f58482226650af634e4d3be97cadf05a83447604. * format * try * Revert "try" This reverts commit 7029f54ddbacfd5fe337c0dba976818a8a1292ad. * use cat * Revert "use cat" This reverts commit 9503cd220dab795a314e549b1d35f3550e97589e. * remove unnecesary double quote * try cat * Revert "try cat" This reverts commit a2df8ff0a9531195e401bb9eb39a1047de7792ec. * return json * unify json * fix * enrich message * TEMP: tag oncall on success * chore: Updates Atlas Go SDK (#2044) * build(deps): bump go.mongodb.org/atlas-sdk * fix tags * undo changes to admin20231001002 * API breaking change fixes --------- Co-authored-by: lantoli <430982+lantoli@users.noreply.github.com> * chore: Follow-up to Atlas SDK upgrade (#2051) * remove unused NewGroup * unify List call thanks to new API * refactor: Uses mocks on admin.APIClient for Project+Teams+ClustersAPIs instead of custom service (#2045) * refactor: Uses mocks on admin.APIClient instead of custom ClusterService (#2056) * fix: Fixes `network_container` resource update (#2055) * failing test * recreate resource if provider_name changes * fix update * allow update in place when provider_name changes * fix regions error handling * refactor tests checks * refactor checks in mig tests as well * fix change check * use MONGODB_ATLAS_PROJECT_ID (#2060) * chore: Removes old service from mockery (#2063) * feat: Allows user to specify to use an existing tag for release (#2053) * remove TEMP oncall tag on success * initialize oncall_tag * send notification when test suite fails * revert back testing change * remove temporary trigger of action * use oncall tag from secrets * Revert "use oncall tag from secrets" This reverts commit 5a7944f4f68ef93dea65e0e7188ff162de60c72e. * use SHA * new line * make oncall tag a secret --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: lantoli <430982+lantoli@users.noreply.github.com> Co-authored-by: Espen Albert Co-authored-by: maastha <122359335+maastha@users.noreply.github.com> --- .../terraform-compatibility-matrix.yml | 24 ++++++- .github/workflows/test-suite.yml | 42 ++++++++++- .../generate-slack-notification-content.sh | 70 +++++++++++++++++++ 3 files changed, 132 insertions(+), 4 deletions(-) create mode 100755 scripts/generate-slack-notification-content.sh diff --git a/.github/workflows/terraform-compatibility-matrix.yml b/.github/workflows/terraform-compatibility-matrix.yml index 40e78bbeb3..4e022252c6 100644 --- a/.github/workflows/terraform-compatibility-matrix.yml +++ b/.github/workflows/terraform-compatibility-matrix.yml @@ -3,7 +3,7 @@ run-name: 'HashiCorp Terraform Compatibility Matrix ${{ inputs.atlas_cloud_env } on: schedule: - - cron: "0 0 1-7 * 6" # runs first Saturday of the month at midnight UTC + - cron: "0 0 1 * *" # runs first day of the month at midnight UTC workflow_dispatch: inputs: atlas_cloud_env: @@ -47,4 +47,24 @@ jobs: with: terraform_matrix: '["${{ matrix.terraform_version }}"]' atlas_cloud_env: ${{ inputs.atlas_cloud_env }} - + + slack-notification: + needs: ["run-test-supported-versions"] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 + - name: Get content of slack message + id: slack-payload + run: | + slack_message=$(./scripts/generate-slack-notification-content.sh ${{ needs.run-test-supported-versions.result }} ${{ secrets.SLACK_ONCALL_TAG }} ${{github.server_url}} ${{github.repository}} ${{github.run_id}}) + echo "slack_payload=${slack_message}" >> "${GITHUB_OUTPUT}" + - name: Send Slack message + id: slack + uses: slackapi/slack-github-action@6c661ce58804a1a20f6dc5fbee7f0381b469e001 + with: + payload: ${{ steps.slack-payload.outputs.slack_payload }} + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK + + diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml index 4ed3fadb2a..1fcd84ac83 100644 --- a/.github/workflows/test-suite.yml +++ b/.github/workflows/test-suite.yml @@ -25,7 +25,7 @@ on: required: false schedule: - - cron: "0 0 * * 0-5" # workflow runs every day at midnight UTC except on Saturdays + - cron: "0 0 2-31 * *" # workflow runs every day at midnight UTC except on the first day of the month concurrency: group: '${{ github.workflow }}' @@ -84,4 +84,42 @@ jobs: if: ${{ !cancelled() }} secrets: inherit uses: ./.github/workflows/cleanup-test-env.yml - \ No newline at end of file + + slack-notification: + needs: [mig-tests, acc-tests, clean-after] + if: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && (needs.mig-tests.result == 'failure' || needs.acc-tests.result == 'failure')}} + runs-on: ubuntu-latest + steps: + - name: Send Slack message + id: slack + uses: slackapi/slack-github-action@6c661ce58804a1a20f6dc5fbee7f0381b469e001 + with: + payload: | + { + "text": ":red_circle: Test Suite failed", + "blocks": [ + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*Test Suite failed* ${{ secrets.SLACK_ONCALL_TAG }}" + } + }, + { + "type": "actions", + "elements": [ + { + "type": "button", + "text": { + "type": "plain_text", + "text": ":github: $action_text" + }, + "url": "${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}" + } + ] + } + ] + } + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK diff --git a/scripts/generate-slack-notification-content.sh b/scripts/generate-slack-notification-content.sh new file mode 100755 index 0000000000..db44afac8f --- /dev/null +++ b/scripts/generate-slack-notification-content.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash + +# Copyright 2024 MongoDB Inc +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +set -euo pipefail + +# Check if the parameter is provided +if [ $# -eq 0 ]; then + echo "Usage: $0 " + exit 1 +fi + +# Check if the parameter is either "success" or "failure" +if [ "$1" != "success" ] && [ "$1" != "failure" ]; then + echo "Invalid parameter. Please provide either 'success' or 'failure'." + exit 1 +fi + +oncall_tag="" +if [ "$1" == "success" ]; then + text_value=":white_check_mark: HashiCorp Terraform Compatibility Matrix succeeded" + action_text="Successful action" +else + text_value=":red_circle: HashiCorp Terraform Compatibility Matrix failed" + action_text="Failed action" + oncall_tag="$2" +fi + +server_url=$3 +repository=$4 +run_id=$5 + +json="{ + \"text\": \"$text_value\", + \"blocks\": [ + { + \"type\": \"section\", + \"text\": { + \"type\": \"mrkdwn\", + \"text\": \"*$text_value* $oncall_tag\" + } + }, + { + \"type\": \"actions\", + \"elements\": [ + { + \"type\": \"button\", + \"text\": { + \"type\": \"plain_text\", + \"text\": \":github: $action_text\" + }, + \"url\": \"${server_url}/${repository}/actions/runs/${run_id}\" + } + ] + } + ] + }" + +echo "$json" | jq -c .