fix(core): fix broken nx-cloud url shortening logic (#31283)
Current URL shortening logic is based on the old Nx Cloud version format - `YYMM.DD.BuildVersion`. Since, 2025 we changed that format to `YYYY.MM.BuildVersion` which breaks this logic and causes the connection URL to be just host. ## Current Behavior <!-- This is the behavior we have today --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
This commit is contained in:
parent
f1171191dd
commit
a71a6cab40
@ -1,7 +1,7 @@
|
||||
import { getGithubSlugOrNull } from '../../utils/git-utils';
|
||||
import {
|
||||
removeVersionModifier,
|
||||
compareCleanCloudVersions,
|
||||
isOldNxCloudVersion,
|
||||
getNxCloudVersion,
|
||||
versionIsValid,
|
||||
getURLifShortenFailed,
|
||||
@ -22,27 +22,22 @@ jest.mock('./get-cloud-options', () => ({
|
||||
}));
|
||||
|
||||
describe('URL shorten various functions', () => {
|
||||
describe('compareCleanCloudVersions', () => {
|
||||
it('should return 1 if the first version is newer', () => {
|
||||
expect(compareCleanCloudVersions('2407.01.100', '2312.25.50')).toBe(1);
|
||||
expect(compareCleanCloudVersions('2402.01.20', '2401.31.300')).toBe(1);
|
||||
expect(compareCleanCloudVersions('2401.01.20', '2312.31.300')).toBe(1);
|
||||
expect(compareCleanCloudVersions('2312.26.05', '2312.25.100')).toBe(1);
|
||||
expect(compareCleanCloudVersions('2312.25.100', '2311.25.90')).toBe(1);
|
||||
expect(compareCleanCloudVersions('2312.25.120', '2312.24.110')).toBe(1);
|
||||
describe('isOldNxCloudVersion', () => {
|
||||
it('should compare versions of the same format', () => {
|
||||
expect(isOldNxCloudVersion('2407.11.5')).toBe(false);
|
||||
expect(isOldNxCloudVersion('2406.12.5')).toBe(false);
|
||||
expect(isOldNxCloudVersion('2406.11.6')).toBe(false);
|
||||
expect(isOldNxCloudVersion('2406.11.5')).toBe(false);
|
||||
expect(isOldNxCloudVersion('2406.11.4')).toBe(true);
|
||||
|
||||
expect(isOldNxCloudVersion('2307.13.12')).toBe(true);
|
||||
expect(isOldNxCloudVersion('2406.10.55')).toBe(true);
|
||||
expect(isOldNxCloudVersion('2406.11.1')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return -1 if the first version is older', () => {
|
||||
expect(compareCleanCloudVersions('2312.25.50', '2407.01.100')).toBe(-1);
|
||||
expect(compareCleanCloudVersions('2312.31.100', '2401.01.100')).toBe(-1);
|
||||
expect(compareCleanCloudVersions('2312.25.100', '2312.26.50')).toBe(-1);
|
||||
expect(compareCleanCloudVersions('2311.25.90', '2312.25.80')).toBe(-1);
|
||||
expect(compareCleanCloudVersions('2312.24.110', '2312.25.100')).toBe(-1);
|
||||
});
|
||||
|
||||
it('should return 0 if both versions are the same', () => {
|
||||
expect(compareCleanCloudVersions('2312.25.50', '2312.25.50')).toBe(0);
|
||||
expect(compareCleanCloudVersions('2407.01.100', '2407.01.100')).toBe(0);
|
||||
it('should compare versions of different format', () => {
|
||||
expect(isOldNxCloudVersion('2025.11.5')).toBe(false);
|
||||
expect(isOldNxCloudVersion('2026.12.5')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -21,10 +21,7 @@ export async function createNxCloudOnboardingURL(
|
||||
|
||||
try {
|
||||
const version = await getNxCloudVersion(apiUrl);
|
||||
if (
|
||||
(version && compareCleanCloudVersions(version, '2406.11.5') < 0) ||
|
||||
!version
|
||||
) {
|
||||
if (!version || isOldNxCloudVersion(version)) {
|
||||
return apiUrl;
|
||||
}
|
||||
} catch (e) {
|
||||
@ -176,32 +173,32 @@ export function versionIsValid(version: string): boolean {
|
||||
return pattern.test(version);
|
||||
}
|
||||
|
||||
export function compareCleanCloudVersions(
|
||||
version1: string,
|
||||
version2: string
|
||||
): number {
|
||||
const parseVersion = (version: string) => {
|
||||
// The format we're using is YYMM.DD.BuildNumber
|
||||
const parts = version.split('.').map((part) => parseInt(part, 10));
|
||||
return {
|
||||
yearMonth: parts[0],
|
||||
day: parts[1],
|
||||
buildNumber: parts[2],
|
||||
};
|
||||
};
|
||||
export function isOldNxCloudVersion(version: string): boolean {
|
||||
const [major, minor, buildNumber] = version
|
||||
.split('.')
|
||||
.map((part) => parseInt(part, 10));
|
||||
|
||||
const v1 = parseVersion(version1);
|
||||
const v2 = parseVersion(version2);
|
||||
|
||||
if (v1.yearMonth !== v2.yearMonth) {
|
||||
return v1.yearMonth > v2.yearMonth ? 1 : -1;
|
||||
}
|
||||
if (v1.day !== v2.day) {
|
||||
return v1.day > v2.day ? 1 : -1;
|
||||
}
|
||||
if (v1.buildNumber !== v2.buildNumber) {
|
||||
return v1.buildNumber > v2.buildNumber ? 1 : -1;
|
||||
// for on-prem images we are using YYYY.MM.BuildNumber format
|
||||
// the first year is 2025
|
||||
if (major >= 2025 && major < 2300) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return 0;
|
||||
// Previously we used YYMM.DD.BuildNumber
|
||||
// All versions before '2406.11.5' had different URL shortening logic
|
||||
const newVersionMajor = 2406;
|
||||
const newVersionMinor = 11;
|
||||
const newVersionBuildNumber = 5;
|
||||
|
||||
if (major !== newVersionMajor) {
|
||||
return major < newVersionMajor;
|
||||
}
|
||||
if (minor !== newVersionMinor) {
|
||||
return minor < newVersionMinor;
|
||||
}
|
||||
if (buildNumber !== newVersionBuildNumber) {
|
||||
return buildNumber < newVersionBuildNumber;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user