Skip to content

Commit 0ccc0e5

Browse files
authored
build: setup slack notifications for circleci jobs (#19608)
Whenever a CI job fails in a non-PR build, the failure will be reported to the `#components-ci-failures` Slack channel. Obviously this can become very verbose as it will report every individual CI job, but that cannot be improved at the time of writing, as CircleCI does not support post-workflow logic. Interestingly there is also a legacy option in the old CircleCI UI for Slack notifications, but for the sake of not relying on that, we use the new recommended way of controlling notifications inside the actual CircleCI configuration.
1 parent a9cabf5 commit 0ccc0e5

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

.circleci/config.yml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ var_20: &only_on_pull_requests_filter
138138
only:
139139
- /pull\/\d+/
140140

141+
# Anchor for a step that notifies Slack when preceding steps failed.
142+
var_21: &slack_notify_on_failure
143+
run:
144+
name: "Notifying team about job failure"
145+
when: on_fail
146+
command: ./scripts/notify-slack-job-failure.sh
147+
141148
# -----------------------------
142149
# Container version of CircleCI
143150
# -----------------------------
@@ -168,6 +175,7 @@ jobs:
168175
# Exclude release and docs packages here as those will be built within
169176
# the "build_release_packages" and "publish_snapshots" jobs.
170177
- run: bazel build src/... --build_tag_filters=-docs-package,-release-package
178+
- *slack_notify_on_failure
171179

172180
# -----------------------------------
173181
# Job which ensures that all non-test Bazel targets build properly
@@ -189,6 +197,7 @@ jobs:
189197
# Exclude release and docs packages here as those will be built within
190198
# the "build_release_packages" and "publish_snapshots" jobs.
191199
- run: bazel build src/... --build_tag_filters=-docs-package,-release-package --config=view-engine
200+
- *slack_notify_on_failure
192201

193202
# --------------------------------------------------------------------------------------------
194203
# Job that runs ts-api-guardian against our API goldens in "tools/public_api_guard".
@@ -208,6 +217,7 @@ jobs:
208217
- *setup_bazel_binary
209218

210219
- run: bazel test tools/public_api_guard/...
220+
- *slack_notify_on_failure
211221

212222
# -----------------------------------------------------------------
213223
# Job that runs the e2e tests with Protractor and Chromium headless
@@ -226,6 +236,7 @@ jobs:
226236
- *setup_bazel_binary
227237

228238
- run: bazel test src/... --build_tag_filters=e2e --test_tag_filters=e2e --build_tests_only
239+
- *slack_notify_on_failure
229240

230241
# ------------------------------------------------------------------------------------------
231242
# Job that runs the unit tests on locally installed browsers (Chrome and Firefox headless).
@@ -245,6 +256,7 @@ jobs:
245256
- *setup_bazel_binary
246257

247258
- run: bazel test src/... --build_tag_filters=-e2e --test_tag_filters=-e2e --build_tests_only
259+
- *slack_notify_on_failure
248260

249261
# ----------------------------------------------------------------------------
250262
# Job that runs the unit tests on Browserstack. The browsers that will be used
@@ -263,6 +275,7 @@ jobs:
263275
- *yarn_install
264276

265277
- run: ./scripts/circleci/run-browserstack-tests.sh
278+
- *slack_notify_on_failure
266279

267280
# ----------------------------------------------------------------------------
268281
# Job that runs the unit tests on Saucelabs. The browsers that will be used
@@ -284,6 +297,7 @@ jobs:
284297
- *yarn_install
285298

286299
- run: ./scripts/circleci/run-saucelabs-tests.sh
300+
- *slack_notify_on_failure
287301

288302
# ----------------------------------
289303
# Lint job.
@@ -315,6 +329,7 @@ jobs:
315329
- run: yarn tslint
316330
- run: yarn -s ts-circular-deps:check
317331

332+
- *slack_notify_on_failure
318333
- *save_cache
319334

320335
# -------------------------------------------------------------------------------------------
@@ -369,6 +384,7 @@ jobs:
369384
- store_artifacts:
370385
path: /tmp/cdk-umd-minified-bundles
371386
destination: /angular_material/cdk_release_output/
387+
- *slack_notify_on_failure
372388

373389
upload_release_packages:
374390
<<: *job_defaults
@@ -411,8 +427,8 @@ jobs:
411427
# as part of this job to the docs-content repository. It's not contained in the
412428
# attached release output, so we need to build it here.
413429
- run: bazel build src/components-examples:npm_package --config=release
414-
415430
- run: ./scripts/circleci/publish-snapshots.sh
431+
- *slack_notify_on_failure
416432

417433
# -----------------------------------------------------------------
418434
# Job that ensures that the release output is compatible with ngcc.
@@ -435,6 +451,7 @@ jobs:
435451
# tsconfig parsing as that causes the release packages to be incorrectly resolved
436452
# to the sources due to path mapping.
437453
- run: yarn ngcc --error-on-failed-entry-point --no-tsconfig
454+
- *slack_notify_on_failure
438455

439456
# -----------------------------------------------------------------
440457
# Job that ensures that the release output is compatible with the
@@ -459,6 +476,7 @@ jobs:
459476
# tsconfig parsing as that causes the release packages to be incorrectly resolved
460477
# to the sources due to path mapping.
461478
- run: yarn ngcc --error-on-failed-entry-point --no-tsconfig
479+
- *slack_notify_on_failure
462480

463481
# ----------------------------------------------------------------------------
464482
# Job that runs the local browser tests against the Angular Github snapshots
@@ -479,6 +497,7 @@ jobs:
479497
- *setup_bazel_binary
480498

481499
- run: bazel test src/... --build_tag_filters=-e2e --test_tag_filters=-e2e --build_tests_only
500+
- *slack_notify_on_failure
482501

483502
# ----------------------------------------------------------------------------
484503
# Job that runs all Bazel tests against View Engine with the current Angular version
@@ -499,6 +518,7 @@ jobs:
499518

500519
# Run project tests with NGC and View Engine.
501520
- run: bazel test src/... --build_tag_filters=-docs-package,-e2e --test_tag_filters=-e2e --config=view-engine --build_tests_only
521+
- *slack_notify_on_failure
502522

503523
# ----------------------------------------------------------------------------
504524
# Job that runs all Bazel tests against View Engine from angular/angular#master.
@@ -519,6 +539,7 @@ jobs:
519539

520540
# Run project tests with NGC and View Engine.
521541
- run: bazel test src/... --build_tag_filters=-docs-package,-e2e --test_tag_filters=-e2e --config=view-engine --build_tests_only
542+
- *slack_notify_on_failure
522543

523544
# ----------------------------------------------------------------------------
524545
# Job that runs all Bazel integration tests.
@@ -537,6 +558,7 @@ jobs:
537558
- *setup_bazel_binary
538559
- run: yarn integration-tests
539560
- run: yarn integration-tests:view-engine
561+
- *slack_notify_on_failure
540562

541563
# ----------------------------------------------------------------------------
542564
# Job that runs all Bazel tests against material-components-web@canary
@@ -560,6 +582,7 @@ jobs:
560582
# Setup the components repository to use the MDC snapshot builds.
561583
# Run project tests with the MDC canary builds.
562584
- run: bazel test src/... --build_tag_filters=-docs-package,-e2e --test_tag_filters=-e2e --build_tests_only
585+
- *slack_notify_on_failure
563586

564587
# ----------------------------------------------------------------------------------------
565588
# Workflow definitions. A workflow usually groups multiple jobs together. This is useful if
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
# Script that notifies Slack about the currently failing job. This script
4+
# will be a noop when running for forked builds (i.e. PRs).
5+
6+
if [[ -z "${CIRCLE_PR_NUMBER}" ]]; then
7+
echo "Skipping notification for pull request."
8+
exit 0
9+
fi
10+
11+
message="\`${CIRCLE_JOB}\` failed in branch: ${CIRCLE_BRANCH}: ${CIRCLE_BUILD_URL}"
12+
data="{\"text\": \"${message}\"}"
13+
14+
curl --request POST --header "Content-Type: application/json" --data "${data}" \
15+
${SLACK_COMPONENTS_CI_FAILURES_WEBHOOK_URL}
16+
17+
echo "Notified Slack about job failure."

0 commit comments

Comments
 (0)