From d03d4fe9c646cb6cb5862540c0f97ca90e01a6f4 Mon Sep 17 00:00:00 2001 From: shaanmugapriya Date: Mon, 12 Feb 2024 14:10:45 +0530 Subject: [PATCH] Updated code to fix 501 --- dist/setup/index.js | 16 +++++++++++++--- setup-dotnet.sln | 30 ++++++++++++++++++++++++++++++ src/setup-dotnet.ts | 14 +++++++++++++- 3 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 setup-dotnet.sln diff --git a/dist/setup/index.js b/dist/setup/index.js index 6070fed..5ec6189 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -93335,6 +93335,10 @@ const qualityOptions = [ 'preview', 'ga' ]; +let cancelled = false; +process.on('SIGINT', () => { + cancelled = true; +}); function run() { return __awaiter(this, void 0, void 0, function* () { try { @@ -93358,8 +93362,6 @@ function run() { versions.push(getVersionFromGlobalJson(globalJsonPath)); } if (!versions.length) { - // Try to fall back to global.json - core.debug('No version found, trying to find version from global.json'); const globalJsonPath = path_1.default.join(process.cwd(), 'global.json'); if (fs.existsSync(globalJsonPath)) { versions.push(getVersionFromGlobalJson(globalJsonPath)); @@ -93376,6 +93378,9 @@ function run() { let dotnetInstaller; const uniqueVersions = new Set(versions); for (const version of uniqueVersions) { + if (cancelled) { + throw new Error('Cancelled'); + } dotnetInstaller = new installer_1.DotnetCoreInstaller(version, quality); const installedVersion = yield dotnetInstaller.installDotnet(); installedDotnetVersions.push(installedVersion); @@ -93396,7 +93401,12 @@ function run() { core.info(`##[add-matcher]${path_1.default.join(matchersPath, 'csc.json')}`); } catch (error) { - core.setFailed(error.message); + if (error.message === 'Cancelled') { + console.log('Cleaning up...'); + } + else { + core.setFailed(error.message); + } } }); } diff --git a/setup-dotnet.sln b/setup-dotnet.sln new file mode 100644 index 0000000..a8cae1d --- /dev/null +++ b/setup-dotnet.sln @@ -0,0 +1,30 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.002.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "__tests__", "__tests__", "{4EBCF652-9B47-4590-A4F4-9AFC5FB9AB16}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "test", "__tests__\e2e-test-csproj\test.csproj", "{BF96E0E1-5384-4445-92C8-B9B999FD812E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BF96E0E1-5384-4445-92C8-B9B999FD812E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BF96E0E1-5384-4445-92C8-B9B999FD812E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BF96E0E1-5384-4445-92C8-B9B999FD812E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BF96E0E1-5384-4445-92C8-B9B999FD812E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {BF96E0E1-5384-4445-92C8-B9B999FD812E} = {4EBCF652-9B47-4590-A4F4-9AFC5FB9AB16} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7249446B-27CA-4F79-B35C-1575C52AFB5D} + EndGlobalSection +EndGlobal diff --git a/src/setup-dotnet.ts b/src/setup-dotnet.ts index 2a628a5..ab184bf 100644 --- a/src/setup-dotnet.ts +++ b/src/setup-dotnet.ts @@ -19,6 +19,11 @@ const qualityOptions = [ export type QualityOptions = (typeof qualityOptions)[number]; +let cancelled = false; +process.on('SIGINT', () => { + cancelled = true; +}); + export async function run() { try { // @@ -69,6 +74,9 @@ export async function run() { let dotnetInstaller: DotnetCoreInstaller; const uniqueVersions = new Set(versions); for (const version of uniqueVersions) { + if (cancelled) { + throw new Error('Cancelled'); + } dotnetInstaller = new DotnetCoreInstaller(version, quality); const installedVersion = await dotnetInstaller.installDotnet(); installedDotnetVersions.push(installedVersion); @@ -92,7 +100,11 @@ export async function run() { const matchersPath = path.join(__dirname, '..', '..', '.github'); core.info(`##[add-matcher]${path.join(matchersPath, 'csc.json')}`); } catch (error) { - core.setFailed(error.message); + if (error.message === 'Cancelled') { + 'Cleaning up...'; + } else { + core.setFailed(error.message); + } } }