Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebased master to monthly network branch #3687

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
/specification/operationsmanagement/ @dashimi16
/specification/policyinsights/ @bulentelmaci
/specification/postgresql/ @qingqingyuan
/specification/powerbidedicated/ @tarostok
/specification/provisioningservices/ @kvish
/specification/recoveryservices/ @dragonfly91 @sonathan
/specification/recoveryservicesbackup/ @dheerendrarathor
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"json-schema-ref-parser": "^3.1.2",
"mocha": "*",
"oad": "^0.1.11",
"oav": "^0.4.57",
"oav": "^0.5.1",
"request": "^2.61.0",
"request-promise-native": "^1.0.5",
"z-schema": "^3.16.1"
Expand Down
80 changes: 38 additions & 42 deletions scripts/breaking-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Licensed under the MIT License. See License in the project root for license information.

'use strict';
var utils = require('../test/util/utils'),
const utils = require('../test/util/utils'),
path = require('path'),
fs = require('fs'),
fs = require('fs-extra'),
os = require('os'),
execSync = require('child_process').execSync,
exec = require('util').promisify(require('child_process').exec),
oad = require('oad');

// This map is used to store the mapping between files resolved and stored location
Expand Down Expand Up @@ -65,13 +65,16 @@ async function runOad(oldSpec, newSpec) {
console.log(`New Spec: "${newSpec}"`);
console.log(`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`);

const result = await oad.compare(oldSpec, newSpec, { consoleLogLevel: 'warn', json: true });
let result = await oad.compare(oldSpec, newSpec, { consoleLogLevel: 'warn', json: true });
console.log(result);

if (!result) {
return;
}

// fix up output from OAD, it does not output valid JSON
result = '[' + result.replace(/}\s+{/gi,"},{") + ']'

return JSON.parse(result);
}

Expand All @@ -80,57 +83,53 @@ async function runOad(oldSpec, newSpec) {
*
* @param {string} swaggerPath Path to the swagger specification file.
*/
function processViaAutoRest(swaggerPath) {
async function processViaAutoRest(swaggerPath) {
if (swaggerPath === null || swaggerPath === undefined || typeof swaggerPath.valueOf() !== 'string' || !swaggerPath.trim().length) {
return Promise.reject(new Error('swaggerPath is a required parameter of type "string" and it cannot be an empty string.'));
throw new Error('swaggerPath is a required parameter of type "string" and it cannot be an empty string.');
}

console.log(`Processing via AutoRest...`);

let outputFileNameWithExt = path.basename(swaggerPath);
let outputFileNameWithoutExt = path.basename(swaggerPath, '.json');
let autoRestCmd = `autorest --input-file=${swaggerPath} --output-artifact=swagger-document.json --output-file=${outputFileNameWithoutExt} --output-folder=${outputFolder}`;
const swaggerOutputFolder = path.join(outputFolder, path.dirname(swaggerPath));
const swaggerOutputFileNameWithoutExt = path.basename(swaggerPath, '.json');
const autoRestCmd = `autorest --input-file=${swaggerPath} --output-artifact=swagger-document.json --output-file=${swaggerOutputFileNameWithoutExt} --output-folder=${swaggerOutputFolder}`;

console.log(`Executing : ${autoRestCmd}`);

try {
let result = execSync(`${autoRestCmd}`, { encoding: 'utf8', maxBuffer: 1024 * 1024 * 64 });
resolvedMapForNewSpecs[outputFileNameWithExt] = path.join(outputFolder, outputFileNameWithExt);
await fs.ensureDir(swaggerOutputFolder);
await exec(`${autoRestCmd}`, { encoding: 'utf8', maxBuffer: 1024 * 1024 * 64 });
resolvedMapForNewSpecs[swaggerPath] = path.join(swaggerOutputFolder, swaggerOutputFileNameWithoutExt + '.json');
} catch (err) {
// Do not update map in case of errors.
console.log(`Error processing via AutoRest: ${err}`);
}

return Promise.resolve();
}

//main function
async function runScript() {
// See whether script is in Travis CI context
console.log(`isRunningInTravisCI: ${isRunningInTravisCI}`);

// Create directory to store the processed & resolved swaggers
if (!fs.existsSync(outputFolder)) {
fs.mkdirSync(outputFolder);
}

let targetBranch = utils.getTargetBranch();
let swaggersToProcess = utils.getFilesChangedInPR();

console.log('Processing swaggers:');
console.log(swaggersToProcess);

for (const swagger of swaggersToProcess) {
await processViaAutoRest(swagger);
}

console.log('Finding new swaggers...')
let newSwaggers = [];
if (isRunningInTravisCI && swaggersToProcess.length > 0) {
newSwaggers = await utils.doOnBranch(utils.getTargetBranch(), async () => {
return swaggersToProcess.filter(s => !fs.existsSync(s))
});
}

console.log(`Resolved map for the new specification is:`);
console.log('Processing via AutoRest...');
for (const swagger of swaggersToProcess) {
if (!newSwaggers.includes(swagger)) {
await processViaAutoRest(swagger);
}
}

console.log(`Resolved map for the new specifications:`);
console.dir(resolvedMapForNewSpecs);

let errors = 0, warnings = 0;
Expand All @@ -145,23 +144,20 @@ async function runScript() {
continue;
}

let outputFileNameWithExt = path.basename(swagger);
console.log(outputFileNameWithExt);
if (resolvedMapForNewSpecs[outputFileNameWithExt]) {
const diff = await runOad(swagger, resolvedMapForNewSpecs[outputFileNameWithExt]);
if (diff) {
if (!diffFiles[swagger]) {
diffFiles[swagger] = [];
}
diffFiles[swagger].push(diff);
if (diff['type'] === 'Error') {
if (errors === 0) {
console.log(`There are potential breaking changes in this PR. Please review before moving forward. Thanks!`);
process.exitCode = 1;
if (resolvedMapForNewSpecs[swagger]) {
const diffs = await runOad(swagger, resolvedMapForNewSpecs[swagger]);
if (diffs) {
diffFiles[swagger] = diffs;
for (const diff of diffs) {
if (diff['type'] === 'Error') {
if (errors === 0) {
console.log(`There are potential breaking changes in this PR. Please review before moving forward. Thanks!`);
process.exitCode = 1;
}
errors += 1;
} else if (diff['type'] === 'Warning') {
warnings += 1;
}
errors += 1;
} else if (diff['type'] === 'Warning') {
warnings += 1;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Please also specify `--node-sdks-folder=<path to root folder of your azure-sdk-f
nodejs:
azure-arm: true
package-name: azure-arm-authorization
package-version: 4.1.0
package-version: 5.0.1
output-folder: $(node-sdks-folder)/lib/services/authorizationManagement
payload-flattening-threshold: 1
generate-license-txt: true
Expand Down
Loading