Skip to content

Commit 6e66ea6

Browse files
committed
fix: clean Slack alert formatting across showcase workflows
Use jq to build JSON payloads safely and payload-file-path to avoid inline multiline content. Limits error context to 3 lines, strips ANSI codes, and caps field length at 200 chars. - drift-detection: split payload build from post, sanitize playwright output - starter-smoke: replace toJSON(format(...)) double-encoding with jq - showcase_deploy: replace 300-char inline ternary with readable shell conditional
1 parent 203e0ad commit 6e66ea6

3 files changed

Lines changed: 42 additions & 11 deletions

File tree

.github/workflows/showcase_deploy.yml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,32 @@ jobs:
315315
echo "services=$SERVICES" >> $GITHUB_OUTPUT
316316
echo "count=$COUNT" >> $GITHUB_OUTPUT
317317
318-
- name: Collect results and notify Slack
318+
- name: Build Slack payload
319+
if: "${{ secrets.SLACK_WEBHOOK_OSS_ALERTS != '' }}"
320+
run: |
321+
URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
322+
DETECT="${{ needs.detect-changes.result }}"
323+
LOCKFILE="${{ needs.check-lockfile.result }}"
324+
BUILD="${{ needs.build.result }}"
325+
COUNT="${{ steps.summary.outputs.count }}"
326+
SERVICES=$(echo "${{ steps.summary.outputs.services }}" | cut -c1-200)
327+
328+
if [ "$DETECT" = "failure" ] || [ "$LOCKFILE" = "failure" ]; then
329+
MSG=":x: *Showcase deploy*: FAILED (pre-build check)"
330+
elif [ "$BUILD" = "success" ]; then
331+
MSG=":white_check_mark: *Showcase deploy*: ${COUNT} service(s) deployed to Railway (${SERVICES})"
332+
elif [ "$BUILD" = "skipped" ] && [ "$DETECT" = "success" ]; then
333+
MSG=":white_check_mark: *Showcase deploy*: no changes detected, nothing to deploy"
334+
else
335+
MSG=":x: *Showcase deploy*: FAILED — ${COUNT} service(s) targeted (${SERVICES})"
336+
fi
337+
338+
jq -n --arg text "$MSG | <$URL|View run>" '{text: $text}' > /tmp/slack-payload.json
339+
340+
- name: Post to Slack
319341
if: "${{ secrets.SLACK_WEBHOOK_OSS_ALERTS != '' }}"
320342
uses: slackapi/slack-github-action@v2.1.0
321343
with:
322344
webhook: ${{ secrets.SLACK_WEBHOOK_OSS_ALERTS }}
323345
webhook-type: incoming-webhook
324-
payload: |
325-
{
326-
"text": "${{ (needs.detect-changes.result == 'failure' || needs.check-lockfile.result == 'failure') && format(':x: *Showcase deploy*: FAILED (pre-build check)') || needs.build.result == 'success' && format(':white_check_mark: *Showcase deploy*: {0} service(s) deployed to Railway ({1})', steps.summary.outputs.count, steps.summary.outputs.services) || (needs.build.result == 'skipped' && needs.detect-changes.result == 'success') && ':white_check_mark: *Showcase deploy*: no changes detected, nothing to deploy' || format(':x: *Showcase deploy*: FAILED — {0} service(s) targeted ({1})', steps.summary.outputs.count, steps.summary.outputs.services) }} | <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View run>"
327-
}
346+
payload-file-path: /tmp/slack-payload.json

.github/workflows/showcase_drift-detection.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,21 @@ jobs:
7272
echo "EOFEOF"
7373
} >> "$GITHUB_OUTPUT"
7474
75+
- name: Build Slack payload
76+
if: failure()
77+
run: |
78+
SUMMARY=$(echo "${{ steps.failures.outputs.details }}" | head -3 | sed 's/\x1b\[[0-9;]*m//g' | cut -c1-200)
79+
URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
80+
jq -n --arg text ":x: *Showcase E2E suite failed*\n<$URL|View run>\n\`\`\`$SUMMARY\`\`\`" \
81+
'{text: $text}' > /tmp/slack-payload.json
82+
7583
- name: Post failure to Slack
7684
if: failure()
7785
uses: slackapi/slack-github-action@v2.1.0
7886
with:
7987
webhook: ${{ secrets.SLACK_WEBHOOK_OSS_ALERTS }}
8088
webhook-type: incoming-webhook
81-
payload: |
82-
{ "text": ":x: *Showcase E2E suite failed*\n<https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|View run>\n\n```\n${{ steps.failures.outputs.details }}\n```" }
89+
payload-file-path: /tmp/slack-payload.json
8390

8491
- name: Create issue on failure
8592
if: failure()

.github/workflows/starter-smoke.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,21 @@ jobs:
114114
path: showcase/tests/test-results/
115115
retention-days: 7
116116

117+
- name: Build Slack payload
118+
if: failure() && (github.event_name == 'schedule' || github.event_name == 'workflow_run')
119+
run: |
120+
SUMMARY=$(echo "${{ steps.failure-cause.outputs.summary }}" | head -3 | sed 's/\x1b\[[0-9;]*m//g' | cut -c1-200)
121+
URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
122+
jq -n --arg text ":x: *Starter smoke test failing: ${{ matrix.starter }}*\n<$URL|View run>\n\`\`\`$SUMMARY\`\`\`" \
123+
'{text: $text}' > /tmp/slack-payload.json
124+
117125
- name: Alert Slack on failure
118126
if: failure() && (github.event_name == 'schedule' || github.event_name == 'workflow_run')
119127
uses: slackapi/slack-github-action@v2.1.0
120128
with:
121129
webhook: ${{ secrets.SLACK_WEBHOOK_OSS_ALERTS }}
122130
webhook-type: incoming-webhook
123-
payload: |
124-
{
125-
"text": ${{ toJSON(format('Starter smoke test failing: *{0}*\n```{1}```\nRun: {2}/{3}/actions/runs/{4}', matrix.starter, steps.failure-cause.outputs.summary, github.server_url, github.repository, github.run_id)) }}
126-
}
131+
payload-file-path: /tmp/slack-payload.json
127132

128133
- name: Create GitHub issue on failure
129134
if: failure() && github.event_name == 'schedule'

0 commit comments

Comments
 (0)