Skip to content

Commit 0ad0051

Browse files
devversionandrewseguin
authored andcommitted
build: cronjob to run tests against mdc snapshot builds (#16668)
Sets up a new cronjob that runs tests against the `material-components-web` repository HEAD. This allows us to validate that our MDC components work properly with upcoming MDC releases. (cherry picked from commit 258ca59)
1 parent 900732f commit 0ad0051

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed

.circleci/config.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ var_17: &setup_bazel_binary
123123
name: "Setting up global Bazel binary"
124124
command: ./scripts/circleci/setup_bazel_binary.sh
125125

126+
# **Note**: When updating the beginning of the cache key, also update the fallback cache
127+
# key to match the new cache key prefix. This allows us to take advantage of CircleCI's
128+
# fallback caching. Read more here: https://circleci.com/docs/2.0/caching/#restoring-cache.
129+
var_18: &mdc_deps_cache_key v1-mdc-deps-{{ checksum "/tmp/material-components-web/package-lock.json" }}
130+
var_19: &mdc_deps_fallback_cache_key v1-mdc-deps-
131+
126132
# -----------------------------
127133
# Container version of CircleCI
128134
# -----------------------------
@@ -456,6 +462,53 @@ jobs:
456462
- run: bazel build src/... --build_tag_filters=-docs-package,-e2e --define=compile=aot
457463
- run: bazel test src/... --build_tag_filters=-docs-package,-e2e --test_tag_filters=-e2e --define=compile=aot
458464

465+
# ----------------------------------------------------------------------------
466+
# Job that runs all Bazel tests against material-components-web#master.
467+
# ----------------------------------------------------------------------------
468+
mdc_snapshot_test_cronjob:
469+
<<: *job_defaults
470+
resource_class: xlarge
471+
environment:
472+
GCP_DECRYPT_TOKEN: *gcp_decrypt_token
473+
MDC_REPO_URL: "https://github.com/material-components/material-components-web.git"
474+
MDC_REPO_BRANCH: "master"
475+
MDC_REPO_TMP_DIR: "/tmp/material-components-web"
476+
steps:
477+
- *checkout_code
478+
- *restore_cache
479+
- *setup_bazel_binary
480+
- *setup_bazel_ci_config
481+
- *setup_bazel_remote_execution
482+
- *yarn_download
483+
- *yarn_install
484+
485+
- run: git clone ${MDC_REPO_URL} --branch ${MDC_REPO_BRANCH} --depth 1 ${MDC_REPO_TMP_DIR}
486+
- restore_cache:
487+
keys:
488+
- *mdc_deps_cache_key
489+
- *mdc_deps_fallback_cache_key
490+
- run:
491+
name: "Installing dependencies for MDC repository"
492+
# MDC repository does not use Yarn for node dependencies, so in order to respect the
493+
# lock-file we need to use "npm" when installing dependencies.
494+
command: cd ${MDC_REPO_TMP_DIR} && npm install
495+
- save_cache:
496+
key: *mdc_deps_cache_key
497+
paths:
498+
# Repository path must be kept in sync with the `$MDC_REPO_TMP_DIR` env variable.
499+
# It needs to be hardcoded here, because env variables interpolation is not supported.
500+
- "/tmp/material-components-web/node_modules"
501+
- run:
502+
name: "Building MDC snapshot builds"
503+
command: |
504+
cd ${MDC_REPO_TMP_DIR}
505+
yarn dist && node scripts/cp-pkgs.js
506+
# Setup the components repository to use the MDC snapshot builds.
507+
- run: node ./scripts/circleci/setup-mdc-snapshots.js ${MDC_REPO_TMP_DIR}/packages/ $(git -C ${MDC_REPO_TMP_DIR} rev-parse HEAD)
508+
# Run project tests with the MDC snapshot builds.
509+
- run: bazel build src/... --build_tag_filters=-docs-package,-e2e
510+
- run: bazel test src/... --build_tag_filters=-docs-package,-e2e --test_tag_filters=-e2e
511+
459512
# ----------------------------------------------------------------------------------------
460513
# Workflow definitions. A workflow usually groups multiple jobs together. This is useful if
461514
# one job depends on another.
@@ -519,6 +572,7 @@ workflows:
519572
# workflow. See: https://circleci.com/ideas/?idea=CCI-I-295
520573
- snapshot_tests_local_browsers
521574
- ivy_snapshot_test_cronjob
575+
- mdc_snapshot_test_cronjob
522576
triggers:
523577
- schedule:
524578
cron: "0 * * * *"
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Script that sets up the MDC snapshot github builds. We set up the snapshot builds by
3+
* overwriting the versions in the "package.json" and taking advantage of Yarn's resolutions
4+
* feature. Yarn resolutions will be used to overwrite nested MDC package versions.
5+
*
6+
* node_modules/@material/toolbar@snapshot
7+
* node_modules/material-components-web@latest
8+
* node_modules/@material/toolbar@snapshot
9+
*/
10+
11+
const {yellow, green} = require('chalk');
12+
const {writeFileSync, existsSync} = require('fs');
13+
const {join} = require('path');
14+
const globSync = require('glob').sync;
15+
16+
const args = process.argv.slice(2);
17+
const [mdcPackagesPath, uniqueId] = args;
18+
const projectDir = join(__dirname, '../../');
19+
const packageJsonPath = join(projectDir, 'package.json');
20+
const packageJson = require(packageJsonPath);
21+
22+
if (!mdcPackagesPath || !uniqueId) {
23+
throw Error('Usage: node ./scripts/setup-mdc-snapshots.js <mdcPackagesPath> <uniqueId>');
24+
}
25+
26+
// Initialize the "resolutions" property in case it is not present in the "package.json" yet.
27+
// See: https://yarnpkg.com/lang/en/docs/package-json/#toc-resolutions for the API.
28+
packageJson['resolutions'] = packageJson['resolutions'] || {};
29+
30+
const mdcPackages = globSync('./*/', {cwd: mdcPackagesPath, absolute: true});
31+
32+
for (let packagePath of mdcPackages) {
33+
const pkgJsonPath = join(packagePath, 'package.json');
34+
35+
if (!existsSync(pkgJsonPath)) {
36+
continue;
37+
}
38+
39+
const packageName = require(pkgJsonPath).name;
40+
const newPackageVersion = `file:${packagePath}`;
41+
42+
// Add resolutions for each package in the format "**/{PACKAGE}" so that all
43+
// nested versions of that specific MDC package will have the same version.
44+
packageJson.resolutions[`**/${packageName}`] = newPackageVersion;
45+
46+
// Since the resolutions only cover the version of all nested installs, we also need
47+
// to explicitly set the version for the package listed in the project "package.json".
48+
packageJson.dependencies[packageName] = newPackageVersion;
49+
50+
// In case this dependency was previously a dev dependency, just remove it because we
51+
// re-added it as a normal dependency for simplicity.
52+
delete packageJson.devDependencies[packageName];
53+
}
54+
55+
// Update the version field in the "package.json" to a new version that contains
56+
// the specified unique id. We need to ensure that the "package.json" is different
57+
// if something changes upstream in the MDC repository as Bazel otherwise incorrectly
58+
// re-uses results from previous builds.
59+
packageJson.version = `${packageJson.version}-${uniqueId}`;
60+
61+
// Write changes to the "packageJson", so that we can install the new versions afterwards.
62+
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
63+
64+
console.log(green('Successfully added the "resolutions" to the "package.json".'));

0 commit comments

Comments
 (0)