From 9e6a20c45ae0d231a8afe50da5d07b5da42cf3b1 Mon Sep 17 00:00:00 2001 From: Jakob Steiner Date: Wed, 5 Jun 2024 16:58:01 +0200 Subject: [PATCH 1/2] feat(versioning): add versioning scheme for glasskube package manager Signed-off-by: Jakob Steiner --- lib/modules/versioning/api.ts | 2 + .../versioning/glasskube/index.spec.ts | 54 +++++++++++++++++++ lib/modules/versioning/glasskube/index.ts | 36 +++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 lib/modules/versioning/glasskube/index.spec.ts create mode 100644 lib/modules/versioning/glasskube/index.ts diff --git a/lib/modules/versioning/api.ts b/lib/modules/versioning/api.ts index a2f52a8a738243..abec7e24a03ca4 100644 --- a/lib/modules/versioning/api.ts +++ b/lib/modules/versioning/api.ts @@ -27,6 +27,7 @@ import * as perl from './perl'; import * as poetry from './poetry'; import * as python from './python'; import * as redhat from './redhat'; +import * as glasskube from './glasskube'; import * as regex from './regex'; import * as rez from './rez'; import * as rpm from './rpm'; @@ -51,6 +52,7 @@ api.set(deb.id, deb.api); api.set(debian.id, debian.api); api.set(docker.id, docker.api); api.set(git.id, git.api); +api.set(glasskube.id, glasskube.api); api.set(goModDirective.id, goModDirective.api); api.set(gradle.id, gradle.api); api.set(hashicorp.id, hashicorp.api); diff --git a/lib/modules/versioning/glasskube/index.spec.ts b/lib/modules/versioning/glasskube/index.spec.ts new file mode 100644 index 00000000000000..f64334be62dcae --- /dev/null +++ b/lib/modules/versioning/glasskube/index.spec.ts @@ -0,0 +1,54 @@ +import { GlasskubeVersioningApi } from '.'; + +describe('modules/versioning/glasskube/index', () => { + const versioning = new GlasskubeVersioningApi(); + it.each` + version | expected + ${'v1.2.3'} | ${true} + ${'v1.2.3+1'} | ${true} + ${'v1.2.3-1'} | ${false} + ${'v1.2.3-1+1'} | ${false} + `('isStable("$version") === $expected', ({ version, expected }) => { + expect(versioning.isStable(version)).toBe(expected); + }); + + it.each` + version | expected + ${'alpha'} | ${false} + ${'v1'} | ${false} + ${'v1.2'} | ${false} + ${'v1.2.3'} | ${true} + ${'v1.2.3+1'} | ${true} + ${'v1.2.3-1'} | ${true} + ${'v1.2.3-1+1'} | ${true} + ${'1.2.3-1+1'} | ${true} + `('isValid("$version") === $expected', ({ version, expected }) => { + expect(versioning.isValid(version)).toBe(expected); + }); + + it.each` + version | major | minor | patch + ${'v1.2.3'} | ${1} | ${2} | ${3} + ${'v1.2.3+1'} | ${1} | ${2} | ${3} + ${'v1.2.3-1'} | ${1} | ${2} | ${3} + `( + 'getMajor, getMinor, getPatch for "$version"', + ({ version, major, minor, patch }) => { + expect(versioning.getMajor(version)).toBe(major); + expect(versioning.getMinor(version)).toBe(minor); + expect(versioning.getPatch(version)).toBe(patch); + expect(versioning.getNewValue); + }, + ); + + it.each` + versionA | versionB + ${'v1.2.3'} | ${'v1.2.3+1'} + ${'v1.2.3+1'} | ${'v1.2.3+2'} + ${'v1.2.3-1'} | ${'v1.2.3+1'} + ${'v1.2.3-1+1'} | ${'v1.2.3+1'} + ${'v1.2.3-1'} | ${'v1.2.3-1+1'} + `('getMajor, getMinor, getPatch for "$version"', ({ versionA, versionB }) => { + expect(versioning.isGreaterThan(versionB, versionA)).toBeTrue(); + }); +}); diff --git a/lib/modules/versioning/glasskube/index.ts b/lib/modules/versioning/glasskube/index.ts new file mode 100644 index 00000000000000..ed411c471912e9 --- /dev/null +++ b/lib/modules/versioning/glasskube/index.ts @@ -0,0 +1,36 @@ +import { SemVer } from 'semver'; +import { GenericVersion, GenericVersioningApi } from '../generic'; +import type { VersioningApi } from '../types'; + +export const id = 'glasskube'; +export const displayName = 'glasskube'; +export const urls = []; +export const supportsRanges = false; + +export class GlasskubeVersioningApi extends GenericVersioningApi { + protected override _parse(version: string): GenericVersion | null { + let parsedVersion: SemVer; + try { + parsedVersion = new SemVer(version); + } catch (error) { + return null; + } + const result: GenericVersion = { + release: [parsedVersion.major, parsedVersion.minor, parsedVersion.patch], + prerelease: + parsedVersion.prerelease.length > 0 + ? parsedVersion.prerelease.join('.') + : undefined, + }; + const build = parsedVersion.build.at(0); + if (build) { + try { + result.release.push(parseInt(build)); + } catch (error) {} + } + return result; + } +} + +export const api: VersioningApi = new GlasskubeVersioningApi(); +export default api; From d0cff6d8ebf7489a329b8a81e13d46f24ff07dd1 Mon Sep 17 00:00:00 2001 From: Jakob Steiner Date: Mon, 10 Jun 2024 10:46:54 +0200 Subject: [PATCH 2/2] chore: fix linter errors --- lib/modules/versioning/api.ts | 2 +- lib/modules/versioning/glasskube/index.spec.ts | 2 +- lib/modules/versioning/glasskube/index.ts | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/modules/versioning/api.ts b/lib/modules/versioning/api.ts index abec7e24a03ca4..2fb4afb5d9479d 100644 --- a/lib/modules/versioning/api.ts +++ b/lib/modules/versioning/api.ts @@ -8,6 +8,7 @@ import * as deb from './deb'; import * as debian from './debian'; import * as docker from './docker'; import * as git from './git'; +import * as glasskube from './glasskube'; import * as goModDirective from './go-mod-directive'; import * as gradle from './gradle'; import * as hashicorp from './hashicorp'; @@ -27,7 +28,6 @@ import * as perl from './perl'; import * as poetry from './poetry'; import * as python from './python'; import * as redhat from './redhat'; -import * as glasskube from './glasskube'; import * as regex from './regex'; import * as rez from './rez'; import * as rpm from './rpm'; diff --git a/lib/modules/versioning/glasskube/index.spec.ts b/lib/modules/versioning/glasskube/index.spec.ts index f64334be62dcae..28fea75c0eea53 100644 --- a/lib/modules/versioning/glasskube/index.spec.ts +++ b/lib/modules/versioning/glasskube/index.spec.ts @@ -2,6 +2,7 @@ import { GlasskubeVersioningApi } from '.'; describe('modules/versioning/glasskube/index', () => { const versioning = new GlasskubeVersioningApi(); + it.each` version | expected ${'v1.2.3'} | ${true} @@ -37,7 +38,6 @@ describe('modules/versioning/glasskube/index', () => { expect(versioning.getMajor(version)).toBe(major); expect(versioning.getMinor(version)).toBe(minor); expect(versioning.getPatch(version)).toBe(patch); - expect(versioning.getNewValue); }, ); diff --git a/lib/modules/versioning/glasskube/index.ts b/lib/modules/versioning/glasskube/index.ts index ed411c471912e9..5365cc2df6a19e 100644 --- a/lib/modules/versioning/glasskube/index.ts +++ b/lib/modules/versioning/glasskube/index.ts @@ -26,7 +26,9 @@ export class GlasskubeVersioningApi extends GenericVersioningApi { if (build) { try { result.release.push(parseInt(build)); - } catch (error) {} + } catch (error) { + /* noop */ + } } return result; }