2022-01-03 08:53:37 +01:00
|
|
|
import * as core from '@actions/core'
|
2024-02-22 11:25:13 +01:00
|
|
|
import * as semver from 'semver'
|
2022-01-03 08:53:37 +01:00
|
|
|
import {execSync} from 'child_process'
|
|
|
|
import {existsSync} from 'fs'
|
2023-02-13 10:07:39 +01:00
|
|
|
import {VERSION_DEV} from './constants'
|
2022-01-03 08:53:37 +01:00
|
|
|
|
|
|
|
// Keep in sync with https://github.com/actions/virtual-environments
|
|
|
|
const KNOWN_VISUAL_STUDIO_INSTALLATIONS = [
|
2022-12-23 09:44:36 +01:00
|
|
|
'C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise', // 'windows-2022' and 'windows-latest'
|
|
|
|
'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise', // 'windows-2019'
|
|
|
|
'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise' // 'windows-2016' (deprecated and removed)
|
2022-01-03 08:53:37 +01:00
|
|
|
]
|
2022-12-23 09:44:36 +01:00
|
|
|
if (process.env['VSINSTALLDIR']) {
|
|
|
|
// if VSINSTALLDIR is set, make it the first known installation
|
|
|
|
KNOWN_VISUAL_STUDIO_INSTALLATIONS.unshift(
|
|
|
|
process.env['VSINSTALLDIR'].replace(/\\$/, '')
|
|
|
|
)
|
|
|
|
}
|
|
|
|
const VCVARSALL_SUBPATH = 'VC\\Auxiliary\\Build\\vcvarsall.bat'
|
2022-01-03 08:53:37 +01:00
|
|
|
|
|
|
|
function findVcvarsallPath(): string {
|
|
|
|
for (const installation of KNOWN_VISUAL_STUDIO_INSTALLATIONS) {
|
2022-12-23 09:44:36 +01:00
|
|
|
const candidate = `${installation}\\${VCVARSALL_SUBPATH}`
|
2022-01-03 08:53:37 +01:00
|
|
|
if (existsSync(candidate)) {
|
|
|
|
return candidate
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new Error('Failed to find vcvarsall.bat')
|
|
|
|
}
|
|
|
|
|
2024-03-12 12:30:08 +01:00
|
|
|
export function needsWindowsEnvironmentSetup(
|
|
|
|
javaVersion: string,
|
|
|
|
graalVMVersion: string,
|
|
|
|
isGraalVMforJDK17OrLater: boolean
|
|
|
|
): boolean {
|
|
|
|
if (javaVersion === VERSION_DEV || graalVMVersion === VERSION_DEV) {
|
|
|
|
return false // no longer required in dev builds
|
|
|
|
} else if (isGraalVMforJDK17OrLater) {
|
|
|
|
return false // no longer required in GraalVM for JDK 17 and later.
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-02-22 11:25:13 +01:00
|
|
|
export function setUpWindowsEnvironment(
|
|
|
|
javaVersion: string,
|
2024-03-11 22:34:51 +01:00
|
|
|
graalVMVersion: string,
|
|
|
|
isGraalVMforJDK17OrLater: boolean
|
2024-02-22 11:25:13 +01:00
|
|
|
): void {
|
2024-03-12 12:30:08 +01:00
|
|
|
if (
|
|
|
|
!needsWindowsEnvironmentSetup(
|
|
|
|
javaVersion,
|
|
|
|
graalVMVersion,
|
|
|
|
isGraalVMforJDK17OrLater
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
return
|
2024-02-22 11:25:13 +01:00
|
|
|
}
|
2023-02-13 10:07:39 +01:00
|
|
|
|
2022-01-03 08:53:37 +01:00
|
|
|
core.startGroup('Updating Windows environment...')
|
|
|
|
|
|
|
|
const vcvarsallPath = findVcvarsallPath()
|
|
|
|
core.debug(`Calling "${vcvarsallPath}"...`)
|
|
|
|
const [originalEnv, vcvarsallOutput, updatedEnv] = execSync(
|
|
|
|
`set && cls && "${vcvarsallPath}" x64 && cls && set`,
|
|
|
|
{shell: 'cmd'}
|
|
|
|
)
|
|
|
|
.toString()
|
|
|
|
.split('\f') // form feed page break (printed by `cls`)
|
|
|
|
core.debug(vcvarsallOutput)
|
|
|
|
|
|
|
|
const originalEnvMap = new Map<string, string>()
|
|
|
|
for (const line of originalEnv.split('\r\n')) {
|
|
|
|
if (line.includes('=')) {
|
|
|
|
const [name, value] = line.split('=')
|
|
|
|
originalEnvMap.set(name, value)
|
|
|
|
} else if (line) {
|
|
|
|
core.debug(`Skipping ${line} (does not include '=')...`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const line of updatedEnv.split('\r\n')) {
|
|
|
|
if (line.includes('=')) {
|
|
|
|
const [name, value] = line.split('=')
|
|
|
|
const originalValue = originalEnvMap.get(name)
|
|
|
|
if (value !== originalValue) {
|
|
|
|
core.exportVariable(name, value)
|
|
|
|
core.debug(`"${name}" set to "${value}"`)
|
|
|
|
}
|
|
|
|
} else if (line) {
|
|
|
|
core.debug(`Skipping ${line} (does not include '=')...`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
core.endGroup()
|
|
|
|
}
|