Skip to content

Commit

Permalink
non zero exit in case of fails or errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kanthesha committed Mar 29, 2024
1 parent 6d17d3f commit dd16021
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,18 @@ export async function main({
outputLogger,
});

await lintProjects({
const isAllPassed = await lintProjects({
projectReferences,
template,
workingDirectoryPath,
cachedRepositoriesDirectoryPath,
outputLogger,
});

if (!isAllPassed) {
// eslint-disable-next-line require-atomic-updates
process.exitCode = 1;
}
}

/**
Expand Down Expand Up @@ -226,18 +231,22 @@ async function lintProjects({
projectLintResultPromiseOutcomes.filter(isPromiseRejectedResult);

outputLogger.logToStdout('');
let isAllPassed = true;
fulfilledProjectLintResultPromiseOutcomes
.sort((a, b) => {
return a.value.projectName.localeCompare(b.value.projectName);
})
.forEach((fulfilledProjectLintResultPromiseOutcome, index) => {
reportProjectLintResult({
const { numberOfFailing } = reportProjectLintResult({
projectLintResult: fulfilledProjectLintResultPromiseOutcome.value,
outputLogger,
});
if (index < fulfilledProjectLintResultPromiseOutcomes.length - 1) {
outputLogger.logToStdout('\n');
}
if (numberOfFailing > 0) {
isAllPassed = false;
}
});
outputLogger.logToStdout('');

Expand All @@ -246,4 +255,6 @@ async function lintProjects({
outputLogger.logToStderr(rejectedProjectLintResultPromiseOutcome.reason);
},
);

return isAllPassed && rejectedProjectLintResultPromiseOutcomes.length === 0;
}
3 changes: 3 additions & 0 deletions src/report-project-lint-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const log = createModuleLogger(projectLogger, 'fetch-or-populate-file-cache');
* @param args - The arguments to this function.
* @param args.projectLintResult - The data collected from the lint execution.
* @param args.outputLogger - Writable streams for output messages.
* @returns Total number of passing and failing result.
*/
export function reportProjectLintResult({
projectLintResult,
Expand Down Expand Up @@ -62,6 +63,8 @@ export function reportProjectLintResult({
chalk.bold('Elapsed time:'),
projectLintResult.elapsedTimeIncludingLinting,
);

return { numberOfPassing, numberOfFailing };
}

/**
Expand Down

0 comments on commit dd16021

Please sign in to comment.