From c18d52140991c567e4dea44b61cf8f35907539c6 Mon Sep 17 00:00:00 2001 From: Anagh Hegde Date: Wed, 13 Nov 2024 11:13:07 +0530 Subject: [PATCH] chore: add alerts for push failures in sync release to pg flow (#37355) --- .github/workflows/sync-release-to-pg.yml | 31 +++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sync-release-to-pg.yml b/.github/workflows/sync-release-to-pg.yml index b5bd192f59..a962d28c9e 100644 --- a/.github/workflows/sync-release-to-pg.yml +++ b/.github/workflows/sync-release-to-pg.yml @@ -50,7 +50,36 @@ jobs: - name: Push changes if: env.MERGE_CONFLICT == 'false' run: | - git push origin pg + set -e + git push origin pg || echo "PUSH_FAILURE=true" >> $GITHUB_ENV + + - name: Capture push failure message + if: env.PUSH_FAILURE == 'true' + run: | + # Capture the last git error message + push_error_message=$(git push origin pg 2>&1 | tail -n 1) + echo "PUSH_ERROR_MESSAGE=$push_error_message" >> $GITHUB_ENV + + - name: Notify on push failure + if: env.PUSH_FAILURE == 'true' + env: + SLACK_MESSAGE: "Push to pg branch failed: ${{ env.PUSH_ERROR_MESSAGE }}" + run: | + # Format the Slack message + slack_message="${{ env.SLACK_MESSAGE }}" + + # Set the Slack message body with channel ID and text + body="$(jq -nc \ + --arg channel C07JMLWEXDJ \ + --arg text "$slack_message" \ + '$ARGS.named' + )" + + # Send the message to Slack + curl -v https://slack.com/api/chat.postMessage \ + --header "Authorization: Bearer ${{ secrets.SLACK_APPSMITH_ALERTS_TOKEN }}" \ + --header "Content-Type: application/json; charset=utf-8" \ + --data-raw "$body" - name: Notify on merge conflicts if: env.MERGE_CONFLICT == 'true'