Skip to content

Commit

Permalink
Account for .n alpha/beta versions
Browse files Browse the repository at this point in the history
Allow alpha and beta releases to be numbered, not just release candidates.
  • Loading branch information
danrahn committed Apr 30, 2024
1 parent ea27a10 commit 5f3c94f
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions Client/Script/VersionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,30 +215,28 @@ class Version {
* * A leading 'v' (which is ignored)
* * 0.0.0, where 0 is any number with 1 or more digits
* * An optional postfix, starting with a dash (-), followed by:
* * `alpha`
* * `beta`
* * `rc.0`, where 0 is any number with 1 or more digits */
static #versionRegex = /^v?(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(?:-(?<type>alpha|beta|rc\.(?<rcVersion>\d+)))?/;
* * `alpha.0`, where `.0` is optional and 0 is any number with 1 or more digits
* * `beta`, where `.0` is optional and 0 is any number with 1 or more digits
* * `rc.0`, where `0` is any number with 1 or more digits */
static #versionRegex = /^v?(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(?:-(?<type>alpha|beta|rc)(?:\.(?<rcVersion>\d+))?)?/;

/**
* Compare two `Version`s, ordering from smallest to largest
* @param {Version} versionA
* @param {Version} versionB
* @returns {number} Negative number if A is less than B, 0 if equal, positive of A is greater than B. */
static Compare(versionA, versionB) {
/* eslint-disable padding-line-between-statements */
let diff = versionA.major - versionB.major;
if (diff !== 0) { return diff; }
if (diff !== 0) return diff;
diff = versionA.minor - versionB.minor;
if (diff !== 0) { return diff; }
if (diff !== 0) return diff;
diff = versionA.patch - versionB.patch;
if (diff !== 0) { return diff; }
if (diff !== 0) return diff;
diff = versionA.releaseTypeInfo.type - versionB.releaseTypeInfo.type;
if (diff !== 0) { return diff; }
if (versionA.releaseTypeInfo.type === PrereleaseType.ReleaseCandidate) {
return versionA.releaseTypeInfo.rcVersion - versionB.releaseTypeInfo.rcVersion;
if (diff !== 0) return diff;
if (versionA.releaseTypeInfo.type < PrereleaseType.Released) {
return versionA.releaseTypeInfo.prereleaseVersion - versionB.releaseTypeInfo.prereleaseVersion;
}
/* eslint-enable */

return 0;
}
Expand All @@ -261,7 +259,7 @@ class Version {
/** Prerelease version info, if any */
releaseTypeInfo = {
type : PrereleaseType.Released,
rcVersion : -1,
prereleaseVersion : -1,
};

/**
Expand All @@ -278,8 +276,8 @@ class Version {
this.minor = parseInt(parts.groups.minor);
this.patch = parseInt(parts.groups.patch);
if (parts.groups.type) {
const partLower = parts.groups.type.toLowerCase();
switch (partLower) {
const typeLower = parts.groups.type.toLowerCase();
switch (typeLower) {
case 'alpha':
this.releaseTypeInfo.type = PrereleaseType.Alpha;
break;
Expand All @@ -288,13 +286,20 @@ class Version {
break;
default:
Log.assert(
partLower.startsWith('rc') && parts.groups.rcVersion,
`Version: Expected rc with a valid rc number if not alpha or beta, found ${partLower}.`);
typeLower.startsWith('rc') && parts.groups.rcVersion,
`Version: Expected rc with a valid rc number if not alpha or beta, found ${typeLower}.`);

this.releaseTypeInfo.type = PrereleaseType.ReleaseCandidate;
this.releaseTypeInfo.rcVersion = parseInt(parts.groups.rcVersion);
this.releaseTypeInfo.prereleaseVersion = parseInt(parts.groups.rcVersion);
break;
}

if (parts.groups.rcVersion) {
this.releaseTypeInfo.prereleaseVersion = parseInt(parts.groups.rcVersion);
} else {
Log.assert(typeLower !== 'rc', 'Release candidates should always have a candidate version.');
this.releaseTypeInfo.prereleaseVersion = 0;
}
}
}

Expand Down

0 comments on commit 5f3c94f

Please sign in to comment.