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

Updated getStatus to run autorest with grouping swaggers based on config file #1529

Merged
merged 1 commit into from
Aug 10, 2017
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
45 changes: 27 additions & 18 deletions scripts/getStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var exec = require('child_process').exec,
utils = require("../test/util/utils");

var swaggersToProcess = utils.swaggers;
var readmesToProcess = utils.readmes;
var finalResult = {};
var filename = `log_${utils.getTimeStamp()}.log`;
var logFilepath = path.join(getLogDir(), filename);
Expand Down Expand Up @@ -50,9 +51,9 @@ function writeContent(content) {
}

//runs the linter on a given swagger spec.
async function runLinter(swagger) {
// TODO: update to use config file... but report grouping is by Swagger right now
let cmd = 'autorest --validation --azure-validator --input-file=' + swagger + ' --message-format=json';
async function runLinter(readme) {
let cmd = 'autorest ' + readme + ' --azure-validator=true --message-format=json';
console.log(cmd);
console.log(`\t- Running Linter.`);
const {err, stdout, stderr } = await new Promise(res => exec(cmd, { encoding: 'utf8', maxBuffer: 1024 * 1024 * 64 },
(err, stdout, stderr) => res({ err: err, stdout: stdout, stderr: stderr })));
Expand All @@ -69,7 +70,7 @@ async function runLinter(swagger) {
//console.log('>>>>>> Parsed Result...');
//console.dir(resultObject, {depth: null, colors: true});
} catch (e) {
console.log(`An error occurred while executing JSON.parse() on the linter output for ${swagger}:`);
console.log(`An error occurred while executing JSON.parse() on the linter output for ${readme}:`);
console.dir(resultString);
console.dir(e, { depth: null, colors: true });
}
Expand All @@ -88,27 +89,35 @@ function runSemanticValidator(swagger) {
});
}

//runs the validation and linting tools on all the swaggers in the repo.
async function runTools(swagger) {
console.log(`Processing "${swagger}":`);
const validationErrors = await runSemanticValidator(swagger);
updateResult(swagger, validationErrors, true);
const linterErrors = await runLinter(swagger);
updateResult(swagger, linterErrors, true);
}

//main function
async function runScript() {
// Useful when debugging a test for a particular swagger.
// Just update the regex. That will return an array of filtered items.
// swaggersToProcess = swaggersToProcess.filter(function (item) {
// return (item.match(/.*arm-network/ig) !== null);
// });
// swaggersToProcess = swaggersToProcess.filter(function (item) {
// return (item.match(/.*Microsoft.network/ig) !== null);
// });
// readmesToProcess = readmesToProcess.filter(function (item) {
// return (item.match(/.*.network/ig) !== null);
// });
createLogFile();
console.log(`The results will be logged here: "${logFilepath}".`);
for (const swagger of swaggersToProcess) {
await runTools(swagger);

for (let swagger of swaggersToProcess) {
const validationErrors = await runSemanticValidator(swagger);
swagger = swagger.split(/\/Microsoft\./gi)[0] + "/readme.md";
console.log(`File Name: "${swagger}"`);
if (validationErrors != null)
{
updateResult(swagger, validationErrors, true);
}
}

for (let readme of readmesToProcess) {
console.log(`Configuration file: "${readme}"`);
const linterErrors = await runLinter(readme);
updateResult(readme, linterErrors, true);
}

//console.dir(finalResult, { depth: null, colors: true });
return finalResult;
}
Expand Down
1 change: 1 addition & 0 deletions test/util/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ exports.globPath = path.join(__dirname, '../', '../', '/specification/**/*.json'
exports.swaggers = glob.sync(exports.globPath, { ignore: ['**/examples/**/*.json', '**/quickstart-templates/*.json', '**/schema/*.json'] });
exports.exampleGlobPath = path.join(__dirname, '../', '../', '/specification/**/examples/**/*.json');
exports.examples = glob.sync(exports.exampleGlobPath);
exports.readmes = glob.sync(path.join(__dirname, '../', '../', '/specification/**/readme.md'));

// Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
// because the buffer-to-string conversion in `fs.readFile()`
Expand Down