Skip to content

Commit 10edf63

Browse files
authored
fix: clean Slack alert formatting across showcase workflows (CopilotKit#3914)
## Summary - **drift-detection**: Split inline payload into `jq`-built file + `payload-file-path`; sanitize playwright output (strip ANSI, head -3, cap 200 chars) - **starter-smoke**: Replace `toJSON(format(...))` double-encoding with `jq` payload builder - **showcase_deploy**: Replace 300-char inline ternary with readable shell conditional + `jq` All three workflows now use the same pattern: build a sanitized JSON file with `jq -n`, then reference it via `payload-file-path`. This eliminates raw `%0A` in Slack messages, unformatted stack traces, and double-encoded JSON. ## Test plan - [ ] Trigger `showcase_drift-detection.yml` manually — verify Slack alert formats correctly on failure - [ ] Trigger `starter-smoke.yml` manually — verify Slack alert on a known-failing starter - [ ] Trigger `showcase_deploy.yml` with `service: shell` — verify deploy notification renders cleanly - [ ] Confirm no `%0A` or raw escape sequences appear in any Slack message
2 parents 886ce96 + 6e66ea6 commit 10edf63

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
@@ -113,16 +113,21 @@ jobs:
113113
path: showcase/tests/test-results/
114114
retention-days: 7
115115

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

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

0 commit comments

Comments
 (0)