[REFACTOR] Workspace version only x.y.z (#10910)

# Introduction
We want the APP_VERSION to be able to contains pre-release options, in a
nutshell to be semVer compatible.
But we want to have workspace, at least for the moment, that only store
`x.y.z` and not `vx.y.z` or `x.y.z-alpha` version in database

Explaining this refactor

Related https://github.com/twentyhq/twenty/pull/10907
This commit is contained in:
Paul Rastoin
2025-03-14 19:21:44 +01:00
committed by GitHub
parent 1aeef2b68e
commit 23b4605987
6 changed files with 149 additions and 21 deletions

View File

@ -0,0 +1,107 @@
import { EachTestingContext } from 'twenty-shared';
import { extractVersionMajorMinorPatch } from 'src/utils/version/extract-version-major-minor-patch';
type IsSameVersionTestCase = EachTestingContext<{
version: string | undefined;
expected: string | null;
}>;
describe('extract-version-major-minor-patch', () => {
const testCase: IsSameVersionTestCase[] = [
{
context: {
version: '1.0.0',
expected: '1.0.0',
},
title: 'Basic version',
},
{
context: {
version: '2.3.4',
expected: '2.3.4',
},
title: 'Version with non-zero patch',
},
{
context: {
version: '0.1.0',
expected: '0.1.0',
},
title: 'Version with zero major',
},
{
context: {
version: '1.0.0-alpha',
expected: '1.0.0',
},
title: 'Version with pre-release tag',
},
{
context: {
version: '1.0.0-beta.1',
expected: '1.0.0',
},
title: 'Version with pre-release tag and number',
},
{
context: {
version: 'v1.0.0',
expected: '1.0.0',
},
title: 'Version with v prefix',
},
{
context: {
version: '42.42.42',
expected: '42.42.42',
},
title: 'Version with large numbers',
},
{
context: {
version: '1.2',
expected: null,
},
title: 'Invalid version - missing patch number',
},
{
context: {
version: 'invalid',
expected: null,
},
title: 'Invalid version - not semver format',
},
{
context: {
version: undefined,
expected: null,
},
title: 'With undefined version',
},
{
context: {
version: '1.0.0.0',
expected: null,
},
title: 'Invalid version - too many segments',
},
{
context: {
version: '1.a.0',
expected: null,
},
title: 'Invalid version - non-numeric minor',
},
{
context: {
version: '',
expected: null,
},
title: 'Invalid version - empty string',
},
];
test.each(testCase)('$title', ({ context: { version, expected } }) => {
expect(extractVersionMajorMinorPatch(version)).toBe(expected);
});
});

View File

@ -0,0 +1,11 @@
import semver from 'semver';
export const extractVersionMajorMinorPatch = (version: string | undefined) => {
const parsed = semver.parse(version);
if (parsed === null) {
return null;
}
return `${parsed.major}.${parsed.minor}.${parsed.patch}`;
};