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

Merge [master] to [beta] #1757

Merged
merged 1 commit into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
40 changes: 30 additions & 10 deletions tools/release-tools/setVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function showHelp() {
}

console.log("");
console.log(scriptName + " [<newVersion>|-patch|-minor|-major] [-dev|-alpha|-beta|-release] [-bld ######] [-test]");
console.log(scriptName + " [<newVersion>|-patch|-minor|-major|-next] [-dev|-alpha|-beta|-release] [-bld ######] [-test]");
console.log("--------------------------");
console.log(" <newVersion> - Identifies the version to set for all packages, must start with x.y.z");
console.log(" -patch - Increment the current version to the next patch number (x.y.z => x.y.[z+1]");
Expand Down Expand Up @@ -87,16 +87,25 @@ function parseArgs() {
} else if (!newVer && theArg === "-major") {
console.log("Increment major existing version");
autoInc = "major";
} else if (!newVer && theArg === "-next") {
console.log("Increment existing version based on autoInc");
autoInc = "next";
} else if (!isRelease && !preRel && theArg === "-dev") {
if (!setPreRelVer("dev")) {
return false;
}
} else if (!isRelease && !preRel && theArg === "-alpha") {
if (!setPreRelVer("alpha")) {
preRel = "alpha";
if (!autoInc && !newVer) {
autoInc = "next";
} else if (!setPreRelVer("alpha")) {
return false;
}
} else if (!isRelease && !preRel && theArg === "-beta") {
if (!setPreRelVer("beta")) {
preRel = "beta";
if (!autoInc && !newVer) {
autoInc = "next";
} else if (!setPreRelVer("beta")) {
return false;
}
} else if (!isRelease && !preRel && theArg === "-release") {
Expand Down Expand Up @@ -156,8 +165,10 @@ function parseArgs() {
}

function updateVersions() {
// Get the configured next release, default to "patch"
const verNext = theVersion.next || "patch";
const rootVersion = require(process.cwd() + "/package.json");
let newVersion = calculateVersion(rootVersion.version);
let newVersion = calculateVersion(rootVersion.version, verNext);
if (newVersion) {
console.log("New version [" + theVersion.release + "] => [" + newVersion + "]");
if (updateAll || (!isReact && !isReactNative)) {
Expand All @@ -178,7 +189,8 @@ function updateVersions() {
const orgVersion = thePackage.version;
if (shouldUpdatePackage(value)) {
orgPkgVersions[value] = orgVersion;
packageDef.release = calculateVersion(orgVersion);
let pkgNext = packageDef.next || verNext;
packageDef.release = calculateVersion(orgVersion, pkgNext);
console.log(" - " + value + ":[" + orgVersion + "] => [" + packages[value].release + "]");
} else {
console.log(" - " + value + ":[" + orgVersion + "] => Skipping");
Expand All @@ -205,7 +217,7 @@ function getNewPackageVersion(package, packageFilename) {

// We are not currently tracking this package so calculate based on the current package.version value
if (shouldUpdatePackage(package.name)) {
packageDef.release = calculateVersion(package.version);
packageDef.release = calculateVersion(package.version, theVersion.next);
} else {
packageDef.release = package.version;
}
Expand All @@ -217,7 +229,7 @@ function getNewPackageVersion(package, packageFilename) {
return packages[packageName].release;
}

function calculateVersion(rootVersion) {
function calculateVersion(rootVersion, pkgAutoInc) {

let preRelParts = (rootVersion || "0.0.0").split("-");
let postfix = preRelParts.length > 1 && preRelParts[1] ? ("-" + preRelParts[1]) : "";
Expand All @@ -234,12 +246,16 @@ function calculateVersion(rootVersion) {
newVersion = newVer;
postfix = "";
} else {
if (autoInc == "patch") {
if (autoInc !== "next") {
pkgAutoInc = autoInc;
}

if (pkgAutoInc == "patch") {
parts[2]++;
} else if (autoInc == "minor") {
} else if (pkgAutoInc == "minor") {
parts[1]++;
parts[2] = 0;
} else if (autoInc == "major") {
} else if (pkgAutoInc == "major") {
parts[0]++;
parts[1] = 0;
parts[2] = 0;
Expand Down Expand Up @@ -505,6 +521,10 @@ if (parseArgs()) {

if (!testOnly && changed) {
console.log("Updating version file");
if (autoInc) {
// We did an automatic update so reset to patch for the next one.
theVersion.next = "patch";
}
// Rewrite the file
const newContent = JSON.stringify(theVersion, null, 4) + "\n";
fs.writeFileSync(process.cwd() + "/version.json", newContent);
Expand Down
1 change: 1 addition & 0 deletions version.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"description": "The release value identifies the base version that will be applied via the tools/release-tools/setVersion.js",
"usage": "When creating a new release you should update this value directly or via the eg. 'npm run setVersion -- 3.2.0' or 'npm run setVersion -- -patch' or 'npm run setVersion -- -minor'",
"release": "2.7.3",
"next": "minor",
"pkgs": {
"@microsoft/applicationinsights-web": {
"package": "package.json",
Expand Down