Skip to content

Commit

Permalink
Explicity set installation path
Browse files Browse the repository at this point in the history
Github actions tool guidelines, is to use the worker tool cache, instead of system-wide install path.
  • Loading branch information
jasoncouture committed Jan 13, 2024
1 parent 4d6c8fc commit 5107a10
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,17 @@ 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);
Expand Down Expand Up @@ -222,11 +233,20 @@ 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);
Expand Down Expand Up @@ -275,6 +295,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) {
Expand All @@ -298,6 +320,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) {
Expand Down

0 comments on commit 5107a10

Please sign in to comment.