Skip to content

Commit

Permalink
[test] Run tests periodically with react@next (#18008)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon authored Oct 24, 2019
1 parent 7f2eca2 commit 7f870e6
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
34 changes: 33 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
version: 2.1

defaults: &defaults
parameters:
react-dist-tag:
description: The dist-tag of react to be used
type: string
default: stable
environment:
# expose it globally otherwise we have to thread it from each job to the install command
REACT_DIST_TAG: << parameters.react-dist-tag >>
working_directory: /tmp/material-ui
docker:
- image: circleci/node:8.15
Expand All @@ -16,6 +24,12 @@ defaults: &defaults
commands:
install_js:
steps:
- run:
name: Resolve react version
command: |
node scripts/use-react-dist-tag
# log a patch for maintainers who want to check out this change
git diff HEAD
- restore_cache:
keys:
- v2-yarn-sha-{{ checksum "yarn.lock" }}
Expand Down Expand Up @@ -157,7 +171,7 @@ workflows:
- checkout:
filters:
branches:
ignore:
ignore:
- l10n
- /dependabot\//
- test_unit:
Expand All @@ -178,3 +192,21 @@ workflows:
- test_static
- test_types
- test_browser
react-next:
triggers:
- schedule:
cron: '0 0 * * *'
filters:
branches:
only:
- master
jobs:
- test_unit:
react-dist-tag: next
- test_browser:
react-dist-tag: next
- test_regressions:
requires:
- test_unit
- test_browser
react-dist-tag: next
55 changes: 55 additions & 0 deletions scripts/use-react-dist-tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* eslint-disable no-console */
/**
* Given an environment variable called `REACT_DIST_TAG` fetch the corresponding
* version and make sure this version is used throughout the repository.
*
* If you work on this file:
* WARNING: This script can only use built-in modules since it has to run before
* `yarn install`
*/
const childProcess = require('child_process');
const fs = require('fs');
const os = require('os');
const path = require('path');
const { promisify } = require('util');

const exec = promisify(childProcess.exec);

// packages published from the react monorepo using the same version
const reactPackageNames = ['react', 'react-dom', 'react-is', 'react-test-renderer', 'scheduler'];

async function main(distTag) {
if (typeof distTag !== 'string') {
throw new TypeError(`expected distTag: string but got '${distTag}'`);
}

if (distTag === 'stable') {
console.log('nothing to do with stable');
return;
}

const { stdout: versions } = await exec(`npm dist-tag ls react ${distTag}`);
const tagMapping = versions.split('\n').find(mapping => {
return mapping.startsWith(`${distTag}: `);
});
if (tagMapping === undefined) {
throw new Error(`Could not find '${distTag}' in "${versions}"`);
}

const version = tagMapping.replace(`${distTag}: `, '');

const packageJsonPath = path.resolve(__dirname, '../package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, { encoding: 'utf8' }));

reactPackageNames.forEach(reactPackageName => {
packageJson.resolutions[reactPackageName] = version;
});

// CircleCI seemingly times out if it has a newline diff at the end
fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}${os.EOL}`);
}

main(process.env.REACT_DIST_TAG).catch(error => {
console.error(error);
process.exit(1);
});

0 comments on commit 7f870e6

Please sign in to comment.