diff --git a/.github/scripts/notify_slack.sh b/.github/scripts/notify_slack.sh deleted file mode 100755 index 8df3f3f648..0000000000 --- a/.github/scripts/notify_slack.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bash -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: BUSL-1.1 - -set -uo pipefail - -# This script is used in GitHub Actions pipelines to notify Slack of a job failure. - -if [[ $GITHUB_REF_NAME == "main" ]]; then - GITHUB_ENDPOINT="https://github.com/${GITHUB_REPOSITORY}/commit/${GITHUB_SHA}" - GITHUB_ACTIONS_ENDPOINT="https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" - COMMIT_MESSAGE=$(git log -1 --pretty=%B | head -n1) - SHORT_REF=$(git rev-parse --short "${GITHUB_SHA}") - curl -X POST -H 'Content-type: application/json' \ - --data \ - "{ \ - \"attachments\": [ \ - { \ - \"fallback\": \"GitHub Actions workflow failed!\", \ - \"text\": \"❌ Failed: \`${GITHUB_ACTOR}\`'s <${GITHUB_ACTIONS_ENDPOINT}|${GITHUB_JOB}> job failed for commit <${GITHUB_ENDPOINT}|${SHORT_REF}> on \`${GITHUB_REF_NAME}\`!\n\n- <${COMMIT_MESSAGE}\", \ - \"footer\": \"${GITHUB_REPOSITORY}\", \ - \"ts\": \"$(date +%s)\", \ - \"color\": \"danger\" \ - } \ - ] \ - }" "${FEED_CONSUL_GH_URL}" -else - echo "Not posting slack failure notifications for non-main branch" -fi diff --git a/.github/workflows/go-tests.yml b/.github/workflows/go-tests.yml index b04f424410..57d993b80f 100644 --- a/.github/workflows/go-tests.yml +++ b/.github/workflows/go-tests.yml @@ -94,9 +94,6 @@ jobs: fi - run: make proto-lint name: "Protobuf Lint" - - name: Notify Slack - if: ${{ failure() }} - run: .github/scripts/notify_slack.sh check-codegen: needs: - setup @@ -116,9 +113,6 @@ jobs: echo "Generated code was not updated correctly" exit 1 fi - - name: Notify Slack - if: ${{ failure() }} - run: .github/scripts/notify_slack.sh lint-enums: needs: @@ -134,9 +128,6 @@ jobs: with: go-version-file: 'go.mod' - run: go install github.com/reillywatson/enumcover/cmd/enumcover@master && enumcover ./... - - name: Notify Slack - if: ${{ failure() }} - run: .github/scripts/notify_slack.sh lint-container-test-deps: needs: @@ -151,9 +142,6 @@ jobs: with: go-version-file: 'go.mod' - run: make lint-container-test-deps - - name: Notify Slack - if: ${{ failure() }} - run: .github/scripts/notify_slack.sh lint-consul-retry: needs: @@ -169,9 +157,6 @@ jobs: with: go-version-file: 'go.mod' - run: go install github.com/hashicorp/lint-consul-retry@master && lint-consul-retry - - name: Notify Slack - if: ${{ failure() }} - run: .github/scripts/notify_slack.sh lint: needs: @@ -516,3 +501,15 @@ jobs: printf "Tests failed or workflow cancelled:\n\n${{ toJSON(needs) }}" exit 1 fi + - name: Notify Slack + if: ${{ failure() && (github.ref_name == 'main' || startsWith(github.ref_name, 'release/')) }} + id: slack + uses: slackapi/slack-github-action@e28cf165c92ffef168d23c5c9000cffc8a25e117 # v1.24.0 + with: + # github.event.head_commit.message and github.ref_name both rely on this event occurring on a push / merge + payload: | + { + "message": "❌ ${{ github.workflow }} workflow failed: \n\n- Run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} \n- Branch: ${{ github.ref_name }} \n- Message: ${{ github.event.head_commit.message }} \n- Author: ${{ github.event.sender.login }}" + } + env: + SLACK_WEBHOOK_URL: ${{ secrets.CONSUL_NIGHTLY_INTEG_TEST_SLACK_WEBHOOK }} \ No newline at end of file diff --git a/.github/workflows/reusable-check-go-mod.yml b/.github/workflows/reusable-check-go-mod.yml index 7fffb61687..72442b2184 100644 --- a/.github/workflows/reusable-check-go-mod.yml +++ b/.github/workflows/reusable-check-go-mod.yml @@ -33,6 +33,3 @@ jobs: git status -s exit 1 fi - - name: Notify Slack - if: ${{ failure() }} - run: .github/scripts/notify_slack.sh diff --git a/.github/workflows/reusable-dev-build-windows.yml b/.github/workflows/reusable-dev-build-windows.yml index 01247c4778..b6bde2653b 100644 --- a/.github/workflows/reusable-dev-build-windows.yml +++ b/.github/workflows/reusable-dev-build-windows.yml @@ -42,6 +42,3 @@ jobs: with: name: ${{inputs.uploaded-binary-name}} path: consul.exe - - name: Notify Slack - if: ${{ failure() }} - run: .github/scripts/notify_slack.sh diff --git a/.github/workflows/reusable-dev-build.yml b/.github/workflows/reusable-dev-build.yml index 99bcb96592..eaf9a643eb 100644 --- a/.github/workflows/reusable-dev-build.yml +++ b/.github/workflows/reusable-dev-build.yml @@ -54,6 +54,3 @@ jobs: with: name: ${{inputs.uploaded-binary-name}} path: ./bin/consul - - name: Notify Slack - if: ${{ failure() }} - run: .github/scripts/notify_slack.sh diff --git a/.github/workflows/reusable-lint.yml b/.github/workflows/reusable-lint.yml index 7863cc2317..52d2dc67d9 100644 --- a/.github/workflows/reusable-lint.yml +++ b/.github/workflows/reusable-lint.yml @@ -55,6 +55,3 @@ jobs: version: v1.51.1 args: --build-tags="${{ env.GOTAGS }}" -v skip-cache: true - - name: Notify Slack - if: ${{ failure() }} - run: .github/scripts/notify_slack.sh diff --git a/.github/workflows/reusable-unit-split.yml b/.github/workflows/reusable-unit-split.yml index 3d959d168b..6f842a162c 100644 --- a/.github/workflows/reusable-unit-split.yml +++ b/.github/workflows/reusable-unit-split.yml @@ -175,6 +175,3 @@ jobs: - name: "Re-run fails report" run: | .github/scripts/rerun_fails_report.sh /tmp/gotestsum-rerun-fails - - name: Notify Slack - if: ${{ failure() }} - run: .github/scripts/notify_slack.sh diff --git a/.github/workflows/reusable-unit.yml b/.github/workflows/reusable-unit.yml index 3b50bfa7e3..1e05f3909b 100644 --- a/.github/workflows/reusable-unit.yml +++ b/.github/workflows/reusable-unit.yml @@ -154,6 +154,3 @@ jobs: - name: "Re-run fails report" run: | .github/scripts/rerun_fails_report.sh /tmp/gotestsum-rerun-fails - - name: Notify Slack - if: ${{ failure() }} - run: .github/scripts/notify_slack.sh