Skip to content

Commit

Permalink
Use rc instead of beta
Browse files Browse the repository at this point in the history
  • Loading branch information
garronej committed Oct 11, 2022
1 parent c9d3057 commit a75bdd3
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 57 deletions.
2 changes: 1 addition & 1 deletion action.yml
Expand Up @@ -77,7 +77,7 @@ outputs:
description: 'Output of is_package_json_version_upgraded, string'
is_upgraded_version:
description: 'Output of is_package_json_version_upgraded, true|false'
is_release_beta:
is_pre_release:
description: 'Output of is_package_json_version_upgraded, true|false'
runs:
using: 'node16'
Expand Down
52 changes: 26 additions & 26 deletions dist/index.js
Expand Up @@ -5420,21 +5420,21 @@ exports.NpmModuleVersion = void 0;
var NpmModuleVersion;
(function (NpmModuleVersion) {
function parse(versionStr) {
const match = versionStr.match(/^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-beta.([0-9]+))?/);
const match = versionStr.match(/^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-rc.([0-9]+))?/);
if (!match) {
throw new Error(`${versionStr} is not a valid NPM version`);
}
return Object.assign({ "major": parseInt(match[1]), "minor": parseInt(match[2]), "patch": parseInt(match[3]) }, (() => {
const str = match[4];
return str === undefined ?
{} :
{ "betaPreRelease": parseInt(str) };
{ "rc": parseInt(str) };
})());
}
NpmModuleVersion.parse = parse;
;
function stringify(v) {
return `${v.major}.${v.minor}.${v.patch}${v.betaPreRelease === undefined ? "" : `-beta.${v.betaPreRelease}`}`;
return `${v.major}.${v.minor}.${v.patch}${v.rc === undefined ? "" : `-rc.${v.rc}`}`;
}
NpmModuleVersion.stringify = stringify;
/**
Expand All @@ -5447,7 +5447,7 @@ var NpmModuleVersion;
function compare(v1, v2) {
const sign = (diff) => diff === 0 ? 0 : (diff < 0 ? -1 : 1);
const noUndefined = (n) => n !== null && n !== void 0 ? n : Infinity;
for (const level of ["major", "minor", "patch", "betaPreRelease"]) {
for (const level of ["major", "minor", "patch", "rc"]) {
if (noUndefined(v1[level]) !== noUndefined(v2[level])) {
return sign(noUndefined(v1[level]) - noUndefined(v2[level]));
}
Expand All @@ -5456,17 +5456,17 @@ var NpmModuleVersion;
}
NpmModuleVersion.compare = compare;
/*
console.log(compare(parse("3.0.0-beta.3"), parse("3.0.0")) === -1 )
console.log(compare(parse("3.0.0-beta.3"), parse("3.0.0-beta.4")) === -1 )
console.log(compare(parse("3.0.0-beta.3"), parse("4.0.0")) === -1 )
console.log(compare(parse("3.0.0-rc.3"), parse("3.0.0")) === -1 )
console.log(compare(parse("3.0.0-rc.3"), parse("3.0.0-rc.4")) === -1 )
console.log(compare(parse("3.0.0-rc.3"), parse("4.0.0")) === -1 )
*/
function bumpType(params) {
const versionAhead = parse(params.versionAheadStr);
const versionBehind = parse(params.versionBehindStr);
if (compare(versionBehind, versionAhead) === 1) {
throw new Error(`Version regression ${versionBehind} -> ${versionAhead}`);
}
for (const level of ["major", "minor", "patch", "betaPreRelease"]) {
for (const level of ["major", "minor", "patch", "rc"]) {
if (versionBehind[level] !== versionAhead[level]) {
return level;
}
Expand Down Expand Up @@ -9673,7 +9673,7 @@ function getLatestSemVersionedTagFactory(params) {
function getLatestSemVersionedTag(params) {
var e_1, _a;
return __awaiter(this, void 0, void 0, function* () {
const { owner, repo, beta, major } = params;
const { owner, repo, rcPolicy, major } = params;
const semVersionedTags = [];
const { listTags } = listTags_1.listTagsFactory({ octokit });
try {
Expand All @@ -9689,17 +9689,17 @@ function getLatestSemVersionedTagFactory(params) {
catch (_d) {
continue;
}
switch (beta) {
case "IGNORE BETA":
if (version.betaPreRelease !== undefined) {
switch (rcPolicy) {
case "IGNORE RC":
if (version.rc !== undefined) {
continue;
}
break;
case "ONLY LOOK FOR BETA":
if (version.betaPreRelease === undefined) {
case "ONLY LOOK FOR RC":
if (version.rc === undefined) {
continue;
}
case "BETA OR REGULAR RELEASE":
case "RC OR REGULAR RELEASE":
break;
}
semVersionedTags.push({ tag, version });
Expand Down Expand Up @@ -11287,7 +11287,7 @@ function action(_actionName, params, core) {
const octokit = createOctokit_1.createOctokit({ github_token });
const { getCommitAhead } = getCommitAhead_1.getCommitAheadFactory({ octokit });
const { getLatestSemVersionedTag } = getLatestSemVersionedTag_1.getLatestSemVersionedTagFactory({ octokit });
const { tag: branchBehind } = (_a = (yield getLatestSemVersionedTag({ owner, repo, "beta": "IGNORE BETA", "major": undefined }))) !== null && _a !== void 0 ? _a : {};
const { tag: branchBehind } = (_a = (yield getLatestSemVersionedTag({ owner, repo, "rcPolicy": "IGNORE RC", "major": undefined }))) !== null && _a !== void 0 ? _a : {};
if (branchBehind === undefined) {
core.warning(`It's the first release, not editing the CHANGELOG.md`);
return;
Expand All @@ -11309,15 +11309,15 @@ function action(_actionName, params, core) {
branch,
"compare_to_version": "0.0.0"
}, core).then(({ version }) => version)));
if (NpmModuleVersion_1.NpmModuleVersion.parse(branchAheadVersion).betaPreRelease !== undefined) {
core.warning(`Version on ${branch} is ${branchAheadVersion} it's a beta release, we do not update the CHANGELOG.md`);
if (NpmModuleVersion_1.NpmModuleVersion.parse(branchAheadVersion).rc !== undefined) {
core.warning(`Version on ${branch} is ${branchAheadVersion} it's a release candidate, we do not update the CHANGELOG.md`);
return;
}
const bumpType = NpmModuleVersion_1.NpmModuleVersion.bumpType({
"versionAheadStr": branchAheadVersion,
"versionBehindStr": branchBehindVersion || "0.0.0"
});
assert_1.assert(bumpType !== "betaPreRelease");
assert_1.assert(bumpType !== "rc");
if (bumpType === "same") {
core.warning(`Version on ${branch} and ${branchBehind} are the same, not editing CHANGELOG.md`);
return;
Expand Down Expand Up @@ -12287,7 +12287,7 @@ exports.outputNames = [
"from_version",
"to_version",
"is_upgraded_version",
"is_release_beta"
"is_pre_release"
];
function getOutputDescription(inputName) {
switch (inputName) {
Expand All @@ -12304,7 +12304,7 @@ function getOutputDescription(inputName) {
case "from_version": return "Output of is_package_json_version_upgraded, string";
case "to_version": return "Output of is_package_json_version_upgraded, string";
case "is_upgraded_version": return "Output of is_package_json_version_upgraded, true|false";
case "is_release_beta": return "Output of is_package_json_version_upgraded, true|false";
case "is_pre_release": return "Output of is_package_json_version_upgraded, true|false";
}
}
exports.getOutputDescription = getOutputDescription;
Expand Down Expand Up @@ -14651,8 +14651,8 @@ function action(_actionName, params, core) {
const getLatestSemVersionedTagParam = {
owner,
repo,
"beta": to_version.betaPreRelease !== undefined ?
"ONLY LOOK FOR BETA" : "IGNORE BETA",
"rcPolicy": to_version.rc !== undefined ?
"ONLY LOOK FOR RC" : "IGNORE RC",
"major": to_version.major
};
let wrap = yield getLatestSemVersionedTag(getLatestSemVersionedTagParam);
Expand All @@ -14668,13 +14668,13 @@ function action(_actionName, params, core) {
core.debug(`Last version was ${NpmModuleVersion_1.NpmModuleVersion.stringify(from_version)}`);
const is_upgraded_version = NpmModuleVersion_1.NpmModuleVersion.compare(to_version, from_version) === 1 ? "true" : "false";
core.debug(`Is version upgraded: ${is_upgraded_version}`);
const is_release_beta = is_upgraded_version === "false" ? "false" : to_version.betaPreRelease !== undefined ? "true" : "false";
core.debug(`Is release beta: ${is_release_beta}`);
const is_pre_release = is_upgraded_version === "false" ? "false" : to_version.rc !== undefined ? "true" : "false";
core.debug(`Is pre release: ${is_pre_release}`);
return {
"to_version": NpmModuleVersion_1.NpmModuleVersion.stringify(to_version),
"from_version": NpmModuleVersion_1.NpmModuleVersion.stringify(from_version),
is_upgraded_version,
is_release_beta
is_pre_release
};
});
}
Expand Down
12 changes: 6 additions & 6 deletions src/is_package_json_version_upgraded.ts
Expand Up @@ -24,7 +24,7 @@ type CoreLike = {
debug: (message: string) => void;
};

export const { setOutput } = setOutputFactory<"from_version" | "to_version" | "is_upgraded_version" | "is_release_beta">();
export const { setOutput } = setOutputFactory<"from_version" | "to_version" | "is_upgraded_version" | "is_pre_release">();

export async function action(
_actionName: "is_package_json_version_upgraded",
Expand Down Expand Up @@ -59,8 +59,8 @@ export async function action(
const getLatestSemVersionedTagParam: Param0<typeof getLatestSemVersionedTag> = {
owner,
repo,
"beta": to_version.betaPreRelease !== undefined ?
"ONLY LOOK FOR BETA" : "IGNORE BETA",
"rcPolicy": to_version.rc !== undefined ?
"ONLY LOOK FOR RC" : "IGNORE RC",
"major": to_version.major
};

Expand Down Expand Up @@ -89,15 +89,15 @@ export async function action(

core.debug(`Is version upgraded: ${is_upgraded_version}`);

const is_release_beta = is_upgraded_version === "false" ? "false" : to_version.betaPreRelease !== undefined ? "true" : "false";
const is_pre_release = is_upgraded_version === "false" ? "false" : to_version.rc !== undefined ? "true" : "false";

core.debug(`Is release beta: ${is_release_beta}`);
core.debug(`Is pre release: ${is_pre_release}`);

return {
"to_version": NpmModuleVersion.stringify(to_version),
"from_version": NpmModuleVersion.stringify(from_version),
is_upgraded_version,
is_release_beta
is_pre_release
};

}
Expand Down
4 changes: 2 additions & 2 deletions src/outputHelper.ts
Expand Up @@ -16,7 +16,7 @@ export const outputNames = [
"from_version",
"to_version",
"is_upgraded_version",
"is_release_beta"
"is_pre_release"
] as const;


Expand All @@ -35,7 +35,7 @@ export function getOutputDescription(inputName: typeof outputNames[number]): str
case "from_version": return "Output of is_package_json_version_upgraded, string";
case "to_version": return "Output of is_package_json_version_upgraded, string";
case "is_upgraded_version": return "Output of is_package_json_version_upgraded, true|false";
case "is_release_beta": return "Output of is_package_json_version_upgraded, true|false";
case "is_pre_release": return "Output of is_package_json_version_upgraded, true|false";
}
}

Expand Down
20 changes: 10 additions & 10 deletions src/tools/NpmModuleVersion.ts
Expand Up @@ -4,14 +4,14 @@ export type NpmModuleVersion = {
major: number;
minor: number;
patch: number;
betaPreRelease?: number;
rc?: number;
};

export namespace NpmModuleVersion {

export function parse(versionStr: string): NpmModuleVersion {

const match = versionStr.match(/^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-beta.([0-9]+))?/);
const match = versionStr.match(/^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-rc.([0-9]+))?/);

if (!match) {
throw new Error(`${versionStr} is not a valid NPM version`);
Expand All @@ -26,15 +26,15 @@ export namespace NpmModuleVersion {
const str = match[4];
return str === undefined ?
{} :
{ "betaPreRelease": parseInt(str) };
{ "rc": parseInt(str) };

})()
};

};

export function stringify(v: NpmModuleVersion) {
return `${v.major}.${v.minor}.${v.patch}${v.betaPreRelease === undefined ? "" : `-beta.${v.betaPreRelease}`}`;
return `${v.major}.${v.minor}.${v.patch}${v.rc === undefined ? "" : `-rc.${v.rc}`}`;
}

/**
Expand All @@ -49,7 +49,7 @@ export namespace NpmModuleVersion {
const sign = (diff: number): -1 | 0 | 1 => diff === 0 ? 0 : (diff < 0 ? -1 : 1);
const noUndefined= (n: number | undefined)=> n ?? Infinity;

for (const level of ["major", "minor", "patch", "betaPreRelease"] as const) {
for (const level of ["major", "minor", "patch", "rc"] as const) {
if (noUndefined(v1[level]) !== noUndefined(v2[level])) {
return sign(noUndefined(v1[level]) - noUndefined(v2[level]));
}
Expand All @@ -60,17 +60,17 @@ export namespace NpmModuleVersion {
}

/*
console.log(compare(parse("3.0.0-beta.3"), parse("3.0.0")) === -1 )
console.log(compare(parse("3.0.0-beta.3"), parse("3.0.0-beta.4")) === -1 )
console.log(compare(parse("3.0.0-beta.3"), parse("4.0.0")) === -1 )
console.log(compare(parse("3.0.0-rc.3"), parse("3.0.0")) === -1 )
console.log(compare(parse("3.0.0-rc.3"), parse("3.0.0-rc.4")) === -1 )
console.log(compare(parse("3.0.0-rc.3"), parse("4.0.0")) === -1 )
*/

export function bumpType(
params: {
versionBehindStr: string;
versionAheadStr: string;
}
): "major" | "minor" | "patch" | "betaPreRelease" | "same" {
): "major" | "minor" | "patch" | "rc" | "same" {


const versionAhead = parse(params.versionAheadStr);
Expand All @@ -80,7 +80,7 @@ export namespace NpmModuleVersion {
throw new Error(`Version regression ${versionBehind} -> ${versionAhead}`);
}

for (const level of ["major", "minor", "patch", "betaPreRelease"] as const) {
for (const level of ["major", "minor", "patch", "rc"] as const) {
if (versionBehind[level] !== versionAhead[level]) {
return level;
}
Expand Down
16 changes: 8 additions & 8 deletions src/tools/octokit-addons/getLatestSemVersionedTag.ts
Expand Up @@ -11,15 +11,15 @@ export function getLatestSemVersionedTagFactory(params: { octokit: Octokit; }) {
params: {
owner: string;
repo: string;
beta: "ONLY LOOK FOR BETA" | "IGNORE BETA" | "BETA OR REGULAR RELEASE";
rcPolicy: "ONLY LOOK FOR RC" | "IGNORE RC" | "RC OR REGULAR RELEASE";
major: number | undefined;
}
): Promise<{
tag: string;
version: NpmModuleVersion;
} | undefined> {

const { owner, repo, beta, major } = params;
const { owner, repo, rcPolicy, major } = params;

const semVersionedTags: { tag: string; version: NpmModuleVersion; }[] = [];

Expand All @@ -41,17 +41,17 @@ export function getLatestSemVersionedTagFactory(params: { octokit: Octokit; }) {
continue;
}

switch (beta) {
case "IGNORE BETA":
if (version.betaPreRelease !== undefined) {
switch (rcPolicy) {
case "IGNORE RC":
if (version.rc !== undefined) {
continue;
}
break;
case "ONLY LOOK FOR BETA":
if (version.betaPreRelease === undefined) {
case "ONLY LOOK FOR RC":
if (version.rc === undefined) {
continue;
}
case "BETA OR REGULAR RELEASE":
case "RC OR REGULAR RELEASE":
break;
}

Expand Down
8 changes: 4 additions & 4 deletions src/update_changelog.ts
Expand Up @@ -57,7 +57,7 @@ export async function action(

const { getLatestSemVersionedTag } = getLatestSemVersionedTagFactory({ octokit });

const { tag: branchBehind } = (await getLatestSemVersionedTag({ owner, repo, "beta": "IGNORE BETA", "major": undefined })) ?? {};
const { tag: branchBehind } = (await getLatestSemVersionedTag({ owner, repo, "rcPolicy": "IGNORE RC", "major": undefined })) ?? {};

if( branchBehind === undefined ){

Expand Down Expand Up @@ -101,9 +101,9 @@ export async function action(
)
);

if( NpmModuleVersion.parse(branchAheadVersion).betaPreRelease !== undefined ){
if( NpmModuleVersion.parse(branchAheadVersion).rc !== undefined ){

core.warning(`Version on ${branch} is ${branchAheadVersion} it's a beta release, we do not update the CHANGELOG.md`);
core.warning(`Version on ${branch} is ${branchAheadVersion} it's a release candidate, we do not update the CHANGELOG.md`);

return;

Expand All @@ -114,7 +114,7 @@ export async function action(
"versionBehindStr": branchBehindVersion || "0.0.0"
});

assert(bumpType !== "betaPreRelease");
assert(bumpType !== "rc");

if( bumpType === "same" ){

Expand Down

0 comments on commit a75bdd3

Please sign in to comment.