-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a script to compare simulation versions, see #358
- Loading branch information
Showing
1 changed file
with
88 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright 2021, University of Colorado Boulder | ||
/** | ||
* Compare the commits between two dependencies.json files, and print out the commits that are different. | ||
* | ||
* USAGE: | ||
* cd perennial | ||
* node js/scripts/compare-dependencies-2.js dependencies1.json dependencies2.json | ||
* | ||
* @author Sam Reid (PhET Interactive Simulations) | ||
*/ | ||
const fs = require( 'fs' ); | ||
|
||
// Parse the command line arguments | ||
const args = process.argv.slice( 2 ); | ||
|
||
// The first command line argument is the first project for comparison | ||
const project1 = args[ 0 ]; | ||
|
||
// The second command line argument is the second project for comparison | ||
const project2 = args[ 1 ]; | ||
|
||
const dependencies1 = JSON.parse( fs.readFileSync( project1 ) ); | ||
const dependencies2 = JSON.parse( fs.readFileSync( project2 ) ); | ||
|
||
const allKeys = [ ...Object.keys( dependencies1 ), ...Object.keys( dependencies2 ) ].filter( repo => repo !== 'comment' ); | ||
|
||
const issues = new Set(); | ||
let commitCount = 0; | ||
|
||
// Iterate over the keys they have in common | ||
allKeys.forEach( repo => { | ||
|
||
// If the key is in dependencies two | ||
if ( dependencies1[ repo ] && dependencies2[ repo ] ) { | ||
|
||
// Print the key and the version | ||
// console.log( `${repo} ${dependencies1[ repo ].sha} ${dependencies2[ repo ].sha}` ); | ||
|
||
// If the shas are the same, print a message to the console that the shas are the same | ||
if ( dependencies1[ repo ].sha === dependencies2[ repo ].sha ) { | ||
console.log( `# ${repo}` ); | ||
console.log( 'SHAs are the same' ); | ||
console.log(); | ||
} | ||
else { | ||
|
||
// We know the shas are different, and we want to compare them using `git log --oneline --ancestry-path` | ||
const command = `git -C ../${repo} log --oneline --ancestry-path ${dependencies1[ repo ].sha}..${dependencies2[ repo ].sha}`; | ||
|
||
// Run that command synchronously | ||
const buffer = require( 'child_process' ).execSync( command ); | ||
|
||
// Convert the buffer to a string and print it out | ||
console.log( `# ${repo}` ); | ||
const bufferString = buffer.toString(); | ||
console.log( bufferString ); | ||
|
||
// Split the buffer string into lines | ||
const lines = bufferString.split( '\n' ); | ||
// console.log( lines.length ); | ||
lines.forEach( line => { | ||
|
||
// If the line contains https://github.com/phetsims/ then add it to the set. | ||
if ( line.includes( 'https://github.com/phetsims/' ) && !line.includes( 'Merge branch \'main\'' ) ) { | ||
|
||
// Find the URL in line using a regular expression | ||
const url = line.substring( line.indexOf( 'https://github.com/phetsims/' ) ); | ||
|
||
issues.add( url ); | ||
} | ||
|
||
if ( line.trim().length > 0 ) { | ||
commitCount++; | ||
} | ||
} ); | ||
} | ||
} | ||
else { | ||
console.log( `# ${repo}` ); | ||
console.log( `Did not appear in both dependencies. project1=${dependencies1[ repo ]}, project2=${dependencies2[ repo ]}` ); | ||
console.log(); | ||
} | ||
} ); | ||
|
||
console.log( 'Discovered issues:' ); | ||
console.log( Array.from( issues ).sort().join( '\n' ) ); | ||
|
||
console.log( `${commitCount} commits referenced ${issues.size} separate issues` ); |