Skip to content

Commit 7e46a6d

Browse files
JoostKmhevery
authored andcommitted
test(ivy): update Material to recent commit from master branch (angular#31569)
Previously, the ivy-2019 branch of the Material (aka components) repo was used, which contains some changes that were necessary to work with Ivy. These changes are not longer necessary, as Material's master branch is fully working with Ivy today. To be up-to-date with recent Material development and its support for more recent dependencies, e.g. TypeScript, it is desirable for us to be on a newer version of Material. This commit moves the Material tests away from the ivy-2019 branch, to a recent commit on master. We are not targeting the master branch itself, as that would introduce a moving target into Angular's CI checks, which is undesirable. Lastly, the usage of gulp to run Material's tests is changed into using Bazel, as Material itself is now also built with Bazel. PR Close angular#31569
1 parent 85d051f commit 7e46a6d

6 files changed

+110
-32
lines changed

.circleci/config.yml

+8-21
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,7 @@ var_5: &setup_bazel_remote_execution
5858
# cause decryption failures based on the openssl version. https://stackoverflow.com/a/39641378/4317734
5959
openssl aes-256-cbc -d -in .circleci/gcp_token -md md5 -k "$CI_REPO_NAME" -out /home/circleci/.gcp_credentials
6060
echo "export GOOGLE_APPLICATION_CREDENTIALS=/home/circleci/.gcp_credentials" >> $BASH_ENV
61-
touch .bazelrc.user
62-
sudo bash -c "echo -e 'build --config=remote\n' >> .bazelrc.user"
63-
sudo bash -c "echo -e 'build:remote --remote_accept_cached=true\n' >> .bazelrc.user"
64-
echo "Reading from remote cache for bazel remote jobs."
65-
if [[ "$CI_PULL_REQUEST" == "false" ]]; then
66-
sudo bash -c "echo -e 'build:remote --remote_upload_local_results=true\n' >> .bazelrc.user"
67-
echo "Uploading local build results to remote cache."
68-
else
69-
sudo bash -c "echo -e 'build:remote --remote_upload_local_results=false\n' >> .bazelrc.user"
70-
echo "Not uploading local build results to remote cache."
71-
fi
61+
./.circleci/setup-rbe.sh .bazelrc.user
7262
7363
# Settings common to each job
7464
var_6: &job_defaults
@@ -625,19 +615,12 @@ jobs:
625615
resource_class: xlarge
626616
docker:
627617
- image: *browsers_docker_image
628-
# The Material unit tests support splitting the browsers across multiple CircleCI
629-
# instances. Since by default this job launches two browsers, we run each browser
630-
# in its own container instance.
631-
# https://github.com/angular/material2/blob/7baeaa797b19da2d2998f0d26f6fede3c8a13714/test/karma.conf.js#L107-L110
632-
parallelism: 2
633-
environment:
634-
# The Material unit tests also support launching the same browser multiple times by
635-
# sharding individual specs across the defined multiple instances.
636-
# See: https://github.com/angular/material2/blob/7baeaa797b19da2d2998f0d26f6fede3c8a13714/test/karma.conf.js#L113-L116
637-
KARMA_PARALLEL_BROWSERS: 3
638618
steps:
639619
- *attach_workspace
640620
- *init_environment
621+
# Although RBE is configured below for the Material repo, also setup RBE in the Angular repo
622+
# to provision Angular's GCP token into the environment variables.
623+
- *setup_bazel_remote_execution
641624
- run:
642625
name: "Cloning Material repository"
643626
command: ./scripts/ci/clone_angular_material_repo.sh
@@ -659,6 +642,10 @@ jobs:
659642
key: v2-angular-material-{{ checksum "/tmp/material2/yarn.lock" }}
660643
paths:
661644
- "/tmp/material2/node_modules"
645+
- run:
646+
name: "Setup Bazel RBE remote execution in Material repo"
647+
command: |
648+
./.circleci/setup-rbe.sh "${MATERIAL_REPO_TMP_DIR}/.bazelrc.user"
662649
- run:
663650
name: "Running Material unit tests"
664651
command: ./scripts/ci/run_angular_material_unit_tests.sh

.circleci/env.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ setPublicVar SAUCE_READY_FILE_TIMEOUT 120
7777
# their separate build setups.
7878
setPublicVar MATERIAL_REPO_TMP_DIR "/tmp/material2"
7979
setPublicVar MATERIAL_REPO_URL "https://github.com/angular/material2.git"
80-
setPublicVar MATERIAL_REPO_BRANCH "ivy-2019"
80+
setPublicVar MATERIAL_REPO_TAG "8.1.0"
8181

8282
# Source `$BASH_ENV` to make the variables available immediately.
8383
source $BASH_ENV;

.circleci/setup-rbe.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
set -u -e -o pipefail
3+
4+
# The path of the .bazelrc.user file to update should be passed as first parameter to this script.
5+
# This allows to setup RBE for both the Angular repo and the Material repo.
6+
bazelrc_user="$1"
7+
8+
echo "Writing RBE configuration to ${bazelrc_user}"
9+
10+
touch ${bazelrc_user}
11+
echo -e 'build --config=remote\n' >> ${bazelrc_user}
12+
echo -e 'build:remote --remote_accept_cached=true\n' >> ${bazelrc_user}
13+
echo "Reading from remote cache for bazel remote jobs."
14+
if [[ "$CI_PULL_REQUEST" == "false" ]]; then
15+
echo -e 'build:remote --remote_upload_local_results=true\n' >> ${bazelrc_user}
16+
echo "Uploading local build results to remote cache."
17+
else
18+
echo -e 'build:remote --remote_upload_local_results=false\n' >> ${bazelrc_user}
19+
echo "Not uploading local build results to remote cache."
20+
fi

scripts/ci/clone_angular_material_repo.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ set -u -e -o pipefail
66
rm -rf ${MATERIAL_REPO_TMP_DIR}
77

88
# Clone the Material repository into the given temporary directory.
9-
git clone --depth 1 --branch ${MATERIAL_REPO_BRANCH} ${MATERIAL_REPO_URL} \
9+
git clone --depth 1 --branch ${MATERIAL_REPO_TAG} ${MATERIAL_REPO_URL} \
1010
${MATERIAL_REPO_TMP_DIR}

scripts/ci/run_angular_material_unit_tests.sh

+17-9
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,28 @@ set -u -e -o pipefail
66
# Save the dir for the root of the Angular repo.
77
angular_dir=$(pwd)
88

9+
# Disable full template type check, as Material doesn't build cleanly with it enabled.
10+
# See https://github.com/angular/components/pull/16373 for details.
11+
# The "ivyTemplateTypeCheck" flag is set to True so that a minimum amount of type checking still
12+
# occurs, at a level compatible with that of VE's type checking. This ensures Ivy's type checker
13+
# is still tested against the Material repo, albeit in its non-strict mode.
14+
sed -i'.bak' "s/\(_ENABLE_NG_TYPE_CHECKING = \)True/\1False/g" ${MATERIAL_REPO_TMP_DIR}/tools/defaults.bzl
15+
sed -i'.bak' "s/\(\"ivyTemplateTypeCheck\": \)False/\1True/g" dist/packages-dist-ivy-aot/bazel/src/ng_module.bzl
16+
917
# Switch into Material directory.
1018
cd ${MATERIAL_REPO_TMP_DIR}
1119

12-
# Install this version of Angular into the freshly cloned repo.
13-
rm -rf ./node_modules/@angular/*
14-
cp -r ${angular_dir}/dist/packages-dist-ivy-aot/* ./node_modules/@angular/
15-
16-
# The angular/material2 CI sets TEST_PLATFORM to either "local", "saucelabs", or "browserstack".
17-
# For angular/angular, we only want to run the "local" tests.
18-
export TEST_PLATFORM=local
20+
# Updates Material's package.json to refer to the packages-dist-ivy-aot directory.
21+
# Note that it's not necessary to perform a yarn install, as Bazel performs its own yarn install.
22+
node ${angular_dir}/scripts/ci/update-deps-to-dist-packages.js ${MATERIAL_REPO_TMP_DIR}/package.json ${angular_dir}/dist/packages-dist-ivy-aot/
1923

2024
# Append the test blocklist into angular/material2's karma-test-shim.js.
2125
# This filters out known-failing tests because the goal is to prevent regressions.
2226
cat ${angular_dir}/tools/material-ci/angular_material_test_blocklist.js >> ./test/karma-test-shim.js
2327

24-
# Now actually run the tests.
25-
yarn gulp test:single-run
28+
# Create a symlink for the Bazel binary installed through NPM, as running through Yarn introduces OOM errors.
29+
./scripts/circleci/setup_bazel_binary.sh
30+
31+
# Now actually run the tests. The dev-app target is excluded as it fails to compile due to
32+
# limitations in Ivy's type checker (see FW-1352 and FW-1433)
33+
bazel test src/... --deleted_packages=//src/dev-app --build_tag_filters=-docs-package,-e2e,-browser:firefox-local --test_tag_filters=-e2e,-browser:firefox-local --define=compile=aot
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* This script updates a package.json file by replacing all dependencies and devDependencies
3+
* such that all packages from the @angular scope point to the packages-dist directory.
4+
*
5+
* Please be aware that updating of versions might introduce compatibility issues. For instance,
6+
* if a peer dependency of Angular, e.g. "typescript" changes, the package.json that is updated
7+
* by this script will not have updated the "typescript" dependency to satisfy the peer dependency
8+
* requirement. As a result, incompatibility errors might occur.
9+
*/
10+
'use strict';
11+
12+
const {yellow, green} = require('chalk');
13+
const {existsSync, writeFileSync} = require('fs');
14+
const {resolve} = require('path');
15+
16+
const [, , packageJsonPath, packagesDistRoot] = process.argv;
17+
18+
const packageJson = require(packageJsonPath);
19+
20+
const updated = [];
21+
const skipped = [];
22+
function updateDeps(dependencies) {
23+
for (const packageName of Object.keys(dependencies)) {
24+
// We're only interested to update packages in the @angular scope
25+
if (!packageName.startsWith('@angular/')) {
26+
continue;
27+
}
28+
29+
// Within the packages-dist directory there's no scope name
30+
const packageNameWithoutScope = packageName.replace('@angular/', '');
31+
const packagePath = resolve(packagesDistRoot, packageNameWithoutScope);
32+
33+
// Check whether the package exists in packages-dist. Not all packages
34+
// in the @angular scope are published from the main Angular repo.
35+
if (existsSync(packagePath)) {
36+
// Update the dependency to point to the packages-dist location.
37+
dependencies[packageName] = `file:${packagePath}`;
38+
updated.push(packageName);
39+
} else {
40+
skipped.push(packageName);
41+
}
42+
}
43+
}
44+
45+
46+
// Update dependencies from @angular scope to those in the packages-dist folder
47+
updateDeps(packageJson.dependencies);
48+
updateDeps(packageJson.devDependencies);
49+
50+
// Write the updated package.json contents
51+
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
52+
53+
// Log all packages that were updated
54+
if (updated.length > 0) {
55+
console.log(green(`Updated ${packageJsonPath} to packages in ${packagesDistRoot}:`));
56+
console.log(` ${updated.join('\n ')}\n`);
57+
}
58+
59+
// Log the packages that were skipped, as they were not present in the packages-dist directory
60+
if (skipped.length > 0) {
61+
console.log(yellow(`Did not update packages that were not present in ${packagesDistRoot}:`));
62+
console.log(` ${skipped.join('\n ')}\n`);
63+
}

0 commit comments

Comments
 (0)