diff --git a/package.json b/package.json index 513747807709..d199b5f82222 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "@microsoft.azure/literate":"^1.0.21", "@microsoft.azure/async-io":"^1.0.21", "@microsoft.azure/polyfill":"^1.0.17", - "oad": "^0.1.6" + "oad": "^0.1.7" }, "homepage": "https://github.com/azure/azure-rest-api-specs", "repository": { diff --git a/scripts/breaking-change.js b/scripts/breaking-change.js index 649d5379a97b..d99eb98d6aaf 100644 --- a/scripts/breaking-change.js +++ b/scripts/breaking-change.js @@ -37,7 +37,16 @@ function runOad(oldSpec, newSpec) { console.log(`New Spec: "${newSpec}"`); console.log(`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`); - return Promise.resolve(oad.compare(oldSpec, newSpec, { consoleLogLevel: 'warn', json: true })); + return oad.compare(oldSpec, newSpec, { consoleLogLevel: 'warn', json: true }).then((result) => { + console.log(result); + if (result !== undefined && typeof result.valueOf() === 'string' && result.indexOf(`"type": "Error"`) > -1) { + console.log(`There are potential breaking changes in this PR. Please review before moving forward. Thanks!`); + process.exitCode = 1; + } + return Promise.resolve(); + }).catch(err => { + console.log(err); + }); } /** @@ -99,8 +108,13 @@ async function runScript() { console.dir(resolvedMapForNewSpecs); for (const swagger of swaggersToProcess) { - let outputFileNameWithExt = path.basename(swagger); + // If file does not exists in the previous commits then we ignore it as it's new file + if (!fs.existsSync(swagger)) { + console.log(`File: "${swagger}" looks to be newly added in this PR.`); + continue; + } + let outputFileNameWithExt = path.basename(swagger); console.log(outputFileNameWithExt); if (resolvedMapForNewSpecs[outputFileNameWithExt]) { await runOad(swagger, resolvedMapForNewSpecs[outputFileNameWithExt]); @@ -110,8 +124,9 @@ async function runScript() { // magic starts here runScript().then(success => { - process.exit(0); + console.log(`Thanks for using breaking change tool to review.`); + console.log(`If you encounter any issue(s), please open issue(s) at https://github.com/Azure/openapi-diff/issues .`); }).catch(err => { console.log(err); - process.exit(1); + process.exitCode = 1; }) diff --git a/scripts/momentOfTruth.js b/scripts/momentOfTruth.js index 70be13a000cf..580d86009f16 100644 --- a/scripts/momentOfTruth.js +++ b/scripts/momentOfTruth.js @@ -139,8 +139,9 @@ async function runScript() { for (const configFile of configsToProcess) { await runTools(configFile, 'after'); } - execSync(`${gitCheckoutCmd}`, { encoding: 'utf8' }); - execSync(`${gitLogCmd}`, { encoding: 'utf8' }); + + utils.checkoutTargetBranch(); + for (const configFile of configsToProcess) { await runTools(configFile, 'before'); } diff --git a/test/util/utils.js b/test/util/utils.js index f3891fc79b3e..9d19b1926676 100644 --- a/test/util/utils.js +++ b/test/util/utils.js @@ -83,6 +83,8 @@ exports.checkoutTargetBranch = function checkoutTargetBranch() { execSync(`git remote -vv`, { encoding: 'utf8' }); execSync(`git branch --all`, { encoding: 'utf8' }); execSync(`git fetch origin ${targetBranch}`, { encoding: 'utf8' }); + execSync(`git diff`, { encoding: 'utf8' }); + execSync(`git stash`, { encoding: 'utf8' }); execSync(`git checkout ${targetBranch}`, { encoding: 'utf8' }); execSync(`git log -3`, { encoding: 'utf8' }); }