Skip to content

Commit

Permalink
[Travis-ci] Oad in ci status (#1520)
Browse files Browse the repository at this point in the history
* Breaking change build should fail if result contains error
Skipping newly added files
Incorporating review feedback

* testing

* log the result as oad.compare returns promise for caller

* Use published oad

* Revert "testing"

This reverts commit a9be94d.
  • Loading branch information
vishrutshah authored Aug 11, 2017
1 parent b92e702 commit d42ee42
Show file tree
Hide file tree
Showing 4 changed files with 25 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": "^0.1.7"
},
"homepage": "https://github.com/azure/azure-rest-api-specs",
"repository": {
Expand Down
23 changes: 19 additions & 4 deletions scripts/breaking-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

/**
Expand Down Expand Up @@ -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]);
Expand All @@ -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;
})
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 @@ -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' });
}
Expand Down

0 comments on commit d42ee42

Please sign in to comment.