-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Allows to specify the version of Cake to use (#1)
- Loading branch information
Showing
8 changed files
with
160 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,65 @@ | ||
import * as path from 'path'; | ||
import * as core from '@actions/core'; | ||
import { exec } from '@actions/exec'; | ||
import { ToolsDirectory } from './toolsDirectory'; | ||
import { Platform } from './platform'; | ||
|
||
const dotnetToolInstall = 'dotnet tool install'; | ||
const dotnetToolUnInstall = 'dotnet tool uninstall'; | ||
const dotnetCake = 'dotnet-cake'; | ||
|
||
export class DotNet { | ||
static disableTelemetry() { | ||
core.exportVariable('DOTNET_CLI_TELEMETRY_OPTOUT', '1'); | ||
} | ||
|
||
static async installLocalCakeTool(targetDirectory: ToolsDirectory = new ToolsDirectory()) { | ||
const cakeTool = Platform.isWindows() ? `${dotnetCake}.exe` : dotnetCake; | ||
static async installLocalCakeTool( | ||
targetDirectory: ToolsDirectory = new ToolsDirectory(), | ||
version?: string | ||
) { | ||
return DotNet.installLocalTool('Cake.Tool', dotnetCake, targetDirectory, version); | ||
} | ||
|
||
static async installLocalTool( | ||
packageId: string, | ||
toolName: string, | ||
targetDirectory: ToolsDirectory = new ToolsDirectory(), | ||
version?: string | ||
) { | ||
const toolExecutable = `${toolName}${Platform.isWindows() ? '.exe' : ''}`; | ||
|
||
if (targetDirectory.containsFile(toolExecutable)) { | ||
if (version) { | ||
const toolInstallPath = path.join( | ||
'.store', | ||
packageId.toLowerCase(), | ||
version.toLowerCase(), | ||
'project.assets.json' | ||
); | ||
|
||
if (targetDirectory.containsFile(cakeTool)) { | ||
core.info(`The Cake.Tool already exists in ${targetDirectory}, skipping installation`); | ||
return; | ||
if (targetDirectory.containsFile(toolInstallPath)) { | ||
core.info(`The ${packageId} version ${version} already exists in ${targetDirectory}, skipping installation`); | ||
return; | ||
} | ||
|
||
const uninstallExitCode = await exec(dotnetToolUnInstall, ['--tool-path', targetDirectory.path, packageId]); | ||
|
||
if (uninstallExitCode != 0) { | ||
throw new Error(`Failed to uninstall previous version of ${packageId}. Exit code: ${uninstallExitCode}`); | ||
} | ||
} else { | ||
core.info(`The ${packageId} already exists in ${targetDirectory}, skipping installation`); | ||
return; | ||
} | ||
} | ||
|
||
return DotNet.installLocalTool('Cake.Tool', targetDirectory); | ||
} | ||
const versionArg = (version) ? ['--version', version] : []; | ||
const installArgs = [...versionArg, '--tool-path', targetDirectory.path, packageId]; | ||
|
||
static async installLocalTool(toolName: string, targetDirectory: ToolsDirectory = new ToolsDirectory()) { | ||
const exitCode = await exec(dotnetToolInstall, ['--tool-path', targetDirectory.path, toolName]); | ||
const exitCode = await exec(dotnetToolInstall, installArgs); | ||
|
||
if (exitCode != 0) { | ||
throw new Error(`Failed to install ${toolName}. Exit code: ${exitCode}`); | ||
throw new Error(`Failed to install ${packageId}. Exit code: ${exitCode}`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters