From 84b41f77fc3e734c220cc394bf2376aa9495a877 Mon Sep 17 00:00:00 2001 From: Andrew Kahr <22359829+AndrewKahr@users.noreply.github.com> Date: Sun, 17 Mar 2024 10:25:47 -0700 Subject: [PATCH] Update version check regex and fix tests --- dist/index.js | Bin 22303007 -> 22303227 bytes dist/index.js.map | Bin 14796635 -> 14796911 bytes src/model/image-tag.test.ts | 15 ++++++++++----- src/model/image-tag.ts | 8 ++++++++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/dist/index.js b/dist/index.js index 33531379c733305e507ff5629e4efb2570ba044b..f8abda07c5c57c764a0d24523e2104e7935853c8 100644 GIT binary patch delta 1586 zcmXxkXH*q*7{~DgT&94cvP6+77m*7p-~bWah#-n9LF+14x+#!w9S9i}Wkm&rb+s~A z!@W{b8CQW?M?jtR=-cW}D4YT5Pge%4|kUfz?)0YF}cl2(UNCdivPYau>P< z{5KgA7E#eMFs^0QzAV`}u%WKpP~&L#-e+)iX}MLu{G@MS+~oX%n0(X!$uq~!o5Uj` zu6|~N|AL@O1DxRkSGd6)9%uzmc)=U3(FQ(fi*{%aU-&`y0uYD}2tr46LNGcb1fd8+ zI3f^XZP<`hIQbs%M=0|ZboVpKny+TI- delta 1454 zcmWmEXFC=E07l^pZzZ9W5Fw*P3lW7xWwp@Wd+!}-E0v1&p4xkBYwxAf-h1y-X`Sc8 zeSX5p%g8ocx+2?bbh1&hak9xyLwZ7{eWD@NI3+j9fPBc00x(5En4u8NVF61NMiE${ zD2l-v#bEVCgF2{-dZ>>Eh(#RY(GZQ$7){U=&Cnbz z&=RfC8g0-P?a&?_&=H-`8C}p7-OwF9&=bAT8-36h{m>r+Fc5<<7(*}=!;pYP3`Y`1 zU?fIiG{#^o#vvKwF##!4_=<1%j$Hh}Py9k2e&Y}R;$LcRl2IBIW5q-Po0m sLkUyDm6}Q|rM42GL@H5Av=XD#QR*u7l=?~oC02=3;*GL6ijg7bKUYaJqW}N^ diff --git a/dist/index.js.map b/dist/index.js.map index e50af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9UsKGLQKz zU?GcG%n}k<$}*O-f&eR7#cI~DmUXOW1BoQDkz_WpnJom_$~LyMgPrVRH+$I2KK65f zgB;>8M>xtcj&p*OoZ>WRNZ~B!NaZ{ixJZagT;>W_xyE&FaFbiy<_>Ax { const testImageParameters = { - editorVersion: '2099.9.f9f9', + editorVersion: '2099.9.9f9', targetPlatform: 'Test', builderPlatform: '', containerRegistryRepository: 'unityci/editor', @@ -37,6 +37,11 @@ describe('ImageTag', () => { ).not.toThrow(); }); + test.each(['some version', ''])('throws for incorrect version %p', (editorVersion) => { + const { targetPlatform } = testImageParameters; + expect(() => new ImageTag({ editorVersion, targetPlatform })).toThrow(); + }); + test.each(['nonExisting'])('throws for unsupported target %p', (targetPlatform) => { expect(() => new ImageTag({ targetPlatform })).toThrow(); }); @@ -45,23 +50,23 @@ describe('ImageTag', () => { describe('toString', () => { it('returns the correct version', () => { const image = new ImageTag({ - editorVersion: '2099.1.1111', + editorVersion: '2099.1.1111f1', targetPlatform: testImageParameters.targetPlatform, containerRegistryRepository: 'unityci/editor', containerRegistryImageVersion: '3', }); switch (process.platform) { case 'win32': - expect(image.toString()).toStrictEqual(`${defaults.image}:windows-2099.1.1111-3`); + expect(image.toString()).toStrictEqual(`${defaults.image}:windows-2099.1.1111f1-3`); break; case 'linux': - expect(image.toString()).toStrictEqual(`${defaults.image}:ubuntu-2099.1.1111-3`); + expect(image.toString()).toStrictEqual(`${defaults.image}:ubuntu-2099.1.1111f1-3`); break; } }); it('returns customImage if given', () => { const image = new ImageTag({ - editorVersion: '2099.1.1111', + editorVersion: '2099.1.1111f1', targetPlatform: testImageParameters.targetPlatform, customImage: `${defaults.image}:2099.1.1111@347598437689743986`, containerRegistryRepository: 'unityci/editor', diff --git a/src/model/image-tag.ts b/src/model/image-tag.ts index 06f68d79..2b9fd910 100644 --- a/src/model/image-tag.ts +++ b/src/model/image-tag.ts @@ -20,6 +20,10 @@ class ImageTag { providerStrategy, } = imageProperties; + if (!ImageTag.versionPattern.test(editorVersion)) { + throw new Error(`Invalid version "${editorVersion}".`); + } + // Todo we might as well skip this class for customImage. // Either this.customImage = customImage; @@ -37,6 +41,10 @@ class ImageTag { this.imageRollingVersion = Number(containerRegistryImageVersion); // Will automatically roll to the latest non-breaking version. } + static get versionPattern(): RegExp { + return /^\d+\.\d+\.\d+[a-z]\d+$/; + } + static get targetPlatformSuffixes() { return { generic: '',