mirror of
https://github.com/microsoft/setup-msbuild.git
synced 2024-11-10 05:51:07 +07:00
Changing to default path for runner location
This commit is contained in:
parent
3ef0817a4a
commit
6fdb4e0384
2957
dist/index.js
vendored
2957
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
63
src/main.ts
63
src/main.ts
@ -1,13 +1,14 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as toolCache from '@actions/tool-cache'
|
|
||||||
import * as exec from '@actions/exec'
|
import * as exec from '@actions/exec'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
|
import * as io from '@actions/io'
|
||||||
import {ExecOptions} from '@actions/exec/lib/interfaces'
|
import {ExecOptions} from '@actions/exec/lib/interfaces'
|
||||||
|
|
||||||
const IS_WINDOWS = process.platform === 'win32'
|
const IS_WINDOWS = process.platform === 'win32'
|
||||||
const VS_VERSION = core.getInput('vs-version') || 'latest'
|
const VS_VERSION = core.getInput('vs-version') || 'latest'
|
||||||
const VSWHERE_PATH = core.getInput('vswhere-path') || ''
|
const VSWHERE_PATH =
|
||||||
const VSWHERE_VERSION = '2.8.4'
|
core.getInput('vswhere-path') ||
|
||||||
|
'C:\\Program Files (x86)\\Microsoft Visual Studio\\Installer'
|
||||||
|
|
||||||
// if a specific version of VS is requested
|
// if a specific version of VS is requested
|
||||||
let VSWHERE_EXEC = ''
|
let VSWHERE_EXEC = ''
|
||||||
@ -31,34 +32,25 @@ async function run(): Promise<void> {
|
|||||||
|
|
||||||
// check to see if we are using a specific path for vswhere
|
// check to see if we are using a specific path for vswhere
|
||||||
let vswhereToolExe = ''
|
let vswhereToolExe = ''
|
||||||
let cachedToolDirectory = ''
|
|
||||||
|
|
||||||
if (VSWHERE_PATH) {
|
if (VSWHERE_PATH) {
|
||||||
// specified a path for vswhere, use it and cache the location
|
// specified a path for vswhere, use it
|
||||||
vswhereToolExe = path.join(VSWHERE_PATH, 'vswhere.exe')
|
vswhereToolExe = path.join(VSWHERE_PATH, 'vswhere.exe')
|
||||||
cachedToolDirectory = await toolCache.cacheDir(
|
|
||||||
VSWHERE_PATH,
|
|
||||||
'vswhere',
|
|
||||||
VSWHERE_VERSION
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
// using the tool on the runner
|
// check in PATH to see if it is there
|
||||||
// check and see if we have a cache for the specified tool version
|
try {
|
||||||
// eslint-disable-next-line @typescript-eslint/await-thenable
|
const vsWhereInPath: string = await io.which('vswhere', true)
|
||||||
cachedToolDirectory = await toolCache.find('vswhere', VSWHERE_VERSION)
|
core.debug(`Found tool in PATH: ${vsWhereInPath}`)
|
||||||
|
vswhereToolExe = path.join(vsWhereInPath, 'vswhere.exe')
|
||||||
// TODO: Remove this when runner has proper tool
|
} catch {
|
||||||
if (cachedToolDirectory) {
|
// wasn't found because which threw
|
||||||
core.debug(`Found cached version of vswhere-${VSWHERE_VERSION}`)
|
} finally {
|
||||||
} else {
|
core.setFailed(
|
||||||
cachedToolDirectory = await installTool()
|
'setup-msbuild requires the path to where vswhere.exe exists'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add cache dir to PATH
|
|
||||||
core.addPath(cachedToolDirectory)
|
|
||||||
|
|
||||||
vswhereToolExe = path.join(cachedToolDirectory, 'vswhere.exe')
|
|
||||||
core.debug(`Full cached tool exe: ${vswhereToolExe}`)
|
core.debug(`Full cached tool exe: ${vswhereToolExe}`)
|
||||||
|
|
||||||
let foundToolPath = ''
|
let foundToolPath = ''
|
||||||
@ -81,37 +73,16 @@ async function run(): Promise<void> {
|
|||||||
|
|
||||||
// extract the folder location for the tool
|
// extract the folder location for the tool
|
||||||
const toolFolderPath = path.dirname(foundToolPath)
|
const toolFolderPath = path.dirname(foundToolPath)
|
||||||
core.debug(`Tool Path: ${toolFolderPath}`)
|
|
||||||
|
|
||||||
// set the outputs for the action to the folder path of msbuild
|
// set the outputs for the action to the folder path of msbuild
|
||||||
core.setOutput('msbuildPath', toolFolderPath)
|
core.setOutput('msbuildPath', toolFolderPath)
|
||||||
|
|
||||||
// add tool path to PATH
|
// add tool path to PATH
|
||||||
core.addPath(toolFolderPath)
|
core.addPath(toolFolderPath)
|
||||||
|
core.debug(`Tool path added to PATH: ${toolFolderPath}`)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(error.message)
|
core.setFailed(error.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function installTool(): Promise<string> {
|
|
||||||
// cached tool was not found, retrieve it
|
|
||||||
core.debug(`Downloading vswhere-${VSWHERE_VERSION}`)
|
|
||||||
|
|
||||||
// using choco install we get proper tool and it automatically puts in the PATH
|
|
||||||
await exec.exec(
|
|
||||||
`choco install vswhere -y --no-progress -force -v --version=${VSWHERE_VERSION}`
|
|
||||||
)
|
|
||||||
|
|
||||||
// add the tool to the cache
|
|
||||||
const newCachedToolDirectory = await toolCache.cacheDir(
|
|
||||||
'C:\\ProgramData\\chocolatey\\lib\\vswhere\\tools',
|
|
||||||
'vswhere',
|
|
||||||
VSWHERE_VERSION
|
|
||||||
)
|
|
||||||
|
|
||||||
core.debug(`New cached tool directory=${newCachedToolDirectory}`)
|
|
||||||
|
|
||||||
return newCachedToolDirectory
|
|
||||||
}
|
|
||||||
|
|
||||||
run()
|
run()
|
||||||
|
Loading…
Reference in New Issue
Block a user