From 7b20bfa88d3b9568e21f85a14b045d9a0f64d79d Mon Sep 17 00:00:00 2001 From: Nikolai Laevskii Date: Mon, 4 Sep 2023 05:13:00 +0200 Subject: [PATCH] Update dotnet utils, to handle more cases --- dist/setup/index.js | 10 +++++++++- src/dotnet-utils.ts | 16 +++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 284fea0..015e4ca 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -72811,7 +72811,15 @@ exports.listSdks = listSdks; * correct version number like '3.1.201', '3.1.201', '3.1.201', '3.1.201', '6.0.402' */ const matchVersionToList = (version, versions) => { - const versionRegex = new RegExp(`^${version.replace(/x/g, '\\d+')}`); + if (!version || version === 'x' || version === '*') { + return versions.at(0); + } + const versionArray = version.split('.'); + if (versionArray.length < 3) { + versionArray.push(...Array(3 - versionArray.length).fill('x')); + } + const normalizedVersion = versionArray.join('.'); + const versionRegex = new RegExp(`^${normalizedVersion.replace(/x/g, '\\d+')}`); const matchedVersion = versions.find(v => versionRegex.test(v)); return matchedVersion; }; diff --git a/src/dotnet-utils.ts b/src/dotnet-utils.ts index 6ba1297..8a44369 100644 --- a/src/dotnet-utils.ts +++ b/src/dotnet-utils.ts @@ -28,7 +28,21 @@ export const listSdks = async () => { * correct version number like '3.1.201', '3.1.201', '3.1.201', '3.1.201', '6.0.402' */ export const matchVersionToList = (version: string, versions: string[]) => { - const versionRegex = new RegExp(`^${version.replace(/x/g, '\\d+')}`); + if (!version || version === 'x' || version === '*') { + return versions.at(0); + } + + const versionArray = version.split('.'); + + if (versionArray.length < 3) { + versionArray.push(...Array(3 - versionArray.length).fill('x')); + } + + const normalizedVersion = versionArray.join('.'); + + const versionRegex = new RegExp( + `^${normalizedVersion.replace(/x/g, '\\d+')}` + ); const matchedVersion = versions.find(v => versionRegex.test(v)); return matchedVersion;