Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
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/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tools/js-sdk-release-tools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure-tools/js-sdk-release-tools",
"version": "2.7.6",
"version": "2.7.7",
"description": "",
"scripts": {
"start": "node dist/changelogToolCli.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import {
bumpPreviewVersion,
getLatestStableVersion,
getNewVersion,
getNextVersion,
isBetaVersion
} from "../../utils/version";
import {isGeneratedCodeStable} from "./isGeneratedCodeStable";
import {execSync} from "child_process";
import { compareDate, getLatestversionDate, getNextversionDate } from "../../utils/date";

const fs = require('fs');
const path = require('path');
Expand All @@ -29,6 +31,7 @@ export async function generateChangelogAndBumpVersion(packageFolderPath: string)
const npm = new NPMScope({ executionFolderPath: packageFolderPath });
const npmViewResult: NPMViewResult = await npm.view({ packageName });
const stableVersion = getLatestStableVersion(npmViewResult);
const nextVersion = getNextVersion(npmViewResult);

if (npmViewResult.exitCode !== 0 || (!!stableVersion && isBetaVersion(stableVersion) && isStableRelease)) {
logger.log(`Package ${packageName} is first${npmViewResult.exitCode !== 0? ' ': ' stable'} release, generating changelogs and setting version for first${npmViewResult.exitCode !== 0? ' ': ' stable'} release...`);
Expand All @@ -48,6 +51,7 @@ export async function generateChangelogAndBumpVersion(packageFolderPath: string)
await shell.exec(`npm pack ${packageName}@${stableVersion}`);
await shell.exec('tar -xzf *.tgz');
await shell.cd(packageFolderPath);

// 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') {
Expand All @@ -57,6 +61,26 @@ export async function generateChangelogAndBumpVersion(packageFolderPath: string)
let apiMdFileNPM: string = path.join(reviewFolder, fs.readdirSync(reviewFolder)[0]);
let apiMdFileLocal: string = path.join(packageFolderPath, 'review', fs.readdirSync(path.join(packageFolderPath, 'review'))[0]);
const changelog: Changelog = await extractExportAndGenerateChangelog(apiMdFileNPM, apiMdFileLocal);
let changeLogContent = fs.readFileSync(path.join(packageFolderPath, 'changelog-temp', 'package', 'CHANGELOG.md'), {encoding: 'utf-8'});
if(nextVersion){
await shell.mkdir(path.join(packageFolderPath, 'changelog-next'));
await shell.cd(path.join(packageFolderPath, 'changelog-next'));
await shell.exec(`npm pack ${packageName}@${nextVersion}`);
await shell.exec('tar -xzf *.tgz');
await shell.cd(packageFolderPath);
logger.log("Create next folder successfully")

const getLatestDate = getLatestversionDate(npmViewResult, stableVersion);
const getNextDate = getNextversionDate(npmViewResult,nextVersion);
if (getLatestDate && getNextDate){
if (!compareDate(getLatestDate, getNextDate)){
changeLogContent = fs.readFileSync(path.join(packageFolderPath, 'changelog-next', 'package', 'CHANGELOG.md'), {encoding: 'utf-8'});
}
}
}
if(changeLogContent.includes("https://aka.ms/js-track2-quickstart")){
changeLogContent=changeLogContent.replace("https://aka.ms/js-track2-quickstart","https://aka.ms/azsdk/js/mgmt/quickstart");
}
if (!changelog.hasBreakingChange && !changelog.hasFeature) {
logger.logError('Cannot generate changelog because the codes of local and npm may be the same.');
logger.log('Try to bump a fix version');
Expand All @@ -70,7 +94,7 @@ export async function generateChangelogAndBumpVersion(packageFolderPath: string)
makeChangesForPatchReleasingTrack2(packageFolderPath, newVersion);
} else {
const newVersion = getNewVersion(stableVersion, usedVersions, changelog.hasBreakingChange, isStableRelease);
makeChangesForReleasingTrack2(packageFolderPath, newVersion, changelog);
makeChangesForReleasingTrack2(packageFolderPath, newVersion, changelog, changeLogContent);
logger.log('Generate changelogs and setting version for track2 release successfully');
return changelog;
}
Expand All @@ -83,6 +107,9 @@ export async function generateChangelogAndBumpVersion(packageFolderPath: string)
}
} finally {
await shell.exec(`rm -r ${path.join(packageFolderPath, 'changelog-temp')}`);
if(nextVersion){
await shell.exec(`rm -r ${path.join(packageFolderPath, 'changelog-next')}`);
}
await shell.cd(jsSdkRepoPath);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,8 @@ function changeClientFile(packageFolderPath: string, packageVersion: string) {
})
}

export function makeChangesForReleasingTrack2(packageFolderPath: string, packageVersion: string, changeLog: Changelog) {
let originalChangeLogContent = fs.readFileSync(path.join(packageFolderPath, 'changelog-temp', 'package', 'CHANGELOG.md'), {encoding: 'utf-8'});
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");
}
export function makeChangesForReleasingTrack2(packageFolderPath: string, packageVersion: string, changeLog: Changelog, changeLogContent: string) {
Comment thread
kazrael2119 marked this conversation as resolved.
Outdated
const originalChangeLogContent = changeLogContent;
const modifiedChangelogContent = `# Release History

## ${packageVersion} (${date})
Expand Down
25 changes: 25 additions & 0 deletions tools/js-sdk-release-tools/src/utils/date.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {NPMViewResult, StringMap, tr} from "@ts-common/azure-js-dev-tools";
import {logger} from "./logger";
const semverInc = require('semver/functions/inc')


export function getLatestversionDate(npmViewResult: NPMViewResult, latestVersion : string){
const time: StringMap<string> | undefined = npmViewResult['time'];
const latestVersionDate = time && time[latestVersion];
return latestVersionDate;
}

export function getNextversionDate(npmViewResult: NPMViewResult, nextVersion: string) {
const time: StringMap<string> | undefined = npmViewResult['time'];
const nextVersionDate = time && time[nextVersion];
return nextVersionDate;

}

export function compareDate(latestDate:string, nextDate:string){
if (latestDate >= nextDate) {
return true;
} {
return false;
}
}
6 changes: 6 additions & 0 deletions tools/js-sdk-release-tools/src/utils/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export function getLatestStableVersion(npmViewResult: NPMViewResult) {
return stableVersion;
}

export function getNextVersion(npmViewResult: NPMViewResult) {
const distTags: StringMap<string> | undefined = npmViewResult['dist-tags'];
const nextVersion = distTags && distTags['next'];
return nextVersion;
}

export function isBetaVersion(stableVersion: string) {
return stableVersion.includes('beta');
}
Expand Down