diff --git a/.circleci/config.yml b/.circleci/config.yml index 7623635a3f..d6f06581e3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -141,6 +141,11 @@ var_14: ¬ify_dev_infra_on_fail notificationJson="{\"text\":\":x: \`$CIRCLE_JOB\` job for $CIRCLE_BRANCH branch failed on build $CIRCLE_BUILD_NUM: $CIRCLE_BUILD_URL :scream:\"}" curl --request POST --header "Content-Type: application/json" --data "$notificationJson" $SLACK_DEV_INFRA_CI_FAILURES_WEBHOOK_URL +# Cache key for the Material unit tests job. **Note** when updating the SHA in the cache keys, +# also update the SHA for the "MATERIAL_REPO_COMMIT" environment variable. +var_15: &material_unit_tests_cache_key v4-angular-material-701302dc482d7e4b77990b24e3b5ab330bbf1aa5 +var_16: &material_unit_tests_cache_key_short v4-angular-material + version: 2 jobs: setup: @@ -621,27 +626,26 @@ jobs: # Although RBE is configured below for the Material repo, also setup RBE in the Angular repo # to provision Angular's GCP token into the environment variables. - *setup_bazel_remote_execution - - run: - name: "Cloning Material repository" - command: ./scripts/ci/clone_angular_material_repo.sh + # Restore the cache before cloning the repository because the clone script re-uses + # the restored repository if present. This reduces the amount of times the components + # repository needs to be cloned (this is slow and increases based on commits in the repo). - restore_cache: - # Material directory must be kept in sync with the `$MATERIAL_REPO_TMP_DIR` env variable. - # It needs to be hardcoded here, because env variables interpolation is not supported. keys: - - v2-angular-material-{{ checksum "/tmp/material2/yarn.lock" }} - - v2-angular-material- + - *material_unit_tests_cache_key + - *material_unit_tests_cache_key_short - run: + name: "Fetching Material repository" + command: ./scripts/ci/clone_angular_material_repo.sh + - run: + # Run yarn install to fetch the Bazel binaries as used in the Material repo. name: Installing Material dependencies. command: yarn --cwd ${MATERIAL_REPO_TMP_DIR} install --frozen-lockfile --non-interactive - # Save the cache before we run the Material unit tests script. This is necessary - # because we don't want to cache the node modules which have been modified to contain - # the attached Ivy package output. - save_cache: - # Material directory must be kept in sync with the `$MATERIAL_REPO_TMP_DIR` env variable. - # It needs to be hardcoded here, because env variables interpolation is not supported. - key: v2-angular-material-{{ checksum "/tmp/material2/yarn.lock" }} + key: *material_unit_tests_cache_key paths: - - "/tmp/material2/node_modules" + # Material directory must be kept in sync with the `$MATERIAL_REPO_TMP_DIR` env variable. + # It needs to be hardcoded here, because env variables interpolation is not supported. + - "/tmp/material2" - run: name: "Setup Bazel RBE remote execution in Material repo" command: | diff --git a/.circleci/env.sh b/.circleci/env.sh index 6b41bcd13f..aa2b1d1829 100755 --- a/.circleci/env.sh +++ b/.circleci/env.sh @@ -77,7 +77,9 @@ setPublicVar SAUCE_READY_FILE_TIMEOUT 120 # their separate build setups. setPublicVar MATERIAL_REPO_TMP_DIR "/tmp/material2" setPublicVar MATERIAL_REPO_URL "https://github.com/angular/material2.git" -setPublicVar MATERIAL_REPO_TAG "8.1.0" +setPublicVar MATERIAL_REPO_BRANCH "master" +# **NOTE**: When updating the commit SHA, also update the cache key in the CircleCI "config.yml". +setPublicVar MATERIAL_REPO_COMMIT "701302dc482d7e4b77990b24e3b5ab330bbf1aa5" # Source `$BASH_ENV` to make the variables available immediately. source $BASH_ENV; diff --git a/scripts/ci/clone_angular_material_repo.sh b/scripts/ci/clone_angular_material_repo.sh index 9eb9b0030b..56969cc2f2 100755 --- a/scripts/ci/clone_angular_material_repo.sh +++ b/scripts/ci/clone_angular_material_repo.sh @@ -2,9 +2,30 @@ set -u -e -o pipefail -# Ensure that the temporary directory does not exist. -rm -rf ${MATERIAL_REPO_TMP_DIR} +# Clones the Angular Material repository if the repository has not been cloned before. If +# the repository is already cloned, the script refreshes the repository by syncing with +# upstream and resetting to the desired Material commit (see "MATERIAL_REPO_COMMIT" variable). -# Clone the Material repository into the given temporary directory. -git clone --depth 1 --branch ${MATERIAL_REPO_TAG} ${MATERIAL_REPO_URL} \ - ${MATERIAL_REPO_TMP_DIR} +if [[ ! -d "${MATERIAL_REPO_TMP_DIR}" ]]; then + # Clone the Material repository if not present through restored cache. + git clone --branch ${MATERIAL_REPO_BRANCH} ${MATERIAL_REPO_URL} ${MATERIAL_REPO_TMP_DIR} + + # Switch into the cloned repository. + cd ${MATERIAL_REPO_TMP_DIR} + + # Reset branch to the desired commit. + git reset --hard ${MATERIAL_REPO_COMMIT} +else + # Switch into the cached repository. + cd ${MATERIAL_REPO_TMP_DIR} + + # Only refresh the repository if the current branch HEAD is not + # matching the desired commit. + if [[ "$(git rev-parse HEAD)" != "${MATERIAL_REPO_COMMIT}" ]]; then + # Pull the latest changes of the specified branch. + git fetch origin ${MATERIAL_REPO_BRANCH} + + # Reset the current branch to the desired commit. + git reset --hard ${MATERIAL_REPO_COMMIT} + fi +fi