Skip to content

Commit

Permalink
chore: Send Slack message for Terraform Compatibility Matrix is execu…
Browse files Browse the repository at this point in the history
…ted (#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 4b0e49e.

* Revert "test echo job status"

This reverts commit 4a83862.

* test getting outputs of matrix

* result

* send slack

* checkout step

* fix name

* correct json

* formating

* Revert "formating"

This reverts commit f584822.

* format

* try

* Revert "try"

This reverts commit 7029f54.

* use cat

* Revert "use cat"

This reverts commit 9503cd2.

* remove unnecesary double quote

* try cat

* Revert "try cat"

This reverts commit a2df8ff.

* 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 5a7944f.

* 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 <EspenAlbert@users.noreply.github.com>
Co-authored-by: maastha <122359335+maastha@users.noreply.github.com>
  • Loading branch information
5 people committed Mar 22, 2024
1 parent b07a93f commit a9089ea
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 4 deletions.
24 changes: 22 additions & 2 deletions .github/workflows/terraform-compatibility-matrix.yml
Expand Up @@ -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:
Expand Down Expand Up @@ -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


42 changes: 40 additions & 2 deletions .github/workflows/test-suite.yml
Expand Up @@ -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 }}'
Expand Down Expand Up @@ -84,4 +84,42 @@ jobs:
if: ${{ !cancelled() }}
secrets: inherit
uses: ./.github/workflows/cleanup-test-env.yml


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
70 changes: 70 additions & 0 deletions 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 <success|failure>"
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 .

0 comments on commit a9089ea

Please sign in to comment.