Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(versioning): add versioning scheme for glasskube package manager #29506

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/modules/versioning/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
54 changes: 54 additions & 0 deletions lib/modules/versioning/glasskube/index.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
38 changes: 38 additions & 0 deletions lib/modules/versioning/glasskube/index.ts
Original file line number Diff line number Diff line change
@@ -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;
Loading