Skip to content

Commit 92d0aa3

Browse files
authored
mgmt add script to update single-service packages (Azure#18242)
* mgmt add script to update single-service packages * fix typo * add doc with format details * update latest packages releases * remove locale
1 parent 28f41e8 commit 92d0aa3

File tree

3 files changed

+259
-14
lines changed

3 files changed

+259
-14
lines changed

sdk/resourcemanager/autocent.js

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const request = require('request');
4+
5+
// mapping for services with different spec folder names
6+
const specs = {
7+
'avs': 'vmware',
8+
'cosmos': 'cosmos-db',
9+
'costmanagement': 'cost-management',
10+
'customerinsights': 'customer-insights',
11+
'datalakeanalytics': 'datalake-analytics',
12+
'datalakestore': 'datalake-store',
13+
'delegatednetwork': 'dnc',
14+
'eventhubs': 'eventhub',
15+
'loganalytics': 'operationalinsights',
16+
'kusto': 'azure-kusto',
17+
'servicemap': 'service-map'
18+
};
19+
const groupUrl = 'https://repo1.maven.org/maven2/com/azure/resourcemanager/';
20+
const artiRegEx = />(azure-resourcemanager-.+)\/</g;
21+
const verRegEx = /<version>(.+)<\/version>/g;
22+
const pkgRegEx = /Package\s+tag\s+(.+)\.\s+For/g;
23+
var startCnt = 0;
24+
var endCnt = 0;
25+
var data = {};
26+
27+
function autocent() {
28+
console.log('[INFO] Automation task to update the mapping of services and API version tags.');
29+
30+
getArtifacts();
31+
}
32+
33+
// method to get all matched artifacts from maven central
34+
function getArtifacts() {
35+
sendRequest(groupUrl, function(response) {
36+
var artifacts = [];
37+
var match = artiRegEx.exec(response);
38+
while (match !== null) {
39+
artifacts.push(match[1]);
40+
match = artiRegEx.exec(response);
41+
}
42+
for (var i in artifacts) {
43+
readMetadata(artifacts[i]);
44+
}
45+
});
46+
}
47+
48+
// method to read metadata for getting all published package versions
49+
function readMetadata(artifact) {
50+
sendRequest(groupUrl + artifact + '/maven-metadata.xml', function(response) {
51+
var versions = [];
52+
var match = verRegEx.exec(response);
53+
while (match !== null) {
54+
++startCnt;
55+
versions.push(match[1]);
56+
match = verRegEx.exec(response);
57+
}
58+
for (var i in versions) {
59+
readPom(artifact, versions[i]);
60+
}
61+
});
62+
}
63+
64+
// method to read pom for each package version and get API version tag from description
65+
function readPom(artifact, version) {
66+
sendRequest(groupUrl + artifact + '/' + version + '/' + artifact + '-' + version + '.pom', function(response) {
67+
var match = pkgRegEx.exec(response);
68+
++endCnt;
69+
if (match === null) {
70+
// console.log('[WARN] no package tag found in ' + artifact + '_' + version);
71+
} else {
72+
var tag = match[1];
73+
var service = artifact.split('-').pop();
74+
if (!data[service]) {
75+
data[service] = {};
76+
}
77+
if (!data[service][tag]) {
78+
data[service][tag] = [];
79+
}
80+
data[service][tag].push(version);
81+
}
82+
if (startCnt == endCnt) {
83+
// update file for listing all latest releases of the packages
84+
var content = '# Single-Service Packages Latest Releases\n\n' +
85+
'The single-service packages provide easy-to-use APIs for each Azure service following the design principals of [Azure Management Libraries for Java](https://github.com/Azure/azure-sdk-for-java/tree/master/sdk/resourcemanager). If you have specific requirement on certain service API version, you may find appropriate package below. If not, you could always choose the latest release.\n\n' +
86+
'According to [Azure REST API reference](https://docs.microsoft.com/rest/api/azure/), most request URIs of Azure services require `api-version` as the query-string parameter. All supported API versions for each Azure service can be found via [Azure REST API Specifications](https://github.com/Azure/azure-rest-api-specs/tree/master/specification). For your convenience, we provide more details of the published packages by format below.\n\n' +
87+
'```\n' +
88+
'service\n' +
89+
'* package-tag\n' +
90+
' * maven.version\n' +
91+
'```\n\n' +
92+
'- `service` for Azure service.\n' +
93+
'- `package-tag` for included resources with API versions.\n' +
94+
'- `maven.version` for maven version of the artifact.\n\n';
95+
96+
var sortedServices = Object.keys(data).sort();
97+
for (var i in sortedServices) {
98+
var service = sortedServices[i];
99+
content += '\n<br/>\n' +
100+
'<details>\n' +
101+
'<summary> ' + service + ' </summary>\n\n';
102+
var sortedTags = Object.keys(data[service]).sort().reverse();
103+
for (var j in sortedTags) {
104+
var tag = sortedTags[j];
105+
var spec = specs[service] ? specs[service] : service;
106+
content += '* [' + tag + '](https://github.com/Azure/azure-rest-api-specs/tree/master/specification/' + spec + '/resource-manager#tag-' + tag + ')\n';
107+
var sortedVersions = data[service][tag].sort(function(a, b) {
108+
// custom method to sort versions
109+
var aVerNums = a.split(".");
110+
var bVerNums = b.split(".");
111+
if (aVerNums[0] > bVerNums[0]) {
112+
return -1;
113+
} else if (aVerNums[0] < bVerNums[0]) {
114+
return 1;
115+
} else {
116+
if (aVerNums[1] > bVerNums[1]) {
117+
return -1;
118+
} else if (aVerNums[1] < bVerNums[1]) {
119+
return 1;
120+
} else {
121+
var aPatchNums = aVerNums[2].split("-beta.");
122+
var bPatchNums = bVerNums[2].split("-beta.");
123+
if (aPatchNums.length < bPatchNums.length) {
124+
return -1;
125+
} else if (aPatchNums.length > bPatchNums.length) {
126+
return 1;
127+
} else {
128+
return b.localeCompare(a);
129+
}
130+
}
131+
}
132+
});
133+
for (var k in sortedVersions) {
134+
var sdk = sortedVersions[k];
135+
content += ' * [' + sdk + '](https://search.maven.org/artifact/com.azure.resourcemanager/azure-resourcemanager-' + service + '/' + sdk + '/jar)\n';
136+
}
137+
}
138+
content += '</details>\n';
139+
}
140+
fs.writeFileSync("docs/SINGLE_SERVICE_PACKAGES.md", content);
141+
}
142+
});
143+
}
144+
145+
// method to send GET request
146+
function sendRequest(url, callback) {
147+
request({
148+
url: url,
149+
method: 'GET',
150+
headers: {
151+
'user-agent': 'AutoCent'
152+
}
153+
}, function(error, response) {
154+
if (error) {
155+
console.log('[ERROR] Request URL: ' + url);
156+
process.exit(1);
157+
}
158+
callback(response.body);
159+
});
160+
}
161+
162+
autocent();
Lines changed: 93 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,104 @@
11
# Single-Service Packages Latest Releases
22

3-
The single-service packages provide easy-to-use APIs for each Azure service following the design principals of [Azure Management Libraries for Java](https://github.com/Azure/azure-sdk-for-java/tree/master/sdk/resourcemanager). If you have specific requirement on certain service API, you may find appropriate package below.
3+
The single-service packages provide easy-to-use APIs for each Azure service following the design principals of [Azure Management Libraries for Java](https://github.com/Azure/azure-sdk-for-java/tree/master/sdk/resourcemanager). If you have specific requirement on certain service API version, you may find appropriate package below. If not, you could always choose the latest release.
4+
5+
According to [Azure REST API reference](https://docs.microsoft.com/rest/api/azure/), most request URIs of Azure services require `api-version` as the query-string parameter. All supported API versions for each Azure service can be found via [Azure REST API Specifications](https://github.com/Azure/azure-rest-api-specs/tree/master/specification). For your convenience, we provide more details of the published packages by format below.
6+
7+
```
8+
service
9+
* package-tag
10+
* maven.version
11+
```
12+
13+
- `service` for Azure service.
14+
- `package-tag` for included resources with API versions.
15+
- `maven.version` for maven version of the artifact.
16+
17+
18+
<br/>
19+
<details>
20+
<summary> costmanagement </summary>
21+
22+
* [package-2020-06](https://github.com/Azure/azure-rest-api-specs/tree/master/specification/cost-management/resource-manager#tag-package-2020-06)
23+
* [1.0.0-beta.1](https://search.maven.org/artifact/com.azure.resourcemanager/azure-resourcemanager-costmanagement/1.0.0-beta.1/jar)
24+
</details>
25+
26+
<br/>
27+
<details>
28+
<summary> eventgrid </summary>
29+
30+
* [package-2020-06](https://github.com/Azure/azure-rest-api-specs/tree/master/specification/eventgrid/resource-manager#tag-package-2020-06)
31+
* [1.0.0-beta.1](https://search.maven.org/artifact/com.azure.resourcemanager/azure-resourcemanager-eventgrid/1.0.0-beta.1/jar)
32+
</details>
33+
34+
<br/>
35+
<details>
36+
<summary> hdinsight </summary>
37+
38+
* [package-2018-06-preview](https://github.com/Azure/azure-rest-api-specs/tree/master/specification/hdinsight/resource-manager#tag-package-2018-06-preview)
39+
* [1.0.0-beta.1](https://search.maven.org/artifact/com.azure.resourcemanager/azure-resourcemanager-hdinsight/1.0.0-beta.1/jar)
40+
</details>
41+
42+
<br/>
43+
<details>
44+
<summary> kusto </summary>
45+
46+
* [package-2020-09-18](https://github.com/Azure/azure-rest-api-specs/tree/master/specification/azure-kusto/resource-manager#tag-package-2020-09-18)
47+
* [1.0.0-beta.1](https://search.maven.org/artifact/com.azure.resourcemanager/azure-resourcemanager-kusto/1.0.0-beta.1/jar)
48+
</details>
49+
50+
<br/>
51+
<details>
52+
<summary> loganalytics </summary>
53+
54+
* [package-2020-08](https://github.com/Azure/azure-rest-api-specs/tree/master/specification/operationalinsights/resource-manager#tag-package-2020-08)
55+
* [1.0.0-beta.1](https://search.maven.org/artifact/com.azure.resourcemanager/azure-resourcemanager-loganalytics/1.0.0-beta.1/jar)
56+
</details>
457

558
<br/>
659
<details>
7-
<summary> service_holder1 </summary>
60+
<summary> mediaservices </summary>
861

9-
* api_version_holder1
10-
* package_version_holder1
11-
* package_version_holder2
12-
* api_version_holder2
13-
* package_version_holder3
62+
* [package-2020-05](https://github.com/Azure/azure-rest-api-specs/tree/master/specification/mediaservices/resource-manager#tag-package-2020-05)
63+
* [1.0.0-beta.1](https://search.maven.org/artifact/com.azure.resourcemanager/azure-resourcemanager-mediaservices/1.0.0-beta.1/jar)
1464
</details>
1565

1666
<br/>
1767
<details>
18-
<summary> service_holder2 </summary>
68+
<summary> mysql </summary>
1969

20-
* api_version_holder1
21-
* package_version_holder1
22-
* package_version_holder2
23-
</details>
70+
* [package-2020-01-01](https://github.com/Azure/azure-rest-api-specs/tree/master/specification/mysql/resource-manager#tag-package-2020-01-01)
71+
* [1.0.0-beta.1](https://search.maven.org/artifact/com.azure.resourcemanager/azure-resourcemanager-mysql/1.0.0-beta.1/jar)
72+
</details>
73+
74+
<br/>
75+
<details>
76+
<summary> postgresql </summary>
77+
78+
* [package-2020-01-01](https://github.com/Azure/azure-rest-api-specs/tree/master/specification/postgresql/resource-manager#tag-package-2020-01-01)
79+
* [1.0.0-beta.1](https://search.maven.org/artifact/com.azure.resourcemanager/azure-resourcemanager-postgresql/1.0.0-beta.1/jar)
80+
</details>
81+
82+
<br/>
83+
<details>
84+
<summary> recoveryservices </summary>
85+
86+
* [package-2016-06](https://github.com/Azure/azure-rest-api-specs/tree/master/specification/recoveryservices/resource-manager#tag-package-2016-06)
87+
* [1.0.0-beta.1](https://search.maven.org/artifact/com.azure.resourcemanager/azure-resourcemanager-recoveryservices/1.0.0-beta.1/jar)
88+
</details>
89+
90+
<br/>
91+
<details>
92+
<summary> relay </summary>
93+
94+
* [package-2017-04](https://github.com/Azure/azure-rest-api-specs/tree/master/specification/relay/resource-manager#tag-package-2017-04)
95+
* [1.0.0-beta.1](https://search.maven.org/artifact/com.azure.resourcemanager/azure-resourcemanager-relay/1.0.0-beta.1/jar)
96+
</details>
97+
98+
<br/>
99+
<details>
100+
<summary> sqlvirtualmachine </summary>
101+
102+
* [package-2017-03-01-preview](https://github.com/Azure/azure-rest-api-specs/tree/master/specification/sqlvirtualmachine/resource-manager#tag-package-2017-03-01-preview)
103+
* [1.0.0-beta.1](https://search.maven.org/artifact/com.azure.resourcemanager/azure-resourcemanager-sqlvirtualmachine/1.0.0-beta.1/jar)
104+
</details>

sdk/resourcemanager/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"credcheck_azure": "node credcheck.js --path=./azure-resourcemanager/src/test/resources/session-records/",
4343
"credcheck_samples": "node credcheck.js --path=./azure-resourcemanager-samples/src/test/resources/session-records/",
4444
"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_appplatform credcheck_redis credcheck_eventhubs credcheck_trafficmanager credcheck_cdn credcheck_containerinstance credcheck_privatedns credcheck_servicebus credcheck_azure credcheck_samples",
45-
"servcheck": "node servcheck.js"
45+
"servcheck": "node servcheck.js",
46+
"autocent": "node autocent.js"
4647
},
4748
"devDependencies": {
4849
"colors": "1.1.2",
@@ -55,6 +56,7 @@
5556
"p-all": "^1.0.0",
5657
"yargs": "3.31.0",
5758
"npm-run-all": "4.1.5",
58-
"pom-parser": "1.2.0"
59+
"pom-parser": "1.2.0",
60+
"request": "2.88.2"
5961
}
6062
}

0 commit comments

Comments
 (0)