Skip to content

Commit c874ad7

Browse files
bvu405meta-codesync[bot]
authored andcommitted
Notify GChat on CI workflow failure
Summary: Adds a separate `notify` job to the OSS CI workflow that POSTs a Google Chat message (URL stored in `GCHAT_WEBHOOK_URL` repo secret) when the `build-and-test` matrix has any failing leg. The message includes repo, branch, workflow name, and a direct link to the failed run. Why a workflow-level `notify` job (not per-step or per-leg): - The `build-and-test` matrix has 6 legs (2 OS x 3 Python). A per-step `if: failure()` notification would send up to 6 GChat messages on a single broken commit. Aggregating into a downstream `notify` job collapses that to a single notification per workflow run. - `needs: build-and-test` makes the notify job run after every leg finishes; `if: failure()` at job scope evaluates the rolled-up status of needed jobs, so it fires exactly once when any leg failed (and not at all on success or cancellation). - Keeps the `build-and-test` job focused on actual build/test work; the notify side-effect is composed in via the workflow DAG. Reviewed By: pdepetro Differential Revision: D104847779 fbshipit-source-id: 6cdafde56c85ffdb88f3a7ce54b65100c8fa6147
1 parent 1cc1b5a commit c874ad7

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,28 @@ jobs:
5454

5555
- name: Run tests
5656
run: pytest tests/ -v
57+
58+
notify:
59+
name: notify-on-failure
60+
needs: build-and-test
61+
# Single workflow-level notification: fires once if ANY leg of the
62+
# build-and-test matrix failed, instead of per-leg (avoids 6x noise
63+
# from the 2 OS x 3 Python matrix). `failure()` at job scope returns
64+
# true when any job in `needs:` has the `failure` result.
65+
if: ${{ failure() }}
66+
runs-on: ubuntu-latest
67+
timeout-minutes: 5
68+
steps:
69+
- name: Notify GChat on failure
70+
env:
71+
GCHAT_WEBHOOK_URL: ${{ secrets.GCHAT_WEBHOOK_URL }}
72+
REPO: ${{ github.repository }}
73+
REF_NAME: ${{ github.ref_name }}
74+
WORKFLOW: ${{ github.workflow }}
75+
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
76+
run: |
77+
text=$(printf '❌ *GitHub Action Failed*\n\n*Repo:* %s\n*Branch:* %s\n*Workflow:* %s\n*Run:* %s' \
78+
"$REPO" "$REF_NAME" "$WORKFLOW" "$RUN_URL")
79+
curl -X POST "$GCHAT_WEBHOOK_URL" \
80+
-H 'Content-Type: application/json' \
81+
-d "$(jq -n --arg text "$text" '{text: $text}')"

0 commit comments

Comments
 (0)