From b18b053aab9abcf64f1fb4ff4f8b05d773861b59 Mon Sep 17 00:00:00 2001 From: Jason Couture Date: Fri, 12 Jan 2024 20:38:55 -0500 Subject: [PATCH] Explicity set installation path Github actions tool guidelines, is to use the worker tool cache, instead of system-wide install path. --- src/installer.ts | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/installer.ts b/src/installer.ts index c71a8c69d9..1b3485643f 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -182,6 +182,14 @@ export class DotnetInstallScript { return this; } + public useInstallPath(installPath: string) { + if(installPath == null) { + installPath= DotnetInstallDir.dirPath; + } + this.useArguments(IS_WINDOWS ? '-Install-Dir' : "--install-dir", installPath); + return this; + } + public useVersion(dotnetVersion: DotnetVersion, quality?: QualityOptions) { if (dotnetVersion.type) { this.useArguments(dotnetVersion.type, dotnetVersion.value); @@ -222,12 +230,18 @@ export abstract class DotnetInstallDir { windows: path.join(process.env['PROGRAMFILES'] + '', 'dotnet') }; - public static readonly dirPath = process.env['DOTNET_INSTALL_DIR'] - ? DotnetInstallDir.convertInstallPathToAbsolute( - process.env['DOTNET_INSTALL_DIR'] - ) - : DotnetInstallDir.default[PLATFORM]; + private static getInstallDirectory() { + if(process.env["DOTNET_INSTALL_DIR"] != null) { + return process.env["DOTNET_INSTALL_DIR"]; + } + if(process.env["RUNNER_TOOL_CACHE"] != null) { + return path.join(process.env["RUNNER_TOOL_CACHE"], "dotnet"); + } + return DotnetInstallDir.default[PLATFORM]; + } + public static readonly dirPath = DotnetInstallDir.convertInstallPathToAbsolute(DotnetInstallDir.getInstallDirectory()); + private static convertInstallPathToAbsolute(installDir: string): string { if (path.isAbsolute(installDir)) return path.normalize(installDir); @@ -257,7 +271,7 @@ export class DotnetCoreInstaller { private version: string, private quality: QualityOptions ) {} - + public async installDotnet(): Promise { const versionResolver = new DotnetVersionResolver(this.version); const dotnetVersion = await versionResolver.createDotnetVersion(); @@ -275,6 +289,8 @@ export class DotnetCoreInstaller { .useArguments(IS_WINDOWS ? '-Runtime' : '--runtime', 'dotnet') // Use latest stable version .useArguments(IS_WINDOWS ? '-Channel' : '--channel', 'LTS') + // Explicitly set the install path (see https://github.com/actions/setup-dotnet/issues/360) + .useInstallPath(DotnetInstallDir.dirPath) .execute(); if (runtimeInstallOutput.exitCode) { @@ -298,6 +314,8 @@ export class DotnetCoreInstaller { ) // Use version provided by user .useVersion(dotnetVersion, this.quality) + // Explicitly set the install path (see https://github.com/actions/setup-dotnet/issues/360) + .useInstallPath(DotnetInstallDir.dirPath) .execute(); if (dotnetInstallOutput.exitCode) {