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

Support Modular Auto Generation #8906

Merged
merged 102 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
b51417c
Add script for generating modular client
wanlwanl Jul 10, 2024
18b2c8e
Update
wanlwanl Jul 12, 2024
c01c609
wip
wanlwanl Jul 15, 2024
2a656f9
WIP
wanlwanl Jul 15, 2024
c5d44e9
wip: remove sync call
wanlwanl Jul 16, 2024
1dd0e18
Done: modular client SDK automation
wanlwanl Jul 17, 2024
bffac92
WIP
wanlwanl Jul 17, 2024
24c175f
WIP
wanlwanl Jul 18, 2024
8ae2d22
minor fixes
wanlwanl Jul 19, 2024
fb45485
Merge remote-tracking branch 'Azure/main' into wanl/generate-mlc-in-p…
wanlwanl Aug 6, 2024
9da8cc3
Updated package.json
wanlwanl Aug 6, 2024
9b7c34a
Improve log
wanlwanl Aug 6, 2024
cee471a
Removed former files
wanlwanl Aug 6, 2024
b181523
Fixed typo
wanlwanl Aug 6, 2024
76ae5f2
Added timeout for runCommand
wanlwanl Aug 6, 2024
7353932
Updated
wanlwanl Aug 7, 2024
b2b948c
Improved logs
wanlwanl Aug 7, 2024
0ddeacf
Only run node test
wanlwanl Aug 7, 2024
51c0432
Removed len == 1 array
wanlwanl Aug 7, 2024
c1cc649
Updated package version
wanlwanl Aug 7, 2024
be22004
Fixed template not found bug
wanlwanl Aug 7, 2024
5479d08
Update build script
wanlwanl Aug 8, 2024
f83c346
Updated package.json
wanlwanl Aug 8, 2024
f41efa4
Fixed sdk type bug
wanlwanl Aug 9, 2024
7fc8d1d
Fixed no throw issue
wanlwanl Aug 9, 2024
7807bee
Fix
wanlwanl Aug 9, 2024
3b4a747
Update package.json
wanlwanl Aug 10, 2024
34d79a5
Update lock file
wanlwanl Aug 10, 2024
8b9f05f
Update
wanlwanl Aug 12, 2024
fcb860a
a
wanlwanl Aug 12, 2024
8d3535c
a
wanlwanl Aug 12, 2024
7629820
Revert "a"
wanlwanl Aug 12, 2024
977fc9c
Revert "a"
wanlwanl Aug 12, 2024
f7d0eb9
debug
wanlwanl Aug 12, 2024
457d84c
Revert "debug"
wanlwanl Aug 12, 2024
6ef90db
Merge remote-tracking branch 'Azure/main' into wanl/generate-mlc-in-p…
wanlwanl Aug 13, 2024
0bacf98
Merge remote-tracking branch 'Azure/main' into wanl/generate-mlc-in-p…
wanlwanl Aug 13, 2024
45ea971
Remove dup code
wanlwanl Aug 13, 2024
fe1d89d
Merge remote-tracking branch 'Azure/main' into wanl/generate-mlc-in-p…
wanlwanl Aug 13, 2024
c8339e6
Fix merge conflict
wanlwanl Aug 14, 2024
b4be50f
Update
wanlwanl Aug 14, 2024
21fef1f
Normalize path
wanlwanl Aug 14, 2024
6eaa6f8
Update apiViewArtifact declaration
wanlwanl Aug 14, 2024
785c1b4
Merge remote-tracking branch 'Azure/main' into wanl/generate-mlc-in-p…
wanlwanl Aug 15, 2024
e8107b4
Update path
wanlwanl Aug 15, 2024
d804811
Workaround to pass pipeline
wanlwanl Aug 15, 2024
555ee16
Update mgitignore
wanlwanl Aug 15, 2024
33400f5
Update api view json
wanlwanl Aug 15, 2024
a03f837
Remove
wanlwanl Aug 15, 2024
34b5721
Update logger
wanlwanl Aug 15, 2024
a5232c3
.
wanlwanl Aug 15, 2024
cfd3cbb
Remove useless log
wanlwanl Aug 15, 2024
d373867
.
wanlwanl Aug 15, 2024
fbafd2a
Comment
wanlwanl Aug 15, 2024
e293e3c
Add debug info
wanlwanl Aug 15, 2024
c6e0480
.
wanlwanl Aug 15, 2024
4864fa9
Silent log
wanlwanl Aug 15, 2024
0063461
Debug
wanlwanl Aug 15, 2024
8cc8d3e
Copy api view to somewhere else to avoid clean up by npm script
wanlwanl Aug 16, 2024
964ddfd
.
wanlwanl Aug 16, 2024
e358bda
Cleanup
wanlwanl Aug 16, 2024
ec3e97b
Update rush script
wanlwanl Aug 16, 2024
1f93650
Update rush script
wanlwanl Aug 16, 2024
15d8ef4
Merge remote-tracking branch 'origin/main' into wanl/generate-mlc-in-…
wanlwanl Aug 19, 2024
a3da3b7
Add missing package
wanlwanl Aug 20, 2024
cfd328b
chore: Remove shx dependency and update npm packages
wanlwanl Aug 20, 2024
9b1dfbb
Update CI creator
wanlwanl Aug 21, 2024
30de101
Add log
wanlwanl Aug 21, 2024
f0ecdab
Update
wanlwanl Aug 21, 2024
d6e8b67
Update MC check
wanlwanl Aug 21, 2024
939dfbb
Update log level
wanlwanl Aug 21, 2024
425ed30
Support emitter 0.32 in api version extraction
wanlwanl Aug 21, 2024
b0d73c0
Change temp folder location
wanlwanl Aug 21, 2024
b28ca4d
Add log
wanlwanl Aug 22, 2024
1c77b07
Add debug info
wanlwanl Aug 22, 2024
92ef62c
Fix package info
wanlwanl Aug 22, 2024
ea7a152
Fix
wanlwanl Aug 22, 2024
b9a5199
Improve logging
wanlwanl Aug 23, 2024
e0f270a
Update logging
wanlwanl Aug 23, 2024
772ff66
.
wanlwanl Aug 23, 2024
a8e7a11
Update logging
wanlwanl Aug 23, 2024
e41f373
Update log
wanlwanl Aug 23, 2024
61a6f11
RLC update
wanlwanl Aug 26, 2024
29fdfc1
Simplify
wanlwanl Aug 26, 2024
98ce65b
Add default package name
wanlwanl Aug 26, 2024
f0f3640
Fix runCommand
wanlwanl Aug 26, 2024
c73b816
Fix parameters finding
wanlwanl Aug 26, 2024
d94c4f7
Fix run command issue
wanlwanl Aug 26, 2024
971cdaf
Fix runCommand issue
wanlwanl Aug 26, 2024
61d11b0
Improve logging
wanlwanl Aug 27, 2024
97fb165
Add error keyword
wanlwanl Aug 27, 2024
80c366d
WIP on wanl/generate-mlc-in-pipeline
wanlwanl Aug 27, 2024
47b9473
.
wanlwanl Aug 27, 2024
726552f
Merge branch 'wanl/dev/generate-mlc-in-pipeline' into wanl/generate-m…
wanlwanl Aug 27, 2024
0b47851
WIP
wanlwanl Aug 29, 2024
e895f7b
Test sdk generation path
wanlwanl Aug 29, 2024
3afea1f
Fix original package version restore
wanlwanl Aug 29, 2024
b5dd0f8
Merge branch 'wanl/dev/generate-mlc-in-pipeline' into wanl/generate-m…
wanlwanl Aug 29, 2024
114e7dd
.
wanlwanl Aug 29, 2024
f24fe00
cleanup
wanlwanl Aug 29, 2024
8a3e306
Update version
wanlwanl Aug 29, 2024
1e942bf
Update package.json
wanlwanl Aug 29, 2024
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
751 changes: 674 additions & 77 deletions tools/js-sdk-release-tools/package-lock.json

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions tools/js-sdk-release-tools/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
{
"name": "@azure-tools/js-sdk-release-tools",
"version": "2.7.11",
"version": "2.7.12",
"description": "",
"files": [
"dist"
],
"scripts": {
"dev": "tsx watch src/changelogToolCli.ts",
"start": "node dist/changelogToolCli.js",
"debug": "node --inspect-brk dist/changelogToolCli.js",
"build": "rimraf dist && tsc -p .",
"build": "rimraf dist && tsc -p . && npm run copy-files",
"copy-files": "copyfiles -f src/common/ciYamlTemplates/*.template.yml dist/common/ciYamlTemplates/",
"prepack": "npm run build",
"test": "vitest --run",
"test:watch": "vitest"
Expand All @@ -22,17 +26,18 @@
"license": "MIT",
"dependencies": {
"@azure-tools/openapi-tools-common": "^1.2.2",
"@npmcli/package-json": "^5.2.0",
"@ts-common/azure-js-dev-tools": "^21.1.0",
"colors": "1.4.0",
"command-line-args": "^5.1.1",
"comment-json": "^4.1.0",
"copyfiles": "^2.4.1",
"fs-extra": "^11.2.0",
"glob": "^11.0.0",
"js-yaml": "^4.1.0",
"parse-ts-to-ast": "^0.1.1",
"semver": "^7.3.5",
"shelljs": "^0.8.4",
"shx": "^0.3.4",
"simple-git": "^3.5.0",
"ts-morph": "^23.0.0",
"tslib": "^1.9.3",
Expand All @@ -42,7 +47,9 @@
"yaml": "^1.10.2"
},
"devDependencies": {
"@types/fs-extra": "^11.0.4",
"@types/node": "^20.12.12",
"@types/npmcli__package-json": "^4.0.4",
"@types/shelljs": "^0.8.15",
"@types/unixify": "^1.0.2",
"rimraf": "^3.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ async function detectBreakingChangesCore(projectContext: ProjectContext): Promis
);
return breakingChangeResults;
} catch (err) {
logger.error(`Failed to detect breaking changes due to ${(err as Error).stack ?? err}`);
logger.error(`Failed to detect breaking changes due to ${(err as Error)?.stack ?? err}`);
return undefined;
}
}
Expand Down
167 changes: 97 additions & 70 deletions tools/js-sdk-release-tools/src/autoGenerateInPipeline.ts
Original file line number Diff line number Diff line change
@@ -1,88 +1,112 @@
#!/usr/bin/env node

import * as path from 'path';
import { generateMgmt } from "./hlc/generateMgmt";
import { generateMgmt } from './hlc/generateMgmt';
import { backupNodeModules, restoreNodeModules } from './utils/backupNodeModules';
import { logger } from "./utils/logger";
import { generateRLCInPipeline } from "./llc/generateRLCInPipeline/generateRLCInPipeline";
import { RunningEnvironment } from "./utils/runningEnvironment";
import { logger } from './utils/logger';
import { generateRLCInPipeline } from './llc/generateRLCInPipeline/generateRLCInPipeline';
import { ModularClientPackageOptions, SDKType } from './common/types';
import { generateAzureSDKPackage } from './mlc/clientGenerator/modularClientPackageGenerator';
import { parseInputJson } from './utils/generateInputUtils';

const shell = require('shelljs');
const fs = require('fs');

async function automationGenerateInPipeline(inputJsonPath: string, outputJsonPath: string, use: string | undefined, typespecEmitter: string | undefined, sdkGenerationType: string | undefined) {
async function automationGenerateInPipeline(
inputJsonPath: string,
outputJsonPath: string,
use: string | undefined,
typespecEmitter: string | undefined,
sdkGenerationType: string | undefined,
local: boolean
) {
const inputJson = JSON.parse(fs.readFileSync(inputJsonPath, { encoding: 'utf-8' }));
const specFolder: string = inputJson['specFolder'];
const readmeFiles: string[] | string | undefined = inputJson['relatedReadmeMdFiles'] ? inputJson['relatedReadmeMdFiles'] : inputJson['relatedReadmeMdFile'];
const typespecProjectFolder: string[] | string | undefined = inputJson['relatedTypeSpecProjectFolder'];
const gitCommitId: string = inputJson['headSha'];
const repoHttpsUrl: string = inputJson['repoHttpsUrl'];
const autorestConfig: string | undefined = inputJson['autorestConfig'];
const downloadUrlPrefix: string | undefined = inputJson.installInstructionInput?.downloadUrlPrefix;
const skipGeneration: boolean | undefined = inputJson['skipGeneration'];
const {
sdkType,
specFolder,
readmeMd,
gitCommitId,
outputJson,
repoHttpsUrl,
downloadUrlPrefix,
skipGeneration,
runningEnvironment,
typespecProject,
autorestConfig
} = await parseInputJson(inputJson);

if (!readmeFiles && !typespecProjectFolder) {
throw new Error(`readme files and typespec project info are both undefined`);
}

if (readmeFiles && (typeof readmeFiles !== 'string') && readmeFiles.length !== 1) {
throw new Error(`get ${readmeFiles.length} readme files`);
}

if (typespecProjectFolder && (typeof typespecProjectFolder !== 'string') && typespecProjectFolder.length !== 1) {
throw new Error(`get ${typespecProjectFolder.length} typespec project`);
}

const isTypeSpecProject = !!typespecProjectFolder;

const packages: any[] = [];
const outputJson = {
packages: packages
};
const readmeMd = isTypeSpecProject ? undefined : typeof readmeFiles === 'string' ? readmeFiles : readmeFiles![0];
const typespecProject = isTypeSpecProject ? typeof typespecProjectFolder === 'string' ? typespecProjectFolder : typespecProjectFolder![0] : undefined;
const isMgmt = isTypeSpecProject ? false : readmeMd!.includes('resource-manager');
const runningEnvironment = typeof readmeFiles === 'string' || typeof typespecProjectFolder === 'string' ? RunningEnvironment.SdkGeneration : RunningEnvironment.SwaggerSdkAutomation;
try {
await backupNodeModules(String(shell.pwd()));
if (isMgmt) {
await generateMgmt({
sdkRepo: String(shell.pwd()),
swaggerRepo: specFolder,
readmeMd: readmeMd!,
gitCommitId: gitCommitId,
use: use,
outputJson: outputJson,
swaggerRepoUrl: repoHttpsUrl,
downloadUrlPrefix: downloadUrlPrefix,
skipGeneration: skipGeneration,
runningEnvironment: runningEnvironment
});
} else {
await generateRLCInPipeline({
sdkRepo: String(shell.pwd()),
swaggerRepo: path.isAbsolute(specFolder) ? specFolder : path.join(String(shell.pwd()), specFolder),
readmeMd: readmeMd,
typespecProject: typespecProject,
autorestConfig,
use: use,
typespecEmitter: !!typespecEmitter ? typespecEmitter : `@azure-tools/typespec-ts`,
outputJson: outputJson,
skipGeneration: skipGeneration,
sdkGenerationType: (sdkGenerationType === "command") ? "command" : "script",
runningEnvironment: runningEnvironment,
swaggerRepoUrl: repoHttpsUrl,
gitCommitId: gitCommitId,
})
if (!local) {
await backupNodeModules(String(shell.pwd()));
}
switch (sdkType) {
case SDKType.HighLevelClient:
await generateMgmt({
sdkRepo: String(shell.pwd()),
swaggerRepo: specFolder,
readmeMd: readmeMd!,
gitCommitId: gitCommitId,
use: use,
outputJson: outputJson,
swaggerRepoUrl: repoHttpsUrl,
downloadUrlPrefix: downloadUrlPrefix,
skipGeneration: skipGeneration,
runningEnvironment: runningEnvironment
});
break;
case SDKType.RestLevelClient:
await generateRLCInPipeline({
sdkRepo: String(shell.pwd()),
swaggerRepo: path.isAbsolute(specFolder) ? specFolder : path.join(String(shell.pwd()), specFolder),
readmeMd: readmeMd,
typespecProject: typespecProject,
autorestConfig,
use: use,
typespecEmitter: !!typespecEmitter ? typespecEmitter : `@azure-tools/typespec-ts`,
outputJson: outputJson,
skipGeneration: skipGeneration,
sdkGenerationType: sdkGenerationType === 'command' ? 'command' : 'script',
runningEnvironment: runningEnvironment,
swaggerRepoUrl: repoHttpsUrl,
gitCommitId: gitCommitId
});
break;

case SDKType.ModularClient: {
const typeSpecDirectory = path.posix.join(specFolder, typespecProject!);
const sdkRepoRoot = String(shell.pwd());
const skip = skipGeneration ?? false;
const repoUrl = repoHttpsUrl;
const options: ModularClientPackageOptions = {
sdkRepoRoot,
specRepoRoot: specFolder,
typeSpecDirectory,
gitCommitId,
skip,
repoUrl,
local,
// support MPG for now
versionPolicyName: 'management'
};
const packageResult = await generateAzureSDKPackage(options);
outputJson.packages = [packageResult];
break;
}
default:
break;
}
} catch (e) {
const packageName = outputJson.packages?.[0].packageName;
logger.error(`Failed to generate SDK for package ${"'" + packageName + "'" ?? ''} due to ${(e as Error)?.stack ?? e}.`);
const packageNameStr = `'${outputJson.packages?.[0]?.packageName}' `;
logger.error(`Failed to generate SDK for package ${packageNameStr ?? ''}due to ${(e as Error)?.stack ?? e}.`);
logger.error(`Please review the detail errors for potential fixes.`);
logger.error(`If the issue persists, contact the support channel at https://aka.ms/azsdk/js-teams-channel and include this spec pull request.`)
logger.error(
`If the issue persists, contact the support channel at https://aka.ms/azsdk/js-teams-channel and include this spec pull request.`
);
throw e;
} finally {
await restoreNodeModules(String(shell.pwd()));
if (!local) {
await restoreNodeModules(String(shell.pwd()));
}
fs.writeFileSync(outputJsonPath, JSON.stringify(outputJson, null, ' '), { encoding: 'utf-8' });
}
}
Expand All @@ -93,10 +117,13 @@ const optionDefinitions = [
{ name: 'sdkGenerationType', type: String },
{ name: 'inputJsonPath', type: String },
{ name: 'outputJsonPath', type: String },
// this option should be only used in local run, it will skip backup node modules, etc.
// do NOT set to true in sdk automation pipeline
{ name: 'local', type: Boolean, defaultValue: false }
];
const commandLineArgs = require('command-line-args');
const options = commandLineArgs(optionDefinitions);
automationGenerateInPipeline(options.inputJsonPath, options.outputJsonPath, options.use, options.typespecEmitter, options.sdkGenerationType).catch(e => {
automationGenerateInPipeline(options.inputJsonPath, options.outputJsonPath, options.use, options.typespecEmitter, options.sdkGenerationType, options.local ?? false).catch(e => {
logger.error(e.message);
process.exit(1);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file.

trigger:
branches:
include:
- main
- feature/*
- release/*
- hotfix/*
exclude:
- feature/v4
paths:
include: null

pr:
branches:
include:
- main
- feature/*
- release/*
- hotfix/*
exclude:
- feature/v4
paths:
include: null

extends:
template: /eng/pipelines/templates/stages/archetype-sdk-client.yml
parameters:
ServiceDirectory: null
Artifacts:
- name: null
safeName: null
Loading