mirror of
https://github.com/garronej/ts-ci.git
synced 2025-11-30 21:43:05 +00:00
Add is_release_beta output in is_package_json_version_upgraded
This commit is contained in:
parent
5297ab00ab
commit
e8c1eb1074
9 changed files with 324 additions and 84 deletions
|
|
@ -4,6 +4,7 @@ export type NpmModuleVersion = {
|
|||
major: number;
|
||||
minor: number;
|
||||
patch: number;
|
||||
betaPreRelease?: number;
|
||||
};
|
||||
|
||||
export namespace NpmModuleVersion {
|
||||
|
|
@ -12,20 +13,28 @@ export namespace NpmModuleVersion {
|
|||
|
||||
const match = versionStr.match(/^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-beta.([0-9]+))?/);
|
||||
|
||||
if( !match ){
|
||||
if (!match) {
|
||||
throw new Error(`${versionStr} is not a valid NPM version`);
|
||||
}
|
||||
|
||||
return {
|
||||
"major": parseInt(match[1]),
|
||||
"minor": parseInt(match[2]),
|
||||
"patch": parseInt(match[3])
|
||||
"patch": parseInt(match[3]),
|
||||
...(() => {
|
||||
|
||||
const str = match[4];
|
||||
return str === undefined ?
|
||||
{} :
|
||||
{ "betaPreRelease": parseInt(str) };
|
||||
|
||||
})()
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
export function stringify(v: NpmModuleVersion) {
|
||||
return `${v.major}.${v.minor}.${v.patch}`;
|
||||
return `${v.major}.${v.minor}.${v.patch}${v.betaPreRelease === undefined ? "" : `-beta.${v.betaPreRelease}`}`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -37,18 +46,17 @@ export namespace NpmModuleVersion {
|
|||
*/
|
||||
export function compare(v1: NpmModuleVersion, v2: NpmModuleVersion): -1 | 0 | 1 {
|
||||
|
||||
const sign = (n: number): -1 | 0 | 1 => n === 0 ? 0 : (n < 0 ? -1 : 1);
|
||||
const sign = (diff: number): -1 | 0 | 1 => diff === 0 ? 0 : (diff < 0 ? -1 : 1);
|
||||
const noUndefined= (n: number | undefined)=> n ?? -1;
|
||||
|
||||
if (v1.major === v2.major) {
|
||||
if (v1.minor === v2.minor) {
|
||||
return sign(v1.patch - v2.patch);
|
||||
} else {
|
||||
return sign(v1.minor - v2.minor);
|
||||
for (const level of ["major", "minor", "patch", "betaPreRelease"] as const) {
|
||||
if (noUndefined(v1[level]) !== noUndefined(v2[level])) {
|
||||
return sign(noUndefined(v1[level]) - noUndefined(v2[level]));
|
||||
}
|
||||
} else {
|
||||
return sign(v1.major - v2.major);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
export function bumpType(
|
||||
|
|
@ -56,34 +64,24 @@ export namespace NpmModuleVersion {
|
|||
versionBehindStr: string;
|
||||
versionAheadStr: string;
|
||||
}
|
||||
): "SAME" | "MAJOR" | "MINOR" | "PATCH" {
|
||||
): "major" | "minor" | "patch" | "betaPreRelease" | "same" {
|
||||
|
||||
|
||||
const versionAhead = parse(params.versionAheadStr);
|
||||
const versionBehind = parse(params.versionBehindStr);
|
||||
|
||||
if( compare(versionBehind, versionAhead) === 1 ){
|
||||
if (compare(versionBehind, versionAhead) === 1) {
|
||||
throw new Error(`Version regression ${versionBehind} -> ${versionAhead}`);
|
||||
}
|
||||
|
||||
if (versionBehind.major !== versionAhead.major) {
|
||||
|
||||
return "MAJOR";
|
||||
|
||||
} else if (versionBehind.minor !== versionAhead.minor) {
|
||||
|
||||
return "MINOR";
|
||||
|
||||
} else if (versionBehind.patch !== versionAhead.patch) {
|
||||
|
||||
return "PATCH";
|
||||
|
||||
} else {
|
||||
|
||||
return "SAME";
|
||||
|
||||
for (const level of ["major", "minor", "patch", "betaPreRelease"] as const) {
|
||||
if (versionBehind[level] !== versionAhead[level]) {
|
||||
return level;
|
||||
}
|
||||
}
|
||||
|
||||
return "same";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,13 +11,14 @@ export function getLatestSemVersionedTagFactory(params: { octokit: Octokit; }) {
|
|||
params: {
|
||||
owner: string;
|
||||
repo: string;
|
||||
doIgnoreBeta: boolean;
|
||||
}
|
||||
): Promise<{
|
||||
tag: string;
|
||||
version: NpmModuleVersion;
|
||||
} | undefined> {
|
||||
|
||||
const { owner, repo } = params;
|
||||
const { owner, repo, doIgnoreBeta } = params;
|
||||
|
||||
const semVersionedTags: { tag: string; version: NpmModuleVersion; }[] = [];
|
||||
|
||||
|
|
@ -25,16 +26,21 @@ export function getLatestSemVersionedTagFactory(params: { octokit: Octokit; }) {
|
|||
|
||||
for await (const tag of listTags({ owner, repo })) {
|
||||
|
||||
const match = tag.match(/^v?([0-9]+\.[0-9]+\.[0-9]+)$/);
|
||||
let version: NpmModuleVersion;
|
||||
|
||||
if (!match) {
|
||||
try{
|
||||
|
||||
version = NpmModuleVersion.parse(tag.replace(/^[vV]?/, ""));
|
||||
|
||||
}catch{
|
||||
continue;
|
||||
}
|
||||
|
||||
semVersionedTags.push({
|
||||
tag,
|
||||
"version": NpmModuleVersion.parse( match[1])
|
||||
});
|
||||
if( doIgnoreBeta && version.betaPreRelease !== undefined ){
|
||||
continue;
|
||||
}
|
||||
|
||||
semVersionedTags.push({ tag, version });
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue