Skip to content

Commit

Permalink
Merge pull request #37 from aminya/more-logging [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya authored Feb 14, 2022
2 parents 630f785 + 4b250a3 commit 5397b1a
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 24 deletions.
2 changes: 1 addition & 1 deletion dist/setup_cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/setup_cpp.js.map

Large diffs are not rendered by default.

22 changes: 13 additions & 9 deletions src/chocolatey/chocolatey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,19 @@ export function setupChocolatey(
}

// https://docs.chocolatey.org/en-us/choco/setup#install-with-cmd.exe
execa.sync(powershell, [
"-NoProfile",
"-InputFormat",
"None",
"-ExecutionPolicy",
"Bypass",
"-Command",
"[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))",
])
execa.sync(
powershell,
[
"-NoProfile",
"-InputFormat",
"None",
"-ExecutionPolicy",
"Bypass",
"-Command",
"[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))",
],
{ stdio: "inherit" }
)

const chocoPath = `${process.env.ALLUSERSPROFILE}\\chocolatey\\bin`
addPath(chocoPath)
Expand Down
4 changes: 2 additions & 2 deletions src/kcov/kcov.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ function getKcovPackageInfo(version: string): PackageInfo {
// await setupCmake("3.22.0", join(untildify(""), "cmake"), "")
await setupAptPack("libdw-dev")
await setupAptPack("libcurl4-openssl-dev")
await execa("cmake", ["-S", "./", "-B", "./build"], { cwd: out })
await execa("cmake", ["--build", "./build", "--config", "Release"], { cwd: out })
await execa("cmake", ["-S", "./", "-B", "./build"], { cwd: out, stdio: "inherit" })
await execa("cmake", ["--build", "./build", "--config", "Release"], { cwd: out, stdio: "inherit" })
await execSudo("cmake", ["--install", "./build"], out)
return out
},
Expand Down
14 changes: 10 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { setupVCVarsall } from "./vcvarsall/vcvarsall"
import { setupKcov } from "./kcov/kcov"
import { addEnv } from "./utils/env/addEnv"
import { setupSevenZip } from "./sevenzip/sevenzip"
import { endGroup, startGroup } from "@actions/core"

/** The setup functions */
const setups = {
Expand Down Expand Up @@ -125,22 +126,23 @@ export async function main(args: string[]): Promise<number> {
// loop over the tools and run their setup function
for (const tool of tools) {
// get the version or "true" or undefined for this tool from the options
const value = opts[tool]
const version = opts[tool]

// skip if undefined
if (value !== undefined) {
if (version !== undefined) {
// running the setup function for this tool
startGroup(`Installing ${tool} ${version}`)
try {
let installationInfo: InstallationInfo | undefined | void
if (tool === "vcvarsall") {
// eslint-disable-next-line no-await-in-loop
setupVCVarsall(getVersion(tool, value), undefined, arch, undefined, undefined, false, false)
setupVCVarsall(getVersion(tool, version), undefined, arch, undefined, undefined, false, false)
} else {
// get the setup function
const setupFunction = setups[tool]

// eslint-disable-next-line no-await-in-loop
installationInfo = await setupFunction(getVersion(tool, value), join(setupCppDir, tool), arch)
installationInfo = await setupFunction(getVersion(tool, version), join(setupCppDir, tool), arch)
}
// preparing a report string
successMessages.push(getSuccessMessage(tool, installationInfo))
Expand All @@ -149,6 +151,7 @@ export async function main(args: string[]): Promise<number> {
error(e as string | Error)
errorMessages.push(`${tool} failed to install`)
}
endGroup()
}
}

Expand All @@ -159,6 +162,7 @@ export async function main(args: string[]): Promise<number> {
const { compiler, version } = getCompilerInfo(maybeCompiler)

// install the compiler. We allow some aliases for the compiler name
startGroup(`Installing ${compiler} ${version ?? ""}`)
switch (compiler) {
case "llvm":
case "clang":
Expand Down Expand Up @@ -198,10 +202,12 @@ export async function main(args: string[]): Promise<number> {
errorMessages.push(`Unsupported compiler ${compiler}`)
}
}
endGroup()
}
} catch (e) {
error(e as string | Error)
errorMessages.push(`Failed to install the ${maybeCompiler}`)
endGroup()
}

if (successMessages.length === 0 && errorMessages.length === 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/exec/powershell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export function execPowershell(command: string) {
throw new Error("Could not find powershell")
}

execa.sync(powershell, ["-c", command])
execa.sync(powershell, ["-c", command], { stdio: "inherit" })
}
2 changes: 1 addition & 1 deletion src/utils/exec/sudo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export function execSudo(file: string, args: string[], cwd?: string) {
stdio: "inherit",
})
} else {
return execa(file, args)
return execa(file, args, { stdio: "inherit" })
}
}
4 changes: 2 additions & 2 deletions src/utils/setup/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function extractExe(file: string, dest: string) {
sevenZip = "7z"
}

await execa(sevenZip, ["x", file, `-o${dest}`])
await execa(sevenZip, ["x", file, `-o${dest}`], { stdio: "inherit" })
return dest
}

Expand All @@ -26,6 +26,6 @@ export async function extractTarByExe(file: string, dest: string, flags = ["--st
} catch {
// ignore
}
await execa("tar", ["xf", file, "-C", dest, ...flags])
await execa("tar", ["xf", file, "-C", dest, ...flags], { stdio: "inherit" })
return dest
}
3 changes: 3 additions & 0 deletions src/utils/setup/setupAptPack.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable require-atomic-updates */
import { InstallationInfo } from "./setupBin"
import { execSudo } from "../exec/sudo"
import { info } from "@actions/core"

let didUpdate: boolean = false
let didInit: boolean = false
Expand All @@ -11,6 +12,8 @@ export async function setupAptPack(
version?: string,
repositories: boolean | string[] = true
): Promise<InstallationInfo> {
info(`Installing ${name} ${version ?? ""} via apt`)

const apt = "apt-get"

process.env.DEBIAN_FRONTEND = "noninteractive"
Expand Down
3 changes: 3 additions & 0 deletions src/utils/setup/setupBin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export async function setupBin(
setupDir: string,
arch: string
): Promise<InstallationInfo> {
info(`Installing ${name} ${version} ${arch} via direct downloading`)

process.env.RUNNER_TEMP = process.env.RUNNER_TEMP ?? tmpdir()
process.env.RUNNER_TOOL_CACHE = process.env.RUNNER_TOOL_CACHE ?? join(tmpdir(), "setup-cpp", "hostedtoolcache")

Expand All @@ -64,6 +66,7 @@ export async function setupBin(
if (existsSync(binDir) && existsSync(join(binDir, binFileName))) {
info(`${name} ${version} was found in the cache at ${binDir}.`)
addPath(binDir)

return { installDir, binDir }
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/utils/setup/setupBrewPack.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable require-atomic-updates */
import { info } from "@actions/core"
import execa from "execa"
import which from "which"
import { setupBrew } from "../../brew/brew"
Expand All @@ -8,6 +9,8 @@ let hasBrew = false

/** A function that installs a package using brew */
export function setupBrewPack(name: string, version?: string): InstallationInfo {
info(`Installing ${name} ${version ?? ""} via brew`)

if (!hasBrew || which.sync("brew", { nothrow: true }) === null) {
setupBrew("", "", process.arch)
hasBrew = true
Expand Down
4 changes: 4 additions & 0 deletions src/utils/setup/setupChocoPack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import which from "which"
import { setupChocolatey } from "../../chocolatey/chocolatey"
import { InstallationInfo } from "./setupBin"
import execa from "execa"
import { info } from "@actions/core"

let hasChoco = false

/** A function that installs a package using choco */
export function setupChocoPack(name: string, version?: string, args: string[] = []): InstallationInfo {
info(`Installing ${name} ${version ?? ""} via chocolatey`)

if (!hasChoco || which.sync("choco", { nothrow: true }) === null) {
setupChocolatey("", "", process.arch)
hasChoco = true
Expand All @@ -34,5 +37,6 @@ export function setupChocoPack(name: string, version?: string, args: string[] =

const binDir = `${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin`
addPath(binDir)

return { binDir }
}
4 changes: 3 additions & 1 deletion src/utils/setup/setupPipPack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ let tried = false

/** A function that installs a package using pip */
export async function setupPipPack(name: string, version?: string): Promise<InstallationInfo> {
info(`Installing ${name} ${version ?? ""} via pip`)

// setup python and pip if needed
if (python === undefined) {
if (which.sync("python3", { nothrow: true }) !== null) {
Expand All @@ -36,7 +38,7 @@ export async function setupPipPack(name: string, version?: string): Promise<Inst
}
if (process.platform === "win32") {
// https://github.com/pypa/pip/issues/10875#issuecomment-1030293005
execa.sync(python, ["-m", "pip", "install", "-U", "pip==21.3.1"])
execa.sync(python, ["-m", "pip", "install", "-U", "pip==21.3.1"], { stdio: "inherit" })
}

execa.sync(python, ["-m", "pip", "install", version !== undefined && version !== "" ? `${name}==${version}` : name], {
Expand Down
4 changes: 2 additions & 2 deletions src/vcpkg/vcpkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ export async function setupVcpkg(_version: string, setupDir: string, _arch: stri
}

if (!existsSync(join(setupDir, addShellExtension("bootstrap-vcpkg")))) {
execa.sync("git", ["clone", "https://github.com/microsoft/vcpkg"], { cwd: dirname(setupDir) })
execa.sync("git", ["clone", "https://github.com/microsoft/vcpkg"], { cwd: dirname(setupDir), stdio: "inherit" })
} else {
warning(`Vcpkg folder already exists at ${setupDir}`)
}

execa.sync(addShellExtension(addShellHere("bootstrap-vcpkg")), { cwd: setupDir, shell: true })
execa.sync(addShellExtension(addShellHere("bootstrap-vcpkg")), { cwd: setupDir, shell: true, stdio: "inherit" })
addPath(setupDir)
// eslint-disable-next-line require-atomic-updates
hasVCPKG = true
Expand Down

0 comments on commit 5397b1a

Please sign in to comment.