Skip to content

Commit

Permalink
🏗 Add fail-fast behavior to CircleCI builds (#32575)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsimha committed Feb 10, 2021
1 parent 2b3c30f commit 36d86e2
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 11 deletions.
5 changes: 2 additions & 3 deletions .circleci/check_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the license.
#

# This script checks if a PR branch is using the most recent CircleCI config.
#
# Reference: https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables.
# Reference: https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables

set -e
err=0
Expand Down
22 changes: 22 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ commands:
steps:
- browser-tools/install-chrome:
replace-existing: true
fail_fast:
steps:
- run:
name: 'Fail Fast'
when: on_fail
command: ./.circleci/fail_fast.sh

jobs:
'Checks':
Expand All @@ -84,6 +90,7 @@ jobs:
- run:
name: 'Checks'
command: node build-system/pr-check/checks.js
- fail_fast
'Unminified Build':
executor:
name: amphtml-xlarge-executor
Expand All @@ -92,6 +99,7 @@ jobs:
- run:
name: 'Unminified Build'
command: node build-system/pr-check/unminified-build.js
- fail_fast
'Nomodule Build':
executor:
name: amphtml-xlarge-executor
Expand All @@ -100,6 +108,7 @@ jobs:
- run:
name: 'Nomodule Build'
command: node build-system/pr-check/nomodule-build.js
- fail_fast
'Module Build':
executor:
name: amphtml-xlarge-executor
Expand All @@ -108,6 +117,7 @@ jobs:
- run:
name: 'Module Build'
command: node build-system/pr-check/module-build.js
- fail_fast
'Bundle Size':
executor:
name: amphtml-medium-executor
Expand All @@ -116,6 +126,7 @@ jobs:
- run:
name: 'Bundle Size'
command: node build-system/pr-check/bundle-size.js
- fail_fast
'Validator Tests':
executor:
name: amphtml-medium-executor
Expand All @@ -127,6 +138,7 @@ jobs:
- run:
name: 'Validator Tests'
command: node build-system/pr-check/validator-tests.js
- fail_fast
'Visual Diff Tests':
executor:
name: amphtml-large-executor
Expand All @@ -136,6 +148,7 @@ jobs:
- run:
name: 'Visual Diff Tests'
command: node build-system/pr-check/visual-diff-tests.js
- fail_fast
'Unit Tests':
executor:
name: amphtml-large-executor
Expand All @@ -149,6 +162,7 @@ jobs:
command: node build-system/pr-check/unit-tests.js
- save_karma_cache:
cache_name: unit
- fail_fast
'Unminified Tests':
executor:
name: amphtml-large-executor
Expand All @@ -162,6 +176,7 @@ jobs:
command: node build-system/pr-check/unminified-tests.js
- save_karma_cache:
cache_name: unminified
- fail_fast
'Nomodule Tests':
executor:
name: amphtml-large-executor
Expand All @@ -175,6 +190,7 @@ jobs:
command: node build-system/pr-check/nomodule-tests.js
- save_karma_cache:
cache_name: nomodule
- fail_fast
'Module Tests':
executor:
name: amphtml-large-executor
Expand All @@ -188,6 +204,7 @@ jobs:
command: node build-system/pr-check/module-tests.js
- save_karma_cache:
cache_name: module
- fail_fast
'End-to-End Tests':
executor:
name: amphtml-large-executor
Expand All @@ -197,6 +214,7 @@ jobs:
- run:
name: 'End-to-End Tests'
command: node build-system/pr-check/e2e-tests.js
- fail_fast
'Performance Tests':
executor:
name: amphtml-xlarge-executor
Expand All @@ -206,6 +224,7 @@ jobs:
- run:
name: 'Performance Tests'
command: node build-system/pr-check/performance-tests.js
- fail_fast
'Experiment A Tests':
executor:
name: amphtml-xlarge-executor
Expand All @@ -215,6 +234,7 @@ jobs:
- run:
name: 'Experiment A Tests'
command: node build-system/pr-check/experiment-tests.js --experiment=experimentA
- fail_fast
'Experiment B Tests':
executor:
name: amphtml-xlarge-executor
Expand All @@ -224,6 +244,7 @@ jobs:
- run:
name: 'Experiment B Tests'
command: node build-system/pr-check/experiment-tests.js --experiment=experimentB
- fail_fast
'Experiment C Tests':
executor:
name: amphtml-xlarge-executor
Expand All @@ -233,6 +254,7 @@ jobs:
- run:
name: 'Experiment C Tests'
command: node build-system/pr-check/experiment-tests.js --experiment=experimentC
- fail_fast

workflows:
'CircleCI':
Expand Down
27 changes: 27 additions & 0 deletions .circleci/fail_fast.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
#
# Copyright 2021 The AMP HTML Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the license.

# This script early-exits the CircleCI workflow when a single job fails.
# Reference: https://support.circleci.com/hc/en-us/articles/360052058811-Exit-build-early-if-any-test-fails

set -e

RED() { echo -e "\n\033[0;31m$1\033[0m"; }

echo $(RED "Exiting workflow because a job failed.")
curl -X POST \
--header "Content-Type: application/json" \
"https://circleci.com/api/v2/workflow/${CIRCLE_WORKFLOW_ID}/cancel?circle-token=${CIRCLE_TOKEN}"
5 changes: 2 additions & 3 deletions .circleci/fetch_merge_commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the license.
#

# This script fetches the merge commit of a PR branch with master to make sure
# PRs are tested against all the latest changes on CircleCI.
#
# Reference: https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables.
# Reference: https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables

set -e
err=0
Expand Down
2 changes: 1 addition & 1 deletion .circleci/install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the license.
#

# Script used by AMP's CI builds to install project dependencies on CircleCI.

set -e
Expand Down
2 changes: 1 addition & 1 deletion .circleci/setup_storage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the license.
#

# Script used by AMP's CI builds to authenticate with GCP storage on CircleCI.
# TODO(rsimha, ampproject/amp-github-apps#1110): Update storage details.

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the license.
#

# Script used by AMP's CI builds to install project dependencies on GH Actions.

set -e
Expand Down
3 changes: 1 addition & 2 deletions build-system/common/enable-git-pre-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the license.
#

# This script adds a pre-push hook to .git/hooks/, which runs some basic tests
# before running "git push".
#
# To enable it, run this script: "./build-system/common/enable-git-pre-push.sh"


Expand Down

0 comments on commit 36d86e2

Please sign in to comment.