Skip to content

Commit

Permalink
Revert "Revert "Revert "Only run precommit hooks when master branch i…
Browse files Browse the repository at this point in the history
…s checked out, see phetsims/perennial#276"""

This reverts commit 94338c7.
  • Loading branch information
jessegreenberg committed Mar 2, 2023
1 parent 738e748 commit 43316d5
Showing 1 changed file with 43 additions and 50 deletions.
93 changes: 43 additions & 50 deletions js/scripts/hook-pre-commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,64 +29,57 @@ const phetTimingLog = require( '../../../perennial-alias/js/common/phetTimingLog

// Identify the current repo
const repo = process.cwd().split( path.sep ).pop();
const branch = ( await execute( 'git', [ 'branch', '--show-current' ], `../${repo}` ) ).trim();

if ( branch === 'master' ) {
const precommitSuccess = await phetTimingLog.startAsync( `hook-pre-commit repo="${repo}"`, async () => {

const precommitSuccess = await phetTimingLog.startAsync( `hook-pre-commit repo="${repo}"`, async () => {
// Console logging via --console
const commandLineArguments = process.argv.slice( 2 );
const outputToConsole = commandLineArguments.includes( '--console' );

// Console logging via --console
const commandLineArguments = process.argv.slice( 2 );
const outputToConsole = commandLineArguments.includes( '--console' );

const promises = [ 'lint', 'report-media', 'tsc', 'qunit', 'phet-io-api-compare' ].map( task => {
return phetTimingLog.startAsync( task, async () => {
const results = await execute( 'node', [
'../chipper/js/scripts/hook-pre-commit-task.js',
`--command=${task}`,
`--repo=${repo}`,
outputToConsole ? '--console' : '' ], '../chipper', {
errors: 'resolve'
} );
results.stdout && results.stdout.trim().length > 0 && console.log( results.stdout );
results.stderr && results.stderr.trim().length > 0 && console.log( results.stderr );
const promises = [ 'lint', 'report-media', 'tsc', 'qunit', 'phet-io-api-compare' ].map( task => {
return phetTimingLog.startAsync( task, async () => {
const results = await execute( 'node', [
'../chipper/js/scripts/hook-pre-commit-task.js',
`--command=${task}`,
`--repo=${repo}`,
outputToConsole ? '--console' : '' ], '../chipper', {
errors: 'resolve'
} );
results.stdout && results.stdout.trim().length > 0 && console.log( results.stdout );
results.stderr && results.stderr.trim().length > 0 && console.log( results.stderr );

if ( results.code === 0 ) {
return 0;
if ( results.code === 0 ) {
return 0;
}
else {
let message = 'Task failed: ' + task;
if ( results.stdout && results.stdout.trim().length > 0 ) {
message = message + ', ' + results.stdout;
}
else {
let message = 'Task failed: ' + task;
if ( results.stdout && results.stdout.trim().length > 0 ) {
message = message + ', ' + results.stdout;
}
if ( results.stderr && results.stderr.trim().length > 0 ) {
message = message + ', ' + results.stderr;
}
throw new Error( message );
if ( results.stderr && results.stderr.trim().length > 0 ) {
message = message + ', ' + results.stderr;
}
}, {
depth: 1
} );
throw new Error( message );
}
}, {
depth: 1
} );
} );

try {
await Promise.all( promises );
console.log( 'All tasks succeeded' );
return true;
}
catch( e ) {
try {
await Promise.all( promises );
console.log( 'All tasks succeeded' );
return true;
}
catch( e ) {

// Exit as soon as any one promise fails
// Each task is responsible for outputting its error to the console, so the console should already
// be showing the error by now
return false;
}
} );
// Exit as soon as any one promise fails
// Each task is responsible for outputting its error to the console, so the console should already
// be showing the error by now
return false;
}
} );

// generatePhetioMacroAPI is preventing exit for unknown reasons, so manually exit here
phetTimingLog.close( () => process.exit( precommitSuccess ? 0 : 1 ) );
}
else {
console.log( 'Skipping pre-commit hook because not on master branch. Detected branch: ' + ( branch.length === 0 ? '(none)' : branch ) );
}
// generatePhetioMacroAPI is preventing exit for unknown reasons, so manually exit here
phetTimingLog.close( () => process.exit( precommitSuccess ? 0 : 1 ) );
} )();

0 comments on commit 43316d5

Please sign in to comment.