Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
4 changes: 2 additions & 2 deletions tools/js-sdk-release-tools/src/autoGenerateInPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ async function automationGenerateInPipeline(inputJsonPath: string, outputJsonPat
}
} catch (e) {
const packageName = outputJson.packages?.[0].packageName;
logger.error(`Failed to generated sdk for package ${packageName ?? ''} due to error: ${(e as Error)?.stack ?? e}`);
logger.error(`If the issue persists, contact the DotNet language support channel at "Language – JS & TS 🥷 - Azure SDK <[email protected]>" and include this spec pull request.`)
logger.error(`Failed to generate SDK for package ${"'" + packageName + "'" ?? ''} due to error: ${(e as Error)?.stack ?? e}.`);
logger.error(`If the issue persists, contact the support channel at "Language – JS & TS 🥷 - Azure SDK <[email protected]>" and include this spec pull request.`)
throw e;
} finally {
await restoreNodeModules(String(shell.pwd()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ const findOperationSignatureChange = (metaDataOld: TSExportedMetaData, metaDataN
const newOpNames = operationGroupFromNew.methods.map(m => m.name);
const newOpNameSet = new Set<string>(newOpNames);
const unchangeOperationNames = oldOpNames.filter(opName => newOpNameSet.has(opName)).map(opName => opName);
logger.warn(`${unchangeOperationNames} operation names aren't changed, but signature may change, please check manually.`);
logger.warn(`'${unchangeOperationNames}' operation names aren't changed, but signature may change, please check manually.`);
return;
}

Expand All @@ -519,7 +519,7 @@ const findOperationSignatureChange = (metaDataOld: TSExportedMetaData, metaDataN
const newOpNames = operationGroupFromNew.properties.map(m => m.name);
const newOpNameSet = new Set<string>(newOpNames);
const unchangeOperationNames = oldOpNames.filter(opName => newOpNameSet.has(opName)).map(opName => opName);
logger.warn(`${unchangeOperationNames} operation names aren't changed, but signature may change, please check manually.`);
logger.warn(`'${unchangeOperationNames}' operation names aren't changed, but signature may change, please check manually.`);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const extractExportAndGenerateChangelog = async (mdFilePathOld: string, m
const metaDataOld = await readSourceAndExtractMetaData(mdFilePathOld);
const metaDataNew = await readSourceAndExtractMetaData(mdFilePathNew);
const changeLog = changelogGenerator(metaDataOld, metaDataNew, oldSdkType, newSdkType);
logger.info('Generated changelog successfully:');
logger.info(changeLog.displayChangeLog());
return changeLog;
};
2 changes: 1 addition & 1 deletion tools/js-sdk-release-tools/src/changelogToolCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {logger} from "./utils/logger";

const changelogToolCli = async (packageFolderPath: string | undefined) => {
if (!packageFolderPath) {
logger.error(`invalid package path ${packageFolderPath}`);
logger.error(`Invalid package path '${packageFolderPath}'.`);
} else {
await generateChangelogAndBumpVersion(packageFolderPath);
}
Expand Down
22 changes: 11 additions & 11 deletions tools/js-sdk-release-tools/src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { spawn, SpawnOptions } from 'child_process';

function printErrorDetails(output: { stdout: string; stderr: string, code: number | null } | undefined) {
if (!output) return;
logger.error(`Error summary:`);
logger.error(`Summary:`);
const printErrorSummary = (content: string) => content.split('\n')
.filter(line => line.includes('error') || line.includes('ERROR'))
.forEach(line => logger.error(line));
printErrorSummary(output.stderr);
printErrorSummary(output.stdout);
logger.error(`Error details:`);
logger.error(`Details:`);
logger.error(output.stderr);
logger.error(output.stdout);
}
Expand All @@ -29,7 +29,7 @@ export function getSDKType(packageRoot: string): SDKType {
const paraPath = getClassicClientParametersPath(packageRoot);
const exist = shell.test('-e', paraPath);
const type = exist ? SDKType.HighLevelClient : SDKType.ModularClient;
logger.info(`SDK type: ${type} detected in ${packageRoot}`);
logger.info(`SDK type '${type}' is detected in '${packageRoot}'.`);
return type;
}

Expand Down Expand Up @@ -78,13 +78,13 @@ export function tryReadNpmPackageChangelog(packageFolderPath: string): string {
const changelogPath = path.join(packageFolderPath, 'changelog-temp', 'package', 'CHANGELOG.md');
try {
if (!fs.existsSync(changelogPath)) {
logger.warn(`NPM package's changelog "${changelogPath}" does not exists`);
logger.warn(`NPM package's changelog '${changelogPath}' does not exist.`);
return "";
}
const originalChangeLogContent = fs.readFileSync(changelogPath, { encoding: 'utf-8' });
return originalChangeLogContent;
} catch (err) {
logger.warn(`Failed to read NPM package's changelog "${changelogPath}": ${(err as Error)?.stack ?? err}`);
logger.warn(`Failed to read NPM package's changelog '${changelogPath}': ${(err as Error)?.stack ?? err}`);
return '';
}
}
Expand All @@ -100,7 +100,7 @@ export function runCommand(
let stdout = '';
let stderr = '';
const commandStr = `${command} ${args.join(' ')}`;
logger.info(`Run command: ${commandStr}`);
logger.info(`Start to run command: '${commandStr}'.`);
const child = spawn(command, args, options);

let timedOut = false;
Expand All @@ -126,27 +126,27 @@ export function runCommand(
if (code === 0) {
resolve({ stdout, stderr, code });
} else {
logger.error(`Run command closed with code ${code}`);
logger.error(`Command closed with code '${code}'.`);
printErrorDetails({ stdout, stderr, code });
reject(new Error(`Run command closed with code ${code}`));
reject(new Error(`Command closed with code '${code}'.`));
}
});

child.on('exit', (code, signal) => {
if (timer) clearTimeout(timer);
if (!timedOut) {
if (signal || code && code !== 0) {
logger.error(`Command "${commandStr}" exited with signal: ${signal ?? 'SIGTERM'} and code: ${code}`);
logger.error(`Command '${commandStr}' exited with signal '${signal ?? 'SIGTERM'}' and code ${code}.`);
printErrorDetails({ stdout, stderr, code });
reject(new Error(`Process was killed with signal: ${signal ?? 'SIGTERM'}`));
reject(new Error(`Process was killed with signal '${signal ?? 'SIGTERM'}'.`));
} else {
resolve({ stdout, stderr, code });
}
}
});

child.on('error', (err) => {
logger.error(`Received command error: ${(err as Error)?.stack ?? err}`);
logger.error((err as Error)?.stack ?? err);
printErrorDetails({ stdout, stderr, code: null });
reject(err);
});
Expand Down
27 changes: 11 additions & 16 deletions tools/js-sdk-release-tools/src/hlc/generateMgmt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function generateMgmt(options: {
skipGeneration?: boolean,
runningEnvironment?: RunningEnvironment;
}) {
logger.info(`>>>>>>>>>>>>>>>>>>> Start: "${options.readmeMd}" >>>>>>>>>>>>>>>>>>>>>>>>>`);
logger.info(`Start to generate SDK from '${options.readmeMd}'.`);
let cmd = '';
if (!options.skipGeneration) {
cmd = `autorest --version=3.9.7 --typescript --modelerfour.lenient-model-deduplication --azure-arm --head-as-boolean=true --license-header=MICROSOFT_MIT_NO_VERSION --generate-test --typescript-sdks-folder=${options.sdkRepo} ${path.join(options.swaggerRepo, options.readmeMd)}`;
Expand All @@ -46,14 +46,11 @@ export async function generateMgmt(options: {
cmd += ` ${options.additionalArgs}`;
}

logger.info('Executing command:');
logger.info('------------------------------------------------------------');
logger.info(cmd);
logger.info('------------------------------------------------------------');
logger.info(`Start to execute command '${cmd}'`);
try {
execSync(cmd, {stdio: 'inherit'});
} catch (e: any) {
throw new Error(`An error occurred while generating codes for readme file: "${options.readmeMd}":\nErr: ${e}\nStderr: "${e.stderr}"\nStdout: "${e.stdout}"\nErrorStack: "${e.stack}"`);
throw new Error(`Failed to generate codes for readme file: "${options.readmeMd}":\nErr: ${e}\nStderr: "${e.stderr}"\nStdout: "${e.stdout}"\nErrorStack: "${e.stack}"`);
}
}

Expand All @@ -63,7 +60,7 @@ export async function generateMgmt(options: {
let outputPackageInfo = getOutputPackageInfo(options.runningEnvironment, options.readmeMd, undefined);

try {
logger.info(`Installing dependencies for ${changedPackageDirectory}...`);
logger.info(`Start to install dependencies for ${changedPackageDirectory}.`);
const packageJson = JSON.parse(fs.readFileSync(path.join(packagePath, 'package.json'), {encoding: 'utf-8'}));
const packageName = packageJson.name;

Expand Down Expand Up @@ -105,16 +102,16 @@ export async function generateMgmt(options: {
}
}

logger.info(`rush update`);
execSync('rush update', {stdio: 'inherit'});
logger.info(`rush build -t ${packageName}: Build generated codes, except test and sample, which may be written manually`);
logger.info(`Start to run command: 'rush update'.`);
execSync('rush update', {stdio: 'ignore'});
logger.info(`Start to run command: 'rush build -t ${packageName}', that builds generated codes, except test and sample, which may be written manually.`);
execSync(`rush build -t ${packageName}`, {stdio: 'inherit'});
logger.info('Generating Changelog and Bumping Version...');
logger.info('Start to generate changelog and bump version...');
let changelog: Changelog | undefined;
if (!options.skipGeneration) {
changelog = await generateChangelogAndBumpVersion(changedPackageDirectory);
}
logger.info(`node common/scripts/install-run-rush.js pack --to ${packageJson.name} --verbose`);
logger.info(`Start to run command: 'node common/scripts/install-run-rush.js pack --to ${packageJson.name} --verbose'.`);
execSync(`node common/scripts/install-run-rush.js pack --to ${packageJson.name} --verbose`, {stdio: 'inherit'});
if (!options.skipGeneration) {
changeReadmeMd(packagePath);
Expand Down Expand Up @@ -155,8 +152,7 @@ export async function generateMgmt(options: {
}
}
} catch (e: any) {
logger.error('Error:');
logger.error(`An error occurred while run build for readme file: "${options.readmeMd}":\nErr: ${e}\nStderr: "${e.stderr}"\nStdout: "${e.stdout}"\nErrorStack: "${e.stack}"`);
logger.error(`Failed to build for readme file '${options.readmeMd}'.\nErr: ${e}\nStderr: "${e.stderr}"\nStdout: "${e.stdout}"\nErrorStack: "${e.stack}"`);
if (outputPackageInfo) {
outputPackageInfo.result = 'failed';
}
Expand All @@ -169,6 +165,5 @@ export async function generateMgmt(options: {
}
}
}

logger.info(`>>>>>>>>>>>>>>>>>>> End: "${options.readmeMd}" >>>>>>>>>>>>>>>>>>>>>>>>>\n`);
logger.info(`Generate SDK from '${options.readmeMd}' successfully.`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ export async function generateChangelogAndBumpVersion(packageFolderPath: string)
const nextVersion = getVersion(npmViewResult, "next");

if (npmViewResult.exitCode !== 0 || (!!stableVersion && isBetaVersion(stableVersion) && isStableRelease)) {
logger.info(`Package ${packageName} is first${npmViewResult.exitCode !== 0? ' ': ' stable'} release, generating changelogs and setting version for first${npmViewResult.exitCode !== 0? ' ': ' stable'} release...`);
logger.info(`Package ${packageName} is first ${npmViewResult.exitCode !== 0? ' ': ' stable'} release, start to generate changelogs and set version for first ${npmViewResult.exitCode !== 0? ' ': ' stable'} release.`);
makeChangesForFirstRelease(packageFolderPath, isStableRelease);
logger.info(`Generate changelogs and setting version for first${npmViewResult.exitCode !== 0? ' ': ' stable'} release successfully`);
logger.info(`Generated changelogs and setting version for first${npmViewResult.exitCode !== 0? ' ': ' stable'} release successfully`);
} else {
if (!stableVersion) {
logger.error(`Invalid latest version ${stableVersion}`);
process.exit(1);
}
logger.info(`Package ${packageName} has been released before, checking whether previous release is track2 sdk...`)
logger.info(`Package ${packageName} has been released before, start to check whether previous release is track2 sdk.`)
const usedVersions = npmViewResult['versions'];
// in our rule, we always compare to stableVersion. But here wo should pay attention to the some stableVersion which contains beta, which means the package has not been GA.
try {
Expand All @@ -58,8 +58,8 @@ export async function generateChangelogAndBumpVersion(packageFolderPath: string)
// only track2 sdk includes sdk-type with value mgmt
const sdkType = JSON.parse(fs.readFileSync(path.join(packageFolderPath, 'changelog-temp', 'package', 'package.json'), {encoding: 'utf-8'}))['sdk-type'];
if (sdkType && sdkType === 'mgmt') {
logger.info(`Package ${packageName} released before is track2 sdk`);
logger.info('Generating changelog by comparing api.md...');
logger.info(`Package ${packageName} released before is track2 sdk.`);
logger.info('Start to generate changelog by comparing api.md.');
const npmPackageRoot = path.join(packageFolderPath, 'changelog-temp', 'package');
const apiMdFileNPM = getApiReviewPath(npmPackageRoot);
const apiMdFileLocal = getApiReviewPath(packageFolderPath);
Expand All @@ -75,23 +75,22 @@ export async function generateChangelogAndBumpVersion(packageFolderPath: string)
const files = shell.ls('*.tgz');
shell.exec(`tar -xzf ${files[0]}`);
shell.cd(packageFolderPath);
logger.info("Create next folder successfully")
logger.info("Created next folder successfully.")

const latestDate = getversionDate(npmViewResult, stableVersion);
const nextDate = getversionDate(npmViewResult,nextVersion);
if (latestDate && nextDate && latestDate <= nextDate){
originalChangeLogContent = tryReadNpmPackageChangelog(packageFolderPath);
logger.info('Need to keep previous preview changelog');

logger.info('Keep previous preview changelog.');
}
}
if(originalChangeLogContent.includes("https://aka.ms/js-track2-quickstart")){
originalChangeLogContent=originalChangeLogContent.replace("https://aka.ms/js-track2-quickstart","https://aka.ms/azsdk/js/mgmt/quickstart");
}
originalChangeLogContent = fixChangelogFormat(originalChangeLogContent);
if (!changelog.hasBreakingChange && !changelog.hasFeature) {
logger.error('Cannot generate changelog because the codes of local and npm may be the same.');
logger.info('Try to bump a fix version');
logger.error('Failed to generate changelog because the codes of local and npm may be the same.');
logger.info('Start to bump a fix version.');
const oriPackageJson = execSync(`git show HEAD:${path.relative(jsSdkRepoPath, path.join(packageFolderPath, 'package.json')).replace(/\\/g, '/')}`, {encoding: 'utf-8'});
const oriVersion = JSON.parse(oriPackageJson).version;
const oriVersionReleased = !usedVersions? false : usedVersions.includes(oriVersion);
Expand All @@ -103,15 +102,15 @@ export async function generateChangelogAndBumpVersion(packageFolderPath: string)
} else {
const newVersion = getNewVersion(stableVersion, usedVersions, changelog.hasBreakingChange, isStableRelease);
makeChangesForReleasingTrack2(packageFolderPath, newVersion, changelog, originalChangeLogContent,stableVersion);
logger.info('Generate changelogs and setting version for track2 release successfully');
logger.info('Generated changelogs and set version for track2 release successfully.');
return changelog;
}
} else {
logger.info(`Package ${packageName} released before is track1 sdk`);
logger.info('Generating changelog of migrating track1 to track2 sdk...');
logger.info(`Package ${packageName} released before is track1 sdk.`);
logger.info('Start to generate changelog of migrating track1 to track2 sdk.');
const newVersion = getNewVersion(stableVersion, usedVersions, true, isStableRelease);
makeChangesForMigrateTrack1ToTrack2(packageFolderPath, newVersion);
logger.info('Generate changelogs and setting version for migrating track1 to track2 successfully');
logger.info('Generated changelogs and setting version for migrating track1 to track2 successfully.');
}
} finally {
shell.rm('-r', `${path.join(packageFolderPath, 'changelog-temp')}`);
Expand Down
2 changes: 1 addition & 1 deletion tools/js-sdk-release-tools/src/hlcCodeGenCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const shell = require('shelljs');
async function automationGenerateInTerminal(absoluteReadmeMd: string, tag?: string, use?: string, additionalArgs?: string) {
const regexResult = /^(.*[\/\\]azure-rest-api-specs[-pr]*)[\/\\](specification.*)/.exec(absoluteReadmeMd);
if (!regexResult || regexResult.length !== 3) {
logger.error(`Cannot Parse readme file path: ${absoluteReadmeMd}`);
logger.error(`Failed to parse README file path: '${absoluteReadmeMd}'.`);
} else {
const gitCommitId = await getLastCommitId(regexResult[1]);
await generateMgmt({
Expand Down
Loading