Skip to content

Commit 28c6db8

Browse files
authored
Merge pull request #1696 from Azure/jcotillo/generate_onboarded_report
Ggenerate onboarded report
2 parents 4ab5d28 + 02f2726 commit 28c6db8

File tree

4 files changed

+127
-0
lines changed

4 files changed

+127
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
pr: none
2+
trigger: none
3+
4+
schedules:
5+
- cron: "0 6 * * 5"
6+
branches:
7+
include:
8+
- master
9+
displayName: Weekly report of onboarded RPs
10+
11+
jobs:
12+
- job: Generate
13+
timeoutInMinutes: 180
14+
15+
pool:
16+
vmImage: 'ubuntu-latest'
17+
18+
steps:
19+
- checkout: self
20+
clean: true
21+
22+
- task: DownloadSecureFile@1
23+
name: schemasDeployKey
24+
inputs:
25+
secureFile: schemas_rsa
26+
displayName: "Download GitHub Deploy Key"
27+
28+
- task: NodeTool@0
29+
inputs:
30+
versionSpec: '14.x'
31+
32+
- script: |
33+
set -Eeuxo pipefail
34+
mkdir ~/.ssh && mv $(schemasDeployKey.secureFilePath) ~/.ssh/schemas_rsa
35+
chmod 700 ~/.ssh
36+
chmod 600 ~/.ssh/schemas_rsa
37+
git config user.name "Autogenerator Pipeline"
38+
git config user.email "[email protected]"
39+
git config core.sshCommand "ssh -i ~/.ssh/schemas_rsa -F /dev/null"
40+
git remote set-url origin [email protected]:Azure/azure-resource-manager-schemas.git
41+
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
42+
git fetch
43+
displayName: Configure git
44+
45+
- script: |
46+
set -Eeuxo pipefail
47+
git checkout $(Build.SourceBranchName)
48+
displayName: Checkout repo
49+
50+
- script: |
51+
set -Eeuxo pipefail
52+
cd generator
53+
npm install
54+
displayName: 'Install packages'
55+
56+
- script: |
57+
set -Eeuxo pipefail
58+
cd generator
59+
npm run generate-onboarded-report
60+
displayName: 'Generate report'
61+
62+
- script: |
63+
set -Eeuxo pipefail
64+
git add --all onboarded-report
65+
if ! git diff-index --quiet HEAD --; then
66+
git commit -m "Generated report"
67+
git push origin $(Build.SourceBranchName)
68+
fi
69+
displayName: Commit report
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import * as constants from '../constants';
2+
import { cloneAndGenerateBasePaths, validateAndReturnReadmePath } from '../specs';
3+
import chalk from 'chalk';
4+
import { findAutogenEntries } from '../autogenlist';
5+
import { executeSynchronous, lowerCaseEquals, writeJsonFile, safeMkdir } from '../utils';
6+
import { getApiVersionsByNamespace } from '../generate';
7+
import { keys, partition } from 'lodash';
8+
import path from 'path';
9+
10+
executeSynchronous(async () => {
11+
const basePaths = await cloneAndGenerateBasePaths(constants.specsRepoPath, constants.specsRepoUri, constants.specsRepoCommitHash);
12+
13+
let allBasePaths = [];
14+
15+
for (const basePath of basePaths) {
16+
const readme = await validateAndReturnReadmePath(constants.specsRepoPath, basePath);
17+
const namespaces = keys(await getApiVersionsByNamespace(readme));
18+
const autogenlistEntries = findAutogenEntries(basePath);
19+
20+
const [autogened, unautogened] = partition(
21+
namespaces,
22+
n => autogenlistEntries.findIndex(w => lowerCaseEquals(w.namespace, n)) > -1);
23+
24+
if (unautogened.length > 0 && autogened.length > 0) {
25+
// For partial autogeneration only, add two items
26+
// one item containing resource types not onboarded for autogeneration
27+
// and the other item containing resource types onboarded for autogeneration
28+
allBasePaths.push({
29+
'basePath': basePath,
30+
'onboardedToAutogen': 'no',
31+
'missing': unautogened,
32+
'included': []
33+
});
34+
35+
allBasePaths.push({
36+
'basePath': basePath,
37+
'onboardedToAutogen': 'yes',
38+
'missing': [],
39+
'included': autogened
40+
});
41+
}
42+
else {
43+
// unautogened.length === 0 means all resource types are onboarded for autogeneration
44+
allBasePaths.push({
45+
'basePath': basePath,
46+
'onboardedToAutogen': unautogened.length === 0 ? 'yes' : 'no',
47+
'missing': unautogened,
48+
'onboarded': []
49+
});
50+
}
51+
}
52+
53+
const autogenResultPath = path.join(constants.autogenResultPath, 'result.json');
54+
await safeMkdir(constants.autogenResultPath);
55+
await writeJsonFile(autogenResultPath, allBasePaths);
56+
});

generator/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const autoRestVerboseOutput = false;
1212

1313
export const schemasBaseUri = 'https://schema.management.azure.com/schemas';
1414
export const schemasBasePath = path.join(generatorRoot, 'schemas');
15+
export const autogenResultPath = path.join(generatorRoot, 'onboarded-report');
1516
export const resourceGroupRootSchema = {
1617
file: path.join(schemasBasePath, 'common/autogeneratedResources.json'),
1718
jsonPath: 'allOf[1].oneOf'

generator/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"npm": ">=6.0.0"
99
},
1010
"scripts": {
11+
"generate-onboarded-report": "ts-node cmd/getrpsonboarded",
1112
"list-basepaths": "ts-node cmd/listbasepaths",
1213
"list-resources": "ts-node cmd/listresources",
1314
"generate-all": "ts-node cmd/generateall",

0 commit comments

Comments
 (0)