diff --git a/sdk/management/api-specs.json b/sdk/management/api-specs.json index 349d24690be0..0823f6bb2fed 100644 --- a/sdk/management/api-specs.json +++ b/sdk/management/api-specs.json @@ -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", diff --git a/sdk/management/package.json b/sdk/management/package.json index ee1d9771e9ee..332c01ceeecf 100644 --- a/sdk/management/package.json +++ b/sdk/management/package.json @@ -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", @@ -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" } } diff --git a/sdk/management/servcheck.js b/sdk/management/servcheck.js new file mode 100644 index 000000000000..0a2b8817eeba --- /dev/null +++ b/sdk/management/servcheck.js @@ -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(); \ No newline at end of file