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

mgmt support api version detection #12907

Merged
merged 2 commits into from
Jul 9, 2020
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
3 changes: 2 additions & 1 deletion sdk/management/api-specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@
"policy": {
"dir": "../resources/mgmt",
"source": "specification/resources/resource-manager/readme.md",
"package": "com.azure.resourcemanager.resources --tag=package-policy-2019-09"
"package": "com.azure.resourcemanager.resources",
"args": "--payload-flattening-threshold=1 --tag=package-policy-2019-09"
},
"powerbi": {
"dir": "../powerbi/mgmt",
Expand Down
6 changes: 4 additions & 2 deletions sdk/management/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"credcheck_storage": "node credcheck.js --path=../storage/mgmt/src/test/resources/session-records/",
"credcheck_azure": "node credcheck.js --path=./azure/src/test/resources/session-records/",
"credcheck_samples": "node credcheck.js --path=./samples/src/test/resources/session-records/",
"credcheck_all": "run-s credcheck_appservice credcheck_authorization credcheck_compute credcheck_containerregistry credcheck_containerservice credcheck_cosmos credcheck_dns credcheck_keyvault credcheck_msi credcheck_monitor credcheck_network credcheck_resources credcheck_sql credcheck_storage credcheck_azure credcheck_samples"
"credcheck_all": "run-s credcheck_appservice credcheck_authorization credcheck_compute credcheck_containerregistry credcheck_containerservice credcheck_cosmos credcheck_dns credcheck_keyvault credcheck_msi credcheck_monitor credcheck_network credcheck_resources credcheck_sql credcheck_storage credcheck_azure credcheck_samples",
"servcheck": "node servcheck.js"
},
"devDependencies": {
"colors": "1.1.2",
Expand All @@ -45,6 +46,7 @@
"gulp-shell": "^0.8.0",
"p-all": "^1.0.0",
"yargs": "3.31.0",
"npm-run-all": "4.1.5"
"npm-run-all": "4.1.5",
"pom-parser": "1.2.0"
}
}
108 changes: 108 additions & 0 deletions sdk/management/servcheck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
const args = require('yargs').argv;
const os = require('os');
const fs = require('fs');
const path = require('path');
const parser = require("pom-parser");
const colors = require('colors');


function servcheck() {
console.log('[INFO] starting to check api versions of services...\n');
readPom();
}


function readPom(callback) {
var opts = {
filePath: __dirname + "/pom.xml",
};
parser.parse(opts, function(err, response) {
if (err) {
console.log('[ERROR] ' + err);
process.exit(1);
}
console.log('[INFO] reading modules from pom...');
readProjSpecs(response.pomObject.project.modules.module);
});
}

const mappings = require('./api-specs.json');

function readProjSpecs(modules) {
console.log('[INFO] reading specs in project...');
var map = {};
Object.keys(mappings).forEach(key => {
if (modules.includes(mappings[key].dir)) {
var val = getCurrentApiVersion(mappings[key].args);
if (val !== undefined) {
map[key] = {};
map[key].name = key;
map[key].tag = val;
map[key].source = mappings[key].source;
}
}
});
readLatestSpecs(map);
}

function getCurrentApiVersion(value) {
var res = undefined;
value.split(/\s+/).forEach(item => {
if (item.includes('--tag=')) {
res = item.replace('--tag=', '');
}
});
return res;
}

function readLatestSpecs(map) {
console.log('[INFO] reading specs from swagger root...');
Object.keys(map).forEach(item => {
readLatestApiVersion(map[item]);
});
}

const dir = args['spec-root'];

function readLatestApiVersion(spec) {
console.log('\n[Service] ' + spec.name);
console.log(' current: ' + spec.tag);
const filePath = path.join(dir, spec.source);
const content = fs.readFileSync(filePath).toString('utf8');

var latest = {};
var allTags = [];
var lines = content.split('\n');
lines.forEach(line => {
if (line.startsWith('tag:')) {
if (latest.tag === undefined || latest.tag != undefined && line.includes(spec.name)) {
latest.tag = getApiVersion(line, 'tag:');
}
}
if (line.includes('Tag:') && !line.includes(' and ')) {
allTags.push(getApiVersion(line, '### Tag:'));
}
});

console.log(' latest: ' + latest.tag);

if (spec.tag !== latest.tag) {
allTags.sort().reverse();
console.log('\n potential versions to upgrade:');
allTags.forEach(tag => {
if (tag == spec.tag) {
console.log(' ' + tag.bold.underline.yellow);
} else {
console.log(' ' + tag);
}
});
}

return latest;
}

function getApiVersion(value, target) {
return value.replace(target, '').replace('\r', '').trim();
}

servcheck();