diff --git a/lib/modules/versioning/api.ts b/lib/modules/versioning/api.ts index a2f52a8a738243c..2fb4afb5d9479d5 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'; @@ -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 000000000000000..28fea75c0eea53e --- /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); + }, + ); + + 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 000000000000000..5365cc2df6a19ec --- /dev/null +++ b/lib/modules/versioning/glasskube/index.ts @@ -0,0 +1,38 @@ +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) { + /* noop */ + } + } + return result; + } +} + +export const api: VersioningApi = new GlasskubeVersioningApi(); +export default api;