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 1 commit
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 @@ -27,6 +27,7 @@
import * as poetry from './poetry';
import * as python from './python';
import * as redhat from './redhat';
import * as glasskube from './glasskube';

Check failure on line 30 in lib/modules/versioning/api.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

`./glasskube` import should occur before import of `./go-mod-directive`
import * as regex from './regex';
import * as rez from './rez';
import * as rpm from './rpm';
Expand All @@ -51,6 +52,7 @@
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`

Check failure on line 5 in lib/modules/versioning/glasskube/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

Expected blank line before this statement.
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);

Check failure on line 40 in lib/modules/versioning/glasskube/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

Expect must have a corresponding matcher call
},
);

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();
});
});
36 changes: 36 additions & 0 deletions lib/modules/versioning/glasskube/index.ts
Original file line number Diff line number Diff line change
@@ -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) {}

Check failure on line 29 in lib/modules/versioning/glasskube/index.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

Empty block statement.
}
return result;
}
}

export const api: VersioningApi = new GlasskubeVersioningApi();
export default api;
Loading