From 377638dd59ddba30d5d2d5f48ca2d017139a4fbe Mon Sep 17 00:00:00 2001 From: xccc-msft Date: Wed, 8 Jul 2020 16:05:31 +0800 Subject: [PATCH 1/2] mgmt support api version detection --- sdk/management/api-specs.json | 3 +- sdk/management/package.json | 6 +- sdk/management/servcheck.js | 108 ++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 sdk/management/servcheck.js 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..8f7e37892cf6 --- /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(); From 09bffdca2fddaa3b2ab16e2cb849cc596c29bda4 Mon Sep 17 00:00:00 2001 From: xccc-msft Date: Wed, 8 Jul 2020 17:05:11 +0800 Subject: [PATCH 2/2] fix alignment --- sdk/management/servcheck.js | 140 ++++++++++++++++++------------------ 1 file changed, 70 insertions(+), 70 deletions(-) diff --git a/sdk/management/servcheck.js b/sdk/management/servcheck.js index 8f7e37892cf6..0a2b8817eeba 100644 --- a/sdk/management/servcheck.js +++ b/sdk/management/servcheck.js @@ -8,101 +8,101 @@ const colors = require('colors'); function servcheck() { console.log('[INFO] starting to check api versions of services...\n'); - readPom(); + 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); - }); + 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); + 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; + 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]); - }); + 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) { + 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; + 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(); + return value.replace(target, '').replace('\r', '').trim(); } -servcheck(); +servcheck(); \ No newline at end of file