|
78 | 78 | sandbox: ndr-dev |
79 | 79 | secrets: |
80 | 80 | AWS_ASSUME_ROLE: ${{ secrets.AWS_ASSUME_ROLE }} |
| 81 | + |
| 82 | + notify-slack: |
| 83 | + runs-on: ubuntu-latest |
| 84 | + needs: [check_packages, run_tests, publish_all_lambda_layers, deploy_all_lambdas, deploy_data_collection] |
| 85 | + if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 86 | + steps: |
| 87 | + - name: Configure AWS Credentials |
| 88 | + uses: aws-actions/configure-aws-credentials@v5 |
| 89 | + with: |
| 90 | + role-to-assume: ${{ secrets.AWS_ASSUME_ROLE }} |
| 91 | + role-skip-session-tagging: true |
| 92 | + aws-region: ${{ vars.AWS_REGION }} |
| 93 | + mask-aws-account-id: true |
| 94 | + |
| 95 | + - name: Get slack bot token from SSM parameter store |
| 96 | + id: ssm-parameters |
| 97 | + run: | |
| 98 | + slack_bot_token=$(aws ssm get-parameter --name "/ndr/alerting/slack/bot_token" --with-decryption --query "Parameter.Value" --output text) |
| 99 | + echo "::add-mask::$slack_bot_token" |
| 100 | + echo "SLACK_BOT_TOKEN=$slack_bot_token" >> $GITHUB_ENV |
| 101 | + |
| 102 | + - name: Send Slack Notification |
| 103 | + uses: slackapi/slack-github-action@v2.1.1 |
| 104 | + with: |
| 105 | + method: chat.postMessage |
| 106 | + token: ${{ env.SLACK_BOT_TOKEN }} |
| 107 | + payload: | |
| 108 | + { |
| 109 | + "channel": "${{ vars.ALERTS_SLACK_CHANNEL_ID }}", |
| 110 | + "attachments": [ |
| 111 | + { |
| 112 | + "color": "#ff0000", |
| 113 | + "blocks": [ |
| 114 | + { |
| 115 | + "type": "header", |
| 116 | + "text": { |
| 117 | + "type": "plain_text", |
| 118 | + "text": "❌ Workflow `${{ github.workflow }}` failed" |
| 119 | + } |
| 120 | + }, |
| 121 | + { |
| 122 | + "type": "section", |
| 123 | + "text": { |
| 124 | + "type": "mrkdwn", |
| 125 | + "text": "*Triggered by:* `${{ github.actor }}`\n*Workflow:* <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.workflow }}>" |
| 126 | + } |
| 127 | + }, |
| 128 | + { |
| 129 | + "type": "divider" |
| 130 | + }, |
| 131 | + { |
| 132 | + "type": "section", |
| 133 | + "fields": [ |
| 134 | + { |
| 135 | + "type": "mrkdwn", |
| 136 | + "text": "*check_packages:* ${{ needs.check_packages.result == 'success' && ':white_check_mark:' || ':x:' }}" |
| 137 | + }, |
| 138 | + { |
| 139 | + "type": "mrkdwn", |
| 140 | + "text": "*run_tests:* ${{ needs.run_tests.result == 'success' && ':white_check_mark:' || ':x:' }}" |
| 141 | + }, |
| 142 | + { |
| 143 | + "type": "mrkdwn", |
| 144 | + "text": "*publish_all_lambda_layers:* ${{ needs.publish_all_lambda_layers.result == 'success' && ':white_check_mark:' || ':x:' }}" |
| 145 | + }, |
| 146 | + { |
| 147 | + "type": "mrkdwn", |
| 148 | + "text": "*deploy_all_lambdas:* ${{ needs.deploy_all_lambdas.result == 'success' && ':white_check_mark:' || ':x:' }}" |
| 149 | + }, |
| 150 | + { |
| 151 | + "type": "mrkdwn", |
| 152 | + "text": "*deploy_data_collection:* ${{ needs.deploy_data_collection.result == 'success' && ':white_check_mark:' || ':x:' }}" |
| 153 | + } |
| 154 | + ] |
| 155 | + }, |
| 156 | + { |
| 157 | + "type": "context", |
| 158 | + "elements": [ |
| 159 | + { |
| 160 | + "type": "mrkdwn", |
| 161 | + "text": "Environment: `development` | Sandbox: `ndr-dev`" |
| 162 | + } |
| 163 | + ] |
| 164 | + } |
| 165 | + ] |
| 166 | + } |
| 167 | + ] |
| 168 | + } |
0 commit comments