Skip to content

Commit 4a7f7c8

Browse files
authored
ci: Send Slack notification when scheduled e2e tests fail (#1859)
## Summary Closes #1725. Adds a `notify_on_failure` job to `on_schedule_tests.yaml` that posts to `#tooling-team-python` whenever the daily scheduled e2e tests fail. The message includes a link to the workflow run and a bulleted list of the failed matrix combinations. Manual `workflow_dispatch` runs are intentionally skipped so ad-hoc triggers don't spam the channel. ## Implementation notes - Uses `slackapi/slack-github-action@v3.0.2` with `webhook-type: incoming-webhook`. - Webhook URL is read from a new repository secret `SLACK_WEBHOOK_URL` — needs to be configured before this PR has any effect. - The list of failed matrix jobs is fetched via `gh api .../actions/runs/{run_id}/attempts/{run_attempt}/jobs` (uses the existing `GITHUB_TOKEN` with `actions: read`). - Job runs only on `failure() && github.event_name == 'schedule'`. ## Setup checklist - [x] Create an incoming webhook for `#tooling-team-python` in Slack. - [x] Add the URL as the `SLACK_WEBHOOK_URL` repository secret.
1 parent 4ba9635 commit 4a7f7c8

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

.github/workflows/on_schedule_tests.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,60 @@ jobs:
6767
run: uv run poe e2e-templates-tests -m "${{ matrix.http-client }} and ${{ matrix.crawler-type }} and ${{ matrix.package-manager }}"
6868
env:
6969
APIFY_TEST_USER_API_TOKEN: ${{ secrets.APIFY_TEST_USER_API_TOKEN }}
70+
71+
# Send a Slack notification to #tooling-team-python when scheduled e2e tests fail.
72+
# Skipped on workflow_dispatch (manual runs) so that ad-hoc triggers don't spam the channel.
73+
notify_on_failure:
74+
name: Notify Slack on failure
75+
needs: end_to_end_tests
76+
if: failure() && github.event_name == 'schedule'
77+
runs-on: ubuntu-latest
78+
permissions:
79+
contents: read
80+
actions: read
81+
82+
steps:
83+
- name: Build Slack payload
84+
env:
85+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86+
REPO: ${{ github.repository }}
87+
RUN_ID: ${{ github.run_id }}
88+
RUN_ATTEMPT: ${{ github.run_attempt }}
89+
WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
90+
HEADING: ':red_circle: Scheduled e2e tests failed'
91+
run: |
92+
failed_jobs=$(gh api \
93+
"repos/${REPO}/actions/runs/${RUN_ID}/attempts/${RUN_ATTEMPT}/jobs?per_page=100" \
94+
--jq '[.jobs[] | select(.conclusion == "failure") | "• \(.name)"] | join("\n")')
95+
jq -n \
96+
--arg repo "${REPO}" \
97+
--arg url "${WORKFLOW_URL}" \
98+
--arg heading "${HEADING}" \
99+
--arg failed "${failed_jobs}" \
100+
'{
101+
text: "\($heading) in \($repo)",
102+
blocks: [
103+
{
104+
type: "header",
105+
text: { type: "plain_text", text: $heading, emoji: true }
106+
},
107+
{
108+
type: "section",
109+
fields: [
110+
{ type: "mrkdwn", text: "*Repository:*\n\($repo)" },
111+
{ type: "mrkdwn", text: "*Workflow run:*\n<\($url)|View on GitHub>" }
112+
]
113+
},
114+
{
115+
type: "section",
116+
text: { type: "mrkdwn", text: "*Failed jobs:*\n\($failed)" }
117+
}
118+
]
119+
}' > slack-payload.json
120+
121+
- name: Send Slack notification
122+
uses: slackapi/slack-github-action@v3.0.2
123+
with:
124+
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
125+
webhook-type: incoming-webhook
126+
payload-file-path: slack-payload.json

0 commit comments

Comments
 (0)