From 69596c5085e0b7a6d079ecec89f3210ddeb6c4e4 Mon Sep 17 00:00:00 2001 From: Aafreen Ansari Date: Wed, 22 Nov 2023 21:24:44 +0000 Subject: [PATCH 1/2] added slack failure notification --- .github/workflows/scheduled-baseline.yml | 11 ++++++++++- .github/workflows/scorecards.yml | 10 ++++++++++ .github/workflows/terraform-member-environment.yml | 9 +++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/.github/workflows/scheduled-baseline.yml b/.github/workflows/scheduled-baseline.yml index 33064b253..f9cb14133 100644 --- a/.github/workflows/scheduled-baseline.yml +++ b/.github/workflows/scheduled-baseline.yml @@ -49,7 +49,16 @@ jobs: - id: set-matrix name: Set Up Matrix run: echo "matrix=$(terraform -chdir=terraform/environments/bootstrap/delegate-access workspace list | sed -e "s/*//" -e "s/^[[:space:]]*//" -e "/default/d" -e "/^$/d" | sort -u | jq -ncR '[inputs]')" >> $GITHUB_OUTPUT - + - name: Slack failure notification + uses: slackapi/slack-github-action@e28cf165c92ffef168d23c5c9000cffc8a25e117 # v1.24.0 + with: + payload: | + {"blocks":[{"type": "section","text": {"type": "mrkdwn","text": ":no_entry: Failed GitHub Action:"}},{"type": "section","fields":[{"type": "mrkdwn","text": "*Workflow:*\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.workflow }}>"},{"type": "mrkdwn","text": "*Job:*\n${{ github.job }}"},{"type": "mrkdwn","text": "*Repo:*\n${{ github.repository }}"}]}]} + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK + if: ${{ failure() }} + delegate-access: strategy: fail-fast: false diff --git a/.github/workflows/scorecards.yml b/.github/workflows/scorecards.yml index 3c1755c29..9a84e9fd6 100644 --- a/.github/workflows/scorecards.yml +++ b/.github/workflows/scorecards.yml @@ -70,3 +70,13 @@ jobs: uses: github/codeql-action/upload-sarif@cdcdbb579706841c47f7063dda365e292e5cad7a # v2.13.4 with: sarif_file: results.sarif + + - name: Slack failure notification + uses: slackapi/slack-github-action@e28cf165c92ffef168d23c5c9000cffc8a25e117 # v1.24.0 + with: + payload: | + {"blocks":[{"type": "section","text": {"type": "mrkdwn","text": ":no_entry: Failed GitHub Action:"}},{"type": "section","fields":[{"type": "mrkdwn","text": "*Workflow:*\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.workflow }}>"},{"type": "mrkdwn","text": "*Job:*\n${{ github.job }}"},{"type": "mrkdwn","text": "*Repo:*\n${{ github.repository }}"}]}]} + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK + if: ${{ failure() }} \ No newline at end of file diff --git a/.github/workflows/terraform-member-environment.yml b/.github/workflows/terraform-member-environment.yml index 17bb6d247..ac51b810a 100644 --- a/.github/workflows/terraform-member-environment.yml +++ b/.github/workflows/terraform-member-environment.yml @@ -48,6 +48,15 @@ jobs: fi >> $GITHUB_OUTPUT - name: Display changed directories run: echo "Directories in scope:" ${{ steps.directories.outputs.CHANGED_DIRECTORIES }} + - name: Slack failure notification + uses: slackapi/slack-github-action@e28cf165c92ffef168d23c5c9000cffc8a25e117 # v1.24.0 + with: + payload: | + {"blocks":[{"type": "section","text": {"type": "mrkdwn","text": ":no_entry: Failed GitHub Action:"}},{"type": "section","fields":[{"type": "mrkdwn","text": "*Workflow:*\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.workflow }}>"},{"type": "mrkdwn","text": "*Job:*\n${{ github.job }}"},{"type": "mrkdwn","text": "*Repo:*\n${{ github.repository }}"}]}]} + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK + if: ${{ failure() }} outputs: directories: ${{ steps.directories.outputs.CHANGED_DIRECTORIES }} From d4e7cdc01d853bc56c1184bd8c5e23dd8b195cfe Mon Sep 17 00:00:00 2001 From: Aafreen Ansari Date: Thu, 23 Nov 2023 11:54:28 +0000 Subject: [PATCH 2/2] update slack failure notification checks --- .github/workflows/terraform-member-environment.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/terraform-member-environment.yml b/.github/workflows/terraform-member-environment.yml index ac51b810a..aeec3bba0 100644 --- a/.github/workflows/terraform-member-environment.yml +++ b/.github/workflows/terraform-member-environment.yml @@ -56,7 +56,7 @@ jobs: env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK - if: ${{ failure() }} + if: ${{ failure() }} && github.event.ref == 'refs/heads/main' outputs: directories: ${{ steps.directories.outputs.CHANGED_DIRECTORIES }} @@ -122,6 +122,15 @@ jobs: scripts/terraform-plan.sh $directory unset workspace done + - name: Slack failure notification + uses: slackapi/slack-github-action@e28cf165c92ffef168d23c5c9000cffc8a25e117 # v1.24.0 + with: + payload: | + {"blocks":[{"type": "section","text": {"type": "mrkdwn","text": ":no_entry: Failed GitHub Action:"}},{"type": "section","fields":[{"type": "mrkdwn","text": "*Workflow:*\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.workflow }}>"},{"type": "mrkdwn","text": "*Job:*\n${{ github.job }}"},{"type": "mrkdwn","text": "*Repo:*\n${{ github.repository }}"}]}]} + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK + if: ${{ failure() }} && github.event.ref == 'refs/heads/main' - name: Mark job skipped if: ${{ steps.workspace.outputs.skip_plan == 'true' }} run: |