Skip to content

Commit 0495773

Browse files
authored
ci: only notify Slack on drift detection or failure (#106)
## Summary Slack notifications for drift tests now follow a state-machine pattern: | Previous run | Current run | Slack? | |---|---|---| | any | drift detected | Yes — "Drift detected" | | any | infra failure | Yes — "Drift tests failed" | | failure | success | Yes — "Drift tests passing again" (recovery) | | success | success | No — stay quiet | Uses `gh run list` to check the previous run's conclusion at notification time. No external state storage needed. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
2 parents 98b3b5f + cd5537e commit 0495773

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

.github/workflows/test-drift.yml

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,41 @@ jobs:
6767
if-no-files-found: warn
6868
retention-days: 30
6969

70+
- name: Check previous run status
71+
id: prev
72+
if: always()
73+
run: |
74+
PREV=$(gh run list --workflow="Drift Tests" --branch=main --limit=2 --json conclusion --jq '.[1].conclusion // "unknown"')
75+
echo "conclusion=$PREV" >> $GITHUB_OUTPUT
76+
env:
77+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78+
7079
- name: Notify Slack
7180
if: always()
7281
run: |
73-
if [ "${{ steps.drift.outputs.exit_code }}" = "2" ]; then
82+
if [ -z "${{ secrets.SLACK_WEBHOOK }}" ]; then exit 0; fi
83+
84+
PREV="${{ steps.prev.outputs.conclusion }}"
85+
NOW="${{ job.status }}"
86+
DRIFT="${{ steps.drift.outputs.exit_code }}"
87+
88+
# Drift detected — always notify
89+
if [ "$DRIFT" = "2" ]; then
7490
EMOJI="🚨"
7591
MSG="*Drift detected* in aimock — providers changed response formats. <https://github.com/CopilotKit/aimock/actions/runs/${{ github.run_id }}|View run>"
76-
elif [ "${{ job.status }}" = "success" ]; then
77-
EMOJI="✅"
78-
MSG="Drift tests passed — all providers match."
79-
else
92+
# Infra failure — always notify
93+
elif [ "$NOW" != "success" ]; then
8094
EMOJI="❌"
8195
MSG="*Drift tests failed* (infra error). <https://github.com/CopilotKit/aimock/actions/runs/${{ github.run_id }}|View run>"
96+
# Recovery: previous was bad, now good — notify once
97+
elif [ "$PREV" = "failure" ]; then
98+
EMOJI="✅"
99+
MSG="Drift tests passing again — all providers match."
100+
# Good → good — stay quiet
101+
else
102+
exit 0
82103
fi
104+
83105
curl -s -X POST "${{ secrets.SLACK_WEBHOOK }}" \
84106
-H "Content-Type: application/json" \
85107
-d "{\"text\": \"${EMOJI} ${MSG}\"}"

0 commit comments

Comments
 (0)