Skip to content

Commit

Permalink
[Issue #2980] Fire off an alert when any deploy fails (#2981)
Browse files Browse the repository at this point in the history
## Summary

Fixes #2980

### Time to review: __2 mins__

## Testing

<img width="531" alt="image"
src="https://github.com/user-attachments/assets/d914250a-f997-4e04-9931-5bcaf2bb7216">

(this was made easy by the fact that the API deploy is currently failing
due to anchore/grype scans)
  • Loading branch information
coilysiren authored Nov 21, 2024
1 parent e9eed30 commit 1b85220
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/actionlint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
paths:
# actionlint doesn't know how to handle the json inside of this file
.github/workflows/ci-cron-vulnerability-scans.yml:
.github/workflows/send-slack-notification.yml:
ignore:
- ".*SC2046.*"
6 changes: 6 additions & 0 deletions .github/workflows/cd-analytics-infra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,9 @@ jobs:
./bin/terraform-init.sh infra/analytics/${{ matrix.directory }} ${{ matrix.envs }}
export TF_CLI_ARGS="-input=false -auto-approve -var environment_name=${{ matrix.envs }}"
./bin/terraform-apply.sh infra/analytics/${{ matrix.directory }} ${{ matrix.envs }}
send-slack-notification:
if: failure()
needs: [build-repository, deploy-infra]
uses: ./.github/workflows/send-slack-notification.yml
secrets: inherit
6 changes: 6 additions & 0 deletions .github/workflows/cd-analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,9 @@ jobs:
with:
app_name: "analytics"
environment: ${{ matrix.envs }}

send-slack-notification:
if: failure()
needs: [analytics-checks, vulnerability-scans, deploy]
uses: ./.github/workflows/send-slack-notification.yml
secrets: inherit
6 changes: 6 additions & 0 deletions .github/workflows/cd-api-infra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,9 @@ jobs:
./bin/terraform-init.sh infra/api/${{ matrix.directory }} ${{ matrix.envs }}
export TF_CLI_ARGS="-input=false -auto-approve -var environment_name=${{ matrix.envs }}"
./bin/terraform-apply.sh infra/api/${{ matrix.directory }} ${{ matrix.envs }}
send-slack-notification:
if: failure()
needs: [build-repository, deploy-infra]
uses: ./.github/workflows/send-slack-notification.yml
secrets: inherit
6 changes: 6 additions & 0 deletions .github/workflows/cd-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ jobs:
with:
app_name: "api"
environment: ${{ matrix.envs }}

send-slack-notification:
if: failure()
needs: [api-checks, vulnerability-scans, deploy]
uses: ./.github/workflows/send-slack-notification.yml
secrets: inherit
6 changes: 6 additions & 0 deletions .github/workflows/cd-frontend-infra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,9 @@ jobs:
./bin/terraform-init.sh infra/frontend/${{ matrix.directory }} ${{ matrix.envs }}
export TF_CLI_ARGS="-input=false -auto-approve -var environment_name=${{ matrix.envs }}"
./bin/terraform-apply.sh infra/frontend/${{ matrix.directory }} ${{ matrix.envs }}
send-slack-notification:
if: failure()
needs: [build-repository, deploy-infra]
uses: ./.github/workflows/send-slack-notification.yml
secrets: inherit
6 changes: 6 additions & 0 deletions .github/workflows/cd-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ jobs:
with:
app_name: "frontend"
environment: ${{ matrix.envs }}

send-slack-notification:
if: failure()
needs: [frontend-checks, vulnerability-scans, deploy]
uses: ./.github/workflows/send-slack-notification.yml
secrets: inherit
6 changes: 6 additions & 0 deletions .github/workflows/cd-metabase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ jobs:
with:
version: ${{ inputs.image-tag }}
environment: ${{ matrix.envs }}

send-slack-notification:
if: failure()
needs: [deploy]
uses: ./.github/workflows/send-slack-notification.yml
secrets: inherit
28 changes: 1 addition & 27 deletions .github/workflows/ci-cron-vulnerability-scans.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,5 @@ jobs:
app_name: ${{ matrix.app_name }}

send-slack-notification:
name: Send Slack notification on failure
needs: vulnerability-scans
runs-on: ubuntu-latest
if: failure()
steps:
- name: Send Slack notification
run: |
curl -X POST -H "Authorization: Bearer ${{ secrets.ALERTS_SLACK_BOT_TOKEN }}" \
-H "Content-Type: application/json; charset=utf-8" \
--data '{
"channel": "${{ secrets.SLACK_ALERTS_CHANNEL_ID }}",
"text": ":x: *GitHub Actions Failure Alert*",
"attachments": [
{
"color": "#ff0000",
"title": "Workflow *'"${{ github.workflow }}"'* failed",
"fields": [
{
"title": "Workflow URL",
"value": "'"${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"'"
}
],
"footer": "GitHub Actions",
"footer_icon": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png",
"ts": '$(date +%s)'
}
]
}' https://slack.com/api/chat.postMessage
uses: ./.github/workflows/send-slack-notification.yml
32 changes: 32 additions & 0 deletions .github/workflows/send-slack-notification.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Slack Notification

on: workflow_call

jobs:
send-slack-notification:
name: Send Slack notification on failure
runs-on: ubuntu-latest
steps:
- name: Send Slack notification
run: |
curl -X POST -H "Authorization: Bearer ${{ secrets.ALERTS_SLACK_BOT_TOKEN }}" \
-H "Content-Type: application/json; charset=utf-8" \
--data '{
"channel": "${{ secrets.SLACK_ALERTS_CHANNEL_ID }}",
"text": ":x: *GitHub Actions Failure Alert*",
"attachments": [
{
"color": "#ff0000",
"title": "Workflow *'"${{ github.workflow }}"'* failed",
"fields": [
{
"title": "Workflow URL",
"value": "'"${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"'"
}
],
"footer": "GitHub Actions",
"footer_icon": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png",
"ts": '$(date +%s)'
}
]
}' https://slack.com/api/chat.postMessage

0 comments on commit 1b85220

Please sign in to comment.