Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b279d2e

Browse files
refactor(.github/workflows): consolidate Slack notifications
Select the failure alert or no-change heartbeat in one final step. This removes duplicated webhook validation, JSON encoding, and curl setup, and prevents a failed heartbeat delivery from triggering a second, contradictory failure notification.
1 parent 915c61b commit b279d2e

1 file changed

Lines changed: 15 additions & 20 deletions

File tree

.github/workflows/aigateway-prices-refresh.yaml

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -153,37 +153,32 @@ jobs:
153153
--jq '.html_url'
154154
fi
155155
156-
- name: Send Slack notification when price book is current
157-
if: steps.detect.outputs.changed == 'false'
156+
- name: Send Slack notification
157+
if: failure() || steps.detect.outputs.changed == 'false'
158158
env:
159+
REFRESH_STATUS: ${{ job.status }}
160+
PRICE_BOOK_CHANGED: ${{ steps.detect.outputs.changed }}
159161
SLACK_WEBHOOK: ${{ secrets.AIGATEWAY_PRICES_SLACK_WEBHOOK }}
160162
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
161163
run: |
162164
set -euo pipefail
163165
if [ -z "${SLACK_WEBHOOK}" ]; then
164-
echo "::error::AIGATEWAY_PRICES_SLACK_WEBHOOK is not set; the no-change notification could not be sent."
166+
echo "::error::AIGATEWAY_PRICES_SLACK_WEBHOOK is not set; the notification could not be sent."
165167
exit 1
166168
fi
167-
text=":white_check_mark: *AI Gateway price book refresh completed.* No generated changes were found. Run: ${RUN_URL}"
168-
payload="$(jq -nc --arg text "${text}" '{text: $text}')"
169-
curl -fsSL -X POST -H 'Content-type: application/json' -d "${payload}" "${SLACK_WEBHOOK}"
170-
echo "Sent Slack notification"
171169
172-
- name: Send Slack notification on failure
173-
if: failure()
174-
env:
175-
SLACK_WEBHOOK: ${{ secrets.AIGATEWAY_PRICES_SLACK_WEBHOOK }}
176-
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
177-
run: |
178-
set -euo pipefail
179-
if [ -z "${SLACK_WEBHOOK}" ]; then
180-
echo "::error::AIGATEWAY_PRICES_SLACK_WEBHOOK is not set; the failure alert could not be sent."
170+
if [ "${REFRESH_STATUS}" = "failure" ]; then
171+
# printf, not a double-quoted literal: bash leaves \n as two
172+
# characters, and jq --arg then escapes the backslash, so Slack
173+
# would print \n as text instead of breaking the line.
174+
text="$(printf ':warning: *AI model price book refresh failed.*\nThe generator fails by design when upstream drops a model pinned in scripts/aibridgepricesgen/overrides.jq or curated in curation.json. Logs: %s' "${RUN_URL}")"
175+
elif [ "${PRICE_BOOK_CHANGED}" = "false" ]; then
176+
text=":white_check_mark: *AI Gateway price book refresh completed.* No generated changes were found. Run: ${RUN_URL}"
177+
else
178+
echo "::error::Unexpected notification state: status=${REFRESH_STATUS}, changed=${PRICE_BOOK_CHANGED}"
181179
exit 1
182180
fi
183-
# printf, not a double-quoted literal: bash leaves \n as two
184-
# characters, and jq --arg then escapes the backslash, so Slack
185-
# would print \n as text instead of breaking the line.
186-
text="$(printf ':warning: *AI model price book refresh failed.*\nThe generator fails by design when upstream drops a model pinned in scripts/aibridgepricesgen/overrides.jq or curated in curation.json. Logs: %s' "${RUN_URL}")"
181+
187182
payload="$(jq -nc --arg text "${text}" '{text: $text}')"
188183
curl -fsSL -X POST -H 'Content-type: application/json' -d "${payload}" "${SLACK_WEBHOOK}"
189184
echo "Sent Slack notification"

0 commit comments

Comments
 (0)