Skip to content

Commit

Permalink
Update update changelog (#13079)
Browse files Browse the repository at this point in the history
* Add function for retrieving existing versions of packages

* Add SetPackageVersion function

* Update versioning tools

* Add GetPackageInstallNotes function

* Remove changes not related to changelog
  • Loading branch information
chidozieononiwu authored Jan 7, 2021
1 parent 468d73b commit 8c30af4
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 28 deletions.
16 changes: 14 additions & 2 deletions eng/scripts/Language-Settings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,13 @@ function Find-javascript-Artifacts-For-Apireview($artifactDir, $packageName = ""
$pkgName = $pattern.replace($packageName, "", 1)
$packageDir = Join-Path $artifactDir $pkgName "temp"
Write-Host "Searching for *.api.json in path $($packageDir)"
$files = Get-ChildItem "${packageDir}" | Where-Object -FilterScript {$_.Name.EndsWith(".api.json")}
$files = Get-ChildItem "${packageDir}" | Where-Object -FilterScript { $_.Name.EndsWith(".api.json") }
if (!$files)
{
Write-Host "$($packageDir) does not have api review json for package"
return $null
}
elseif($files.Count -ne 1)
elseif ($files.Count -ne 1)
{
Write-Host "$($packageDir) should contain only one api review for $($packageName)"
Write-Host "No of Packages $($files.Count)"
Expand All @@ -228,3 +228,15 @@ function Find-javascript-Artifacts-For-Apireview($artifactDir, $packageName = ""
}
return $packages
}

function SetPackageVersion ($PackageName, $Version, $ServiceDirectory = $null, $ReleaseDate, $BuildType = $null, $GroupId = $null)
{
if ($null -eq $ReleaseDate)
{
$ReleaseDate = Get-Date -Format "yyyy-MM-dd"
}
Push-Location "$EngDir/tools/versioning"
npm install
node ./set-version.js --artifact-name $PackageName --new-version $Version --release-date $ReleaseDate --repo-root $RepoRoot
Pop-Location
}
30 changes: 21 additions & 9 deletions eng/tools/versioning/VersionUtils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const path = require("path");
const { readFile, writeFile } = require("eng-package-utils");
var spawnSync = require("child_process").spawnSync, child;
var spawnSync = require("child_process").spawnSync,
child;

// This is done to update files which are only periodically generated and
// checked in. Since these files could be generated once between many versions
Expand All @@ -17,10 +18,7 @@ async function updatePackageConstants(packagePath, packageJson, newVersion) {
const fileContents = await readFile(targetPath);

const versionExpression = buildSemverRegex(constantFileSpec.prefix);
const updatedContents = fileContents.replace(
versionExpression,
`$1${newVersion}`
);
const updatedContents = fileContents.replace(versionExpression, `$1${newVersion}`);

if (updatedContents == fileContents) {
continue;
Expand All @@ -34,10 +32,24 @@ function buildSemverRegex(prefix) {
return new RegExp(`(${prefix}.*?)(${semverRegex.toString()})`, "g");
}

function updateChangelog(targetPackagePath, repoRoot, newVersion, unreleased, replaceVersion) {
const changelogLocation = path.join(targetPackagePath, "CHANGELOG.md");
const updateChangelogPath = path.resolve(path.join(repoRoot, "eng/common/Update-Change-Log.ps1"));
child = spawnSync("pwsh", [updateChangelogPath, newVersion, changelogLocation, unreleased, replaceVersion]);
function updateChangelog(
targetPackagePath,
packageName,
repoRoot,
newVersion,
unreleased,
replaceVersion,
releaseDate = null
) {
const service = path.basename(path.dirname(targetPackagePath));
const updateChangelogPath = path.resolve(
path.join(repoRoot, "eng/common/scripts/Update-ChangeLog.ps1")
);
let args = [updateChangelogPath, newVersion, service, packageName, unreleased, replaceVersion];
if (releaseDate != null) {
args.push(releaseDate);
}
child = spawnSync("pwsh", args);
console.log("Powershell Data: " + child.stdout);
console.log("Powershell Errors: " + child.stderr);

Expand Down
17 changes: 9 additions & 8 deletions eng/tools/versioning/increment.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@ async function main(argv) {

const rushSpec = await packageUtils.getRushSpec(repoRoot);
const targetPackage = rushSpec.projects.find(
packageSpec => packageSpec.packageName.replace("@", "").replace("/", "-") == artifactName
(packageSpec) => packageSpec.packageName.replace("@", "").replace("/", "-") == artifactName
);

const targetPackagePath = path.join(repoRoot, targetPackage.projectFolder);
const packageJsonLocation = path.join(targetPackagePath, "package.json");

const packageJsonContents = await packageUtils.readFileJson(
packageJsonLocation
);
const packageJsonContents = await packageUtils.readFileJson(packageJsonLocation);

const oldVersion = packageJsonContents.version;
const newVersion = incrementVersion(packageJsonContents.version);
Expand All @@ -64,12 +62,15 @@ async function main(argv) {
};
await packageUtils.writePackageJson(packageJsonLocation, updatedPackageJson);

await versionUtils.updatePackageConstants(
await versionUtils.updatePackageConstants(targetPackagePath, packageJsonContents, newVersion);
const updateStatus = versionUtils.updateChangelog(
targetPackagePath,
packageJsonContents,
newVersion
artifactName,
repoRoot,
newVersion,
true,
false
);
const updateStatus = versionUtils.updateChangelog(targetPackagePath, repoRoot, newVersion, true, false);
if (!updateStatus) {
process.exit(1);
}
Expand Down
27 changes: 18 additions & 9 deletions eng/tools/versioning/set-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ let argv = require("yargs")
describe: "package version string",
demandOption: true
},
"release-date": {
type: "string",
default: new Date().toISOString().slice(0, 10),
describe: "the date of intended release",
demandOption: false
},
"repo-root": {
type: "string",
default: "../../../",
Expand All @@ -30,21 +36,20 @@ const packageUtils = require("eng-package-utils");
async function main(argv) {
const artifactName = argv["artifact-name"];
const newVersion = argv["new-version"];
const releaseDate = argv["release-date"];
const repoRoot = argv["repo-root"];
const dryRun = argv["dry-run"];

const rushSpec = await packageUtils.getRushSpec(repoRoot);

const targetPackage = rushSpec.projects.find(
packageSpec => packageSpec.packageName.replace("@", "").replace("/", "-") == artifactName
(packageSpec) => packageSpec.packageName.replace("@", "").replace("/", "-") == artifactName
);

const targetPackagePath = path.join(repoRoot, targetPackage.projectFolder);
const packageJsonLocation = path.join(targetPackagePath, "package.json");

const packageJsonContents = await packageUtils.readFileJson(
packageJsonLocation
);
const packageJsonContents = await packageUtils.readFileJson(packageJsonLocation);

const oldVersion = packageJsonContents.version;
console.log(`${packageJsonContents.name}: ${oldVersion} -> ${newVersion}`);
Expand All @@ -60,13 +65,17 @@ async function main(argv) {
};
await packageUtils.writePackageJson(packageJsonLocation, updatedPackageJson);

await versionUtils.updatePackageConstants(
await versionUtils.updatePackageConstants(targetPackagePath, packageJsonContents, newVersion);

const updateStatus = versionUtils.updateChangelog(
targetPackagePath,
packageJsonContents,
newVersion
artifactName,
repoRoot,
newVersion,
false,
true,
releaseDate
);

const updateStatus = versionUtils.updateChangelog(targetPackagePath, repoRoot, newVersion, false, true);
if (!updateStatus) {
process.exit(1);
}
Expand Down

0 comments on commit 8c30af4

Please sign in to comment.