-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d4ddef
commit 23426e9
Showing
6 changed files
with
504 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
// Copyright 2020, University of Colorado Boulder | ||
|
||
/** | ||
* Holds data related to a CT snapshot | ||
* | ||
* @author Jonathan Olson <[email protected]> | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const copyDirectory = require( '../../perennial/js/common/copyDirectory' ); | ||
const createDirectory = require( '../../perennial/js/common/createDirectory' ); | ||
const deleteDirectory = require( '../../perennial/js/common/deleteDirectory' ); | ||
const execute = require( '../../perennial/js/common/execute' ); | ||
const getRepoList = require( '../../perennial/js/common/getRepoList' ); | ||
const gitRevParse = require( '../../perennial/js/common/gitRevParse' ); | ||
const npmCommand = require( '../../perennial/js/common/npmCommand' ); | ||
const fs = require( 'fs' ); | ||
const _ = require( 'lodash' ); // eslint-disable-line | ||
|
||
// constants | ||
const copyOptions = { filter: path => path.indexOf( 'node_modules' ) < 0 }; | ||
|
||
class CTSnapshot { | ||
/** | ||
* Creates this snapshot. | ||
* @public | ||
* | ||
* @param {string} rootDir | ||
* @param {function({string})} setSnapshotStatus | ||
*/ | ||
async create( rootDir, setSnapshotStatus ) { | ||
|
||
// @private {string} | ||
this.rootDir = rootDir; | ||
|
||
// @private {function} | ||
this.setSnapshotStatus = setSnapshotStatus; | ||
|
||
const timestamp = Date.now(); | ||
const snapshotDir = `${rootDir}/ct-snapshots`; | ||
|
||
this.setSnapshotStatus( `Initializing new snapshot: ${timestamp}` ); | ||
|
||
// @public {number} | ||
this.timestamp = timestamp; | ||
|
||
// @public {string} | ||
this.name = `snapshot-${timestamp}`; | ||
|
||
// @public {boolean} | ||
this.exists = true; | ||
|
||
// @public {string} | ||
this.phetDir = `${snapshotDir}/${timestamp}-phet`; | ||
this.phetioDir = `${snapshotDir}/${timestamp}-phet-io`; | ||
|
||
if ( !fs.existsSync( snapshotDir ) ) { | ||
await createDirectory( snapshotDir ); | ||
} | ||
await createDirectory( this.phetDir ); | ||
await createDirectory( this.phetioDir ); | ||
|
||
this.setSnapshotStatus( 'Copying snapshot files' ); | ||
|
||
// @public {Array.<string>} | ||
this.repos = getRepoList( 'active-repos' ); | ||
|
||
// @public {Array.<string>} | ||
this.npmInstalledRepos = []; | ||
|
||
// @public {Object} - maps repo {string} => sha {string} | ||
this.shas = {}; | ||
for ( const repo of this.repos ) { | ||
this.shas[ repo ] = await gitRevParse( repo, 'master' ); | ||
} | ||
|
||
for ( const repo of this.repos ) { | ||
await copyDirectory( `${rootDir}/${repo}`, `${this.phetDir}/${repo}`, copyOptions ); | ||
await copyDirectory( `${rootDir}/${repo}`, `${this.phetioDir}/${repo}`, copyOptions ); | ||
} | ||
|
||
// @public {Array.<Object>} | ||
this.tests = JSON.parse( await execute( 'node', [ 'js/listContinuousTests.js' ], '../perennial' ) ).map( test => { | ||
test.snapshot = this; | ||
return test; | ||
} ); | ||
this.browserTests = this.tests.filter( test => [ 'sim-test', 'qunit-test', 'pageload-test' ].includes( test.type ) ).map( test => { | ||
test.count = 0; | ||
return test; | ||
} ); | ||
this.lintTests = this.tests.filter( test => test.type === 'lint' ).map( test => { | ||
test.complete = false; | ||
return test; | ||
} ); | ||
this.buildTests = this.tests.filter( test => test.type === 'build' ).map( test => { | ||
test.complete = false; | ||
test.success = false; | ||
return test; | ||
} ); | ||
} | ||
|
||
async npmInstall() { | ||
const npmRepos = this.repos.filter( repo => fs.existsSync( `../${repo}/package.json` ) ); | ||
for ( const repo of npmRepos ) { | ||
this.setSnapshotStatus( `Running npm update for ${repo}` ); | ||
|
||
await execute( npmCommand, [ 'update', `--cache=../npm-caches/${repo}`, '--tmp=../npm-tmp' ], `${this.phetDir}/${repo}` ); | ||
await execute( npmCommand, [ 'update', `--cache=../npm-caches/${repo}`, '--tmp=../npm-tmp' ], `${this.phetioDir}/${repo}` ); | ||
} | ||
} | ||
|
||
/** | ||
* Removes the snapshot's files. | ||
* @public | ||
*/ | ||
async remove() { | ||
await deleteDirectory( this.phetDir ); | ||
await deleteDirectory( this.phetioDir ); | ||
|
||
this.exists = false; | ||
} | ||
|
||
getAvailableBrowserTests( es5Only ) { | ||
return this.browserTests.filter( test => { | ||
if ( es5Only && !test.es5 ) { | ||
return false; | ||
} | ||
|
||
if ( test.buildDependencies ) { | ||
for ( const dependency of test.buildDependencies ) { | ||
if ( !_.some( this.buildTests, buildTest => buildTest.repo === dependency && buildTest.brand === test.brand && buildTest.success ) ) { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
} ); | ||
} | ||
} | ||
|
||
module.exports = CTSnapshot; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.