This commit is contained in:
Ivan Ka 2025-01-03 17:56:07 -05:00 committed by GitHub
commit 473753509a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 161 additions and 121 deletions

View file

@ -1,11 +1,13 @@
import { regEx } from '../../../util/regex';
const regex = regEx(/^(?<codename>\w+)-(?<date>\d{8})(?<suffix>\.\d{1,2})?$/);
function isDatedCodeName(input: string): boolean {
return regEx(/^(?<codename>\w+)-(?<date>\d{8})$/).test(input);
return regex.test(input);
}
function getDatedContainerImageCodename(version: string): null | string {
const groups = regEx(/^(?<codename>\w+)-(?<date>\d{8})$/).exec(version);
const groups = regex.exec(version);
if (!groups?.groups) {
return null;
}
@ -13,7 +15,7 @@ function getDatedContainerImageCodename(version: string): null | string {
}
function getDatedContainerImageVersion(version: string): null | number {
const groups = regEx(/^(?<codename>\w+)-(?<date>\d{8})$/).exec(version);
const groups = regex.exec(version);
if (!groups?.groups) {
return null;
}
@ -21,8 +23,18 @@ function getDatedContainerImageVersion(version: string): null | number {
return parseInt(groups.groups.date, 10);
}
function getDatedContainerImageSuffix(version: string): null | string {
const groups = regex.exec(version);
if (!groups?.groups?.suffix) {
return null;
}
return groups.groups.suffix;
}
export {
isDatedCodeName,
getDatedContainerImageCodename,
getDatedContainerImageVersion,
getDatedContainerImageSuffix,
};

View file

@ -82,7 +82,11 @@ describe('modules/versioning/ubuntu/index', () => {
${'impish'} | ${true}
${'jammy'} | ${true}
${'jammy-20230816'} | ${true}
${'jammy-2023086'} | ${false}
${'jammy-20230816'} | ${true}
${'yakkety-20160806.1'} | ${true}
${'utopic-20150228.11'} | ${true}
${'utopic-20150228.11.1'} | ${false}
${'oracular-20240811.'} | ${false}
`('isValid("$version") === $expected', ({ version, expected }) => {
expect(ubuntu.isValid(version)).toBe(expected);
});
@ -285,6 +289,9 @@ describe('modules/versioning/ubuntu/index', () => {
${'jammy'} | ${'jammy-20230816'} | ${false}
${'jammy-20230816'} | ${'jammy-20230816'} | ${true}
${'jammy-20230716'} | ${'jammy-20230816'} | ${false}
${'jammy-20230716.1'} | ${'jammy-20230716.1'} | ${true}
${'jammy-20230716.1'} | ${'jammy-20230716.2'} | ${false}
${'jammy-20230716.1'} | ${'jammy-20230816.11'} | ${false}
`('equals($a, $b) === $expected', ({ a, b, expected }) => {
expect(ubuntu.equals(a, b)).toBe(expected);
});
@ -317,6 +324,11 @@ describe('modules/versioning/ubuntu/index', () => {
${'jammy-20230816'} | ${'jammy-20230716'} | ${true}
${'jammy-20230716'} | ${'jammy-20230816'} | ${false}
${'focal-20230816'} | ${'jammy-20230716'} | ${false}
${'zesty-20170517.1'} | ${'jammy-20240627.1'} | ${false}
${'jammy-20240627.3'} | ${'jammy-20240627.1'} | ${true}
${'jammy-20240627.3'} | ${'jammy-20240627.4'} | ${false}
${'jammy-20240627.1'} | ${'precise-20150228.11'} | ${true}
${'jammy-20240627'} | ${'precise-20150228.11'} | ${true}
`('isGreaterThan("$a", "$b") === $expected', ({ a, b, expected }) => {
expect(ubuntu.isGreaterThan(a, b)).toBe(expected);
});

View file

@ -4,6 +4,7 @@ import { DistroInfo } from '../distro';
import type { NewValueConfig, VersioningApi } from '../types';
import {
getDatedContainerImageCodename,
getDatedContainerImageSuffix,
getDatedContainerImageVersion,
isDatedCodeName,
} from './common';
@ -105,6 +106,12 @@ function equals(version: string, other: string): boolean {
return false;
}
const verSuffix = getDatedContainerImageSuffix(version);
const otherSuffix = getDatedContainerImageSuffix(other);
if (verSuffix !== otherSuffix) {
return false;
}
const ver = getVersionByCodename(version);
const otherVer = getVersionByCodename(other);
return isVersion(ver) && isVersion(otherVer) && ver === otherVer;
@ -138,6 +145,15 @@ function isGreaterThan(version: string, other: string): boolean {
return false;
}
const xSuffixVersion = getDatedContainerImageSuffix(version) ?? 0;
const ySuffixVersion = getDatedContainerImageSuffix(other) ?? 0;
if (xSuffixVersion > ySuffixVersion) {
return true;
}
if (xSuffixVersion < ySuffixVersion) {
return false;
}
const xPatch = getPatch(version) ?? 0;
const yPatch = getPatch(other) ?? 0;
return xPatch > yPatch;