forked from renovatebot/renovate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(versioning): add versioning scheme for glasskube package manager (…
…renovatebot#29506) Signed-off-by: Jakob Steiner <[email protected]>
- Loading branch information
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |