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 { getGithubSlugOrNull } from '../../utils/git-utils';
|
||||||
import {
|
import {
|
||||||
removeVersionModifier,
|
removeVersionModifier,
|
||||||
compareCleanCloudVersions,
|
isOldNxCloudVersion,
|
||||||
getNxCloudVersion,
|
getNxCloudVersion,
|
||||||
versionIsValid,
|
versionIsValid,
|
||||||
getURLifShortenFailed,
|
getURLifShortenFailed,
|
||||||
@ -22,27 +22,22 @@ jest.mock('./get-cloud-options', () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
describe('URL shorten various functions', () => {
|
describe('URL shorten various functions', () => {
|
||||||
describe('compareCleanCloudVersions', () => {
|
describe('isOldNxCloudVersion', () => {
|
||||||
it('should return 1 if the first version is newer', () => {
|
it('should compare versions of the same format', () => {
|
||||||
expect(compareCleanCloudVersions('2407.01.100', '2312.25.50')).toBe(1);
|
expect(isOldNxCloudVersion('2407.11.5')).toBe(false);
|
||||||
expect(compareCleanCloudVersions('2402.01.20', '2401.31.300')).toBe(1);
|
expect(isOldNxCloudVersion('2406.12.5')).toBe(false);
|
||||||
expect(compareCleanCloudVersions('2401.01.20', '2312.31.300')).toBe(1);
|
expect(isOldNxCloudVersion('2406.11.6')).toBe(false);
|
||||||
expect(compareCleanCloudVersions('2312.26.05', '2312.25.100')).toBe(1);
|
expect(isOldNxCloudVersion('2406.11.5')).toBe(false);
|
||||||
expect(compareCleanCloudVersions('2312.25.100', '2311.25.90')).toBe(1);
|
expect(isOldNxCloudVersion('2406.11.4')).toBe(true);
|
||||||
expect(compareCleanCloudVersions('2312.25.120', '2312.24.110')).toBe(1);
|
|
||||||
|
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', () => {
|
it('should compare versions of different format', () => {
|
||||||
expect(compareCleanCloudVersions('2312.25.50', '2407.01.100')).toBe(-1);
|
expect(isOldNxCloudVersion('2025.11.5')).toBe(false);
|
||||||
expect(compareCleanCloudVersions('2312.31.100', '2401.01.100')).toBe(-1);
|
expect(isOldNxCloudVersion('2026.12.5')).toBe(false);
|
||||||
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);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -21,10 +21,7 @@ export async function createNxCloudOnboardingURL(
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const version = await getNxCloudVersion(apiUrl);
|
const version = await getNxCloudVersion(apiUrl);
|
||||||
if (
|
if (!version || isOldNxCloudVersion(version)) {
|
||||||
(version && compareCleanCloudVersions(version, '2406.11.5') < 0) ||
|
|
||||||
!version
|
|
||||||
) {
|
|
||||||
return apiUrl;
|
return apiUrl;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -134,7 +131,7 @@ async function getInstallationSupportsGitHub(apiUrl: string): Promise<boolean> {
|
|||||||
return !!response.data.isGithubIntegrationEnabled;
|
return !!response.data.isGithubIntegrationEnabled;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (process.env.NX_VERBOSE_LOGGING === 'true') {
|
if (process.env.NX_VERBOSE_LOGGING === 'true') {
|
||||||
logger.warn(`Failed to access system features. GitHub integration assumed to be disabled.
|
logger.warn(`Failed to access system features. GitHub integration assumed to be disabled.
|
||||||
${e}`);
|
${e}`);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -176,32 +173,32 @@ export function versionIsValid(version: string): boolean {
|
|||||||
return pattern.test(version);
|
return pattern.test(version);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function compareCleanCloudVersions(
|
export function isOldNxCloudVersion(version: string): boolean {
|
||||||
version1: string,
|
const [major, minor, buildNumber] = version
|
||||||
version2: string
|
.split('.')
|
||||||
): number {
|
.map((part) => parseInt(part, 10));
|
||||||
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],
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const v1 = parseVersion(version1);
|
// for on-prem images we are using YYYY.MM.BuildNumber format
|
||||||
const v2 = parseVersion(version2);
|
// the first year is 2025
|
||||||
|
if (major >= 2025 && major < 2300) {
|
||||||
if (v1.yearMonth !== v2.yearMonth) {
|
return false;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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