Skip to content

Commit 5cffd39

Browse files
committed
fix: use cross-spawn instead of @actions/exec
to support color and inputs
1 parent b263e79 commit 5cffd39

File tree

8 files changed

+30
-30
lines changed

8 files changed

+30
-30
lines changed

dist/setup_cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/setup_cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/chocolatey/chocolatey.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
/* eslint-disable require-atomic-updates */
2-
import { exec } from "@actions/exec"
2+
import spawn from "cross-spawn"
33
import { existsSync } from "fs"
44
import { dirname } from "path"
55
import which from "which"
66
import { InstallationInfo } from "../utils/setup/setupBin"
77

88
let binDir: string | undefined
99

10-
export async function setupChocolatey(
10+
export function setupChocolatey(
1111
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1212
_version: string,
1313
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1414
_setupCppDir: string,
1515
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1616
_arch: string
17-
): Promise<InstallationInfo | undefined> {
17+
): InstallationInfo | undefined {
1818
if (process.platform !== "win32") {
1919
return undefined
2020
}
@@ -30,9 +30,10 @@ export async function setupChocolatey(
3030
}
3131

3232
// https://docs.chocolatey.org/en-us/choco/setup#install-with-cmd.exe
33-
const exit = await exec(
34-
`@"%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\\chocolatey\\bin"`
35-
)
33+
const exit = spawn.sync(
34+
`@"%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\\chocolatey\\bin"`,
35+
{ stdio: "inherit" }
36+
).status
3637

3738
if (exit !== 0) {
3839
throw new Error(`Failed to install chocolatey`)

src/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,11 @@ export async function main(args: string[]): Promise<number> {
161161
if (installationInfo !== undefined) {
162162
successMessages.push(getSuccessMessage(tool, installationInfo))
163163
} else {
164-
successMessages.push(`${tool} was successfully installed`)
164+
successMessages.push(` ${tool} was successfully installed`)
165165
}
166166
} catch (e) {
167167
// push error message to the logger
168-
errorMessages.push(`${tool} failed to install`)
168+
errorMessages.push(` ${tool} failed to install`)
169169
}
170170
}
171171
}
@@ -229,7 +229,7 @@ function maybeGetInput(key: string) {
229229
}
230230

231231
function getSuccessMessage(tool: string, installationInfo: InstallationInfo) {
232-
let success = `${tool} was successfully installed`
232+
let success = ` ${tool} was successfully installed`
233233
if ("installDir" in installationInfo) {
234234
success += `\nThe installation direcotry is ${installationInfo.installDir}`
235235
}

src/utils/setup/setupAptPack.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,33 @@
11
/* eslint-disable require-atomic-updates */
2-
import { exec } from "@actions/exec"
2+
import spawn from "cross-spawn"
33
import { InstallationInfo } from "./setupBin"
44
import { mightSudo } from "./sudo"
55

66
let didUpdate: boolean = false
77

88
/** A function that installs a package using apt */
9-
export async function setupAptPack(
10-
name: string,
11-
version?: string,
12-
repository: boolean | string = true
13-
): Promise<InstallationInfo> {
9+
export function setupAptPack(name: string, version?: string, repository: boolean | string = true): InstallationInfo {
1410
const apt = mightSudo("apt-get")
1511

16-
let exit = 0
12+
let exit: number | null = 0
1713

1814
if (typeof repository === "string") {
19-
exit = await exec(mightSudo("add-apt-repository"), ["--update", repository])
15+
exit = spawn.sync(mightSudo("add-apt-repository"), ["--update", repository], { stdio: "inherit" }).status
2016
}
2117

2218
if (!didUpdate || repository === true) {
23-
await exec(apt, ["update"])
19+
exit = spawn.sync(apt, ["update"], { stdio: "inherit" }).status
2420
didUpdate = true
2521
}
2622

2723
if (version !== undefined && version !== "") {
2824
try {
29-
exit = await exec(apt, ["install", `${name}=${version}`])
25+
exit = spawn.sync(apt, ["install", `${name}=${version}`], { stdio: "inherit" }).status
3026
} catch {
31-
exit = await exec(apt, ["install", `${name}-${version}`])
27+
exit = spawn.sync(apt, ["install", `${name}-${version}`], { stdio: "inherit" }).status
3228
}
3329
} else {
34-
exit = await exec(apt, ["install", name])
30+
exit = spawn.sync(apt, ["install", name], { stdio: "inherit" }).status
3531
}
3632

3733
if (exit !== 0) {

src/utils/setup/setupBrewPack.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable require-atomic-updates */
2-
import { execFileSync } from "child_process"
2+
import spawn from "cross-spawn"
33
import which from "which"
44
import { setupBrew } from "../../brew/brew"
55
import { InstallationInfo } from "./setupBin"
@@ -14,7 +14,7 @@ export function setupBrewPack(name: string, version?: string): InstallationInfo
1414
}
1515

1616
// brew is not thread-safe
17-
execFileSync("brew", ["install", version !== undefined && version !== "" ? `${name}@${version}` : name], {
17+
spawn.sync("brew", ["install", version !== undefined && version !== "" ? `${name}@${version}` : name], {
1818
stdio: "inherit",
1919
})
2020

src/utils/setup/setupChocoPack.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* eslint-disable require-atomic-updates */
22
import { addPath } from "@actions/core"
3-
import { exec } from "@actions/exec"
43
import which from "which"
54
import { setupChocolatey } from "../../chocolatey/chocolatey"
65
import { InstallationInfo } from "./setupBin"
6+
import spawn from "cross-spawn"
77

88
let hasChoco = false
99

@@ -16,9 +16,9 @@ export async function setupChocoPack(name: string, version?: string, args: strin
1616

1717
let exit
1818
if (version !== undefined && version !== "") {
19-
exit = await exec("choco", ["install", "-y", name, `--version=${version}`, ...args])
19+
exit = spawn.sync("choco", ["install", "-y", name, `--version=${version}`, ...args], { stdio: "inherit" }).status
2020
} else {
21-
exit = await exec("choco", ["install", "-y", name, ...args])
21+
exit = spawn.sync("choco", ["install", "-y", name, ...args], { stdio: "inherit" }).status
2222
}
2323

2424
if (exit !== 0) {

src/utils/setup/setupPipPack.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable require-atomic-updates */
2-
import { exec, getExecOutput } from "@actions/exec"
2+
import { getExecOutput } from "@actions/exec"
3+
import spawn from "cross-spawn"
34
import which from "which"
45
import { addPath, info } from "@actions/core"
56
import { setupPython } from "../../python/python"
@@ -24,7 +25,9 @@ export async function setupPipPack(name: string, version?: string) {
2425
}
2526
}
2627

27-
const exit = await exec(pip, ["install", version !== undefined && version !== "" ? `${name}==${version}` : name])
28+
const exit = spawn.sync(pip, ["install", version !== undefined && version !== "" ? `${name}==${version}` : name], {
29+
stdio: "inherit",
30+
}).status
2831
if (exit !== 0) {
2932
throw new Error(`Failed to install ${name} ${version}`)
3033
}

0 commit comments

Comments
 (0)