fix: create logging groups around the setup functions

This commit is contained in:
Amin Yahyaabadi 2022-02-13 15:43:21 -08:00
parent 630f785194
commit 969a124c7d
7 changed files with 28 additions and 4 deletions

2
dist/setup_cpp.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,7 @@
/* eslint-disable require-atomic-updates */
import { InstallationInfo } from "./setupBin"
import { execSudo } from "../exec/sudo"
import { endGroup, startGroup } from "@actions/core"
let didUpdate: boolean = false
let didInit: boolean = false
@ -11,6 +12,8 @@ export async function setupAptPack(
version?: string,
repositories: boolean | string[] = true
): Promise<InstallationInfo> {
startGroup(`Installing ${name} ${version ?? ""} via apt`)
const apt = "apt-get"
process.env.DEBIAN_FRONTEND = "noninteractive"
@ -55,5 +58,6 @@ export async function setupAptPack(
await execSudo(apt, ["install", "--fix-broken", "-y", name])
}
endGroup()
return { binDir: "/usr/bin/" }
}

View File

@ -1,5 +1,5 @@
import { find, downloadTool, cacheDir } from "@actions/tool-cache"
import { info } from "@actions/core"
import { endGroup, info, startGroup } from "@actions/core"
import { addPath } from "../path/addPath"
import { join } from "path"
import { existsSync } from "fs"
@ -45,6 +45,8 @@ export async function setupBin(
setupDir: string,
arch: string
): Promise<InstallationInfo> {
startGroup(`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")
@ -64,6 +66,8 @@ export async function setupBin(
if (existsSync(binDir) && existsSync(join(binDir, binFileName))) {
info(`${name} ${version} was found in the cache at ${binDir}.`)
addPath(binDir)
endGroup()
return { installDir, binDir }
}
}
@ -91,6 +95,7 @@ export async function setupBin(
const downloaded = await downloadTool(url)
await extractFunction?.(downloaded, setupDir)
} catch (err) {
endGroup()
throw new Error(`Failed to download ${name} ${version} ${arch}: ${err}`)
}
}
@ -105,5 +110,6 @@ export async function setupBin(
await cacheDir(setupDir, name, version)
}
endGroup()
return { installDir, binDir }
}

View File

@ -1,4 +1,5 @@
/* eslint-disable require-atomic-updates */
import { endGroup, startGroup } from "@actions/core"
import execa from "execa"
import which from "which"
import { setupBrew } from "../../brew/brew"
@ -8,6 +9,8 @@ let hasBrew = false
/** A function that installs a package using brew */
export function setupBrewPack(name: string, version?: string): InstallationInfo {
startGroup(`Installing ${name} ${version ?? ""} via brew`)
if (!hasBrew || which.sync("brew", { nothrow: true }) === null) {
setupBrew("", "", process.arch)
hasBrew = true
@ -18,5 +21,6 @@ export function setupBrewPack(name: string, version?: string): InstallationInfo
stdio: "inherit",
})
endGroup()
return { binDir: "/usr/local/bin/" }
}

View File

@ -4,11 +4,14 @@ import which from "which"
import { setupChocolatey } from "../../chocolatey/chocolatey"
import { InstallationInfo } from "./setupBin"
import execa from "execa"
import { endGroup, startGroup } from "@actions/core"
let hasChoco = false
/** A function that installs a package using choco */
export function setupChocoPack(name: string, version?: string, args: string[] = []): InstallationInfo {
startGroup(`Installing ${name} ${version ?? ""} via chocolatey`)
if (!hasChoco || which.sync("choco", { nothrow: true }) === null) {
setupChocolatey("", "", process.arch)
hasChoco = true
@ -34,5 +37,7 @@ export function setupChocoPack(name: string, version?: string, args: string[] =
const binDir = `${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin`
addPath(binDir)
endGroup()
return { binDir }
}

View File

@ -2,7 +2,7 @@
import { getExecOutput } from "@actions/exec"
import execa from "execa"
import which from "which"
import { info } from "@actions/core"
import { endGroup, info, startGroup } from "@actions/core"
import { addPath } from "../path/addPath"
import { setupPython } from "../../python/python"
import { isBinUptoDate } from "./version"
@ -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> {
startGroup(`Installing ${name} ${version ?? ""} via pip`)
// setup python and pip if needed
if (python === undefined) {
if (which.sync("python3", { nothrow: true }) !== null) {
@ -28,9 +30,11 @@ export async function setupPipPack(name: string, version?: string): Promise<Inst
await setupPython(getVersion("python", undefined), "", process.arch)
// try again
if (tried) {
endGroup()
throw new Error("Failed to install python")
}
tried = true
endGroup()
return setupPipPack(name, version)
}
}
@ -66,5 +70,6 @@ export async function setupPipPack(name: string, version?: string): Promise<Inst
addPath(binDir)
}
endGroup()
return { binDir }
}