Skip to content

Commit

Permalink
Breaking change build should fail if result contains error
Browse files Browse the repository at this point in the history
Skipping newly added files
Incorporating review feedback
  • Loading branch information
vishrutshah committed Aug 9, 2017
1 parent e9bc153 commit 4d283f0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "vishrutshah/openapi-diff#chain-result"
},
"homepage": "https://github.com/azure/azure-rest-api-specs",
"repository": {
Expand Down
22 changes: 18 additions & 4 deletions scripts/breaking-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,15 @@ 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) => {
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);
});
}

/**
Expand Down Expand Up @@ -99,8 +107,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]);
Expand All @@ -110,8 +123,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;
})
5 changes: 3 additions & 2 deletions scripts/momentOfTruth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
2 changes: 2 additions & 0 deletions test/util/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,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' });
}
Expand Down

0 comments on commit 4d283f0

Please sign in to comment.