fix: use execa instead of cross-spawn and @action/exec

This commit is contained in:
Amin Yahyaabadi 2021-09-18 08:13:23 -05:00
parent a70ed6421c
commit 9bef371233
11 changed files with 31 additions and 70 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

@ -43,6 +43,7 @@
"@actions/exec": "^1.1.0", "@actions/exec": "^1.1.0",
"@actions/io": "^1.1.1", "@actions/io": "^1.1.1",
"@actions/tool-cache": "^1.7.1", "@actions/tool-cache": "^1.7.1",
"execa": "^5.1.1",
"hasha": "^5.2.2", "hasha": "^5.2.2",
"mri": "^1.2.0", "mri": "^1.2.0",
"semver": "^7.3.5", "semver": "^7.3.5",

View File

@ -21,6 +21,7 @@ importers:
cross-env: 7.0.3 cross-env: 7.0.3
cross-spawn: ^7.0.3 cross-spawn: ^7.0.3
eslint-config-atomic: ^1.16.2 eslint-config-atomic: ^1.16.2
execa: ^5.1.1
hasha: ^5.2.2 hasha: ^5.2.2
jest: ^27.2.0 jest: ^27.2.0
mri: ^1.2.0 mri: ^1.2.0
@ -39,6 +40,7 @@ importers:
'@actions/exec': 1.1.0 '@actions/exec': 1.1.0
'@actions/io': 1.1.1 '@actions/io': 1.1.1
'@actions/tool-cache': 1.7.1 '@actions/tool-cache': 1.7.1
execa: 5.1.1
hasha: 5.2.2 hasha: 5.2.2
mri: 1.2.0 mri: 1.2.0
semver: 7.3.5 semver: 7.3.5
@ -2829,7 +2831,6 @@ packages:
path-key: 3.1.1 path-key: 3.1.1
shebang-command: 2.0.0 shebang-command: 2.0.0
which: 2.0.2 which: 2.0.2
dev: true
/crypto-browserify/3.12.0: /crypto-browserify/3.12.0:
resolution: {integrity: sha512-fz4spIh+znjO2VjL+IdhEpRJ3YN6sMzITSBijk6FK2UvTqruSQW+/cCZTSNsMiZNvUeq0CqurF+dAbyiGOY6Wg==} resolution: {integrity: sha512-fz4spIh+znjO2VjL+IdhEpRJ3YN6sMzITSBijk6FK2UvTqruSQW+/cCZTSNsMiZNvUeq0CqurF+dAbyiGOY6Wg==}
@ -3890,7 +3891,6 @@ packages:
onetime: 5.1.2 onetime: 5.1.2
signal-exit: 3.0.3 signal-exit: 3.0.3
strip-final-newline: 2.0.0 strip-final-newline: 2.0.0
dev: true
/exit-on-epipe/1.0.1: /exit-on-epipe/1.0.1:
resolution: {integrity: sha512-h2z5mrROTxce56S+pnvAV890uu7ls7f1kEvVGJbw1OlFH3/mlJ5bkXu0KRyW94v37zzHPiUd55iLn3DA7TjWpw==} resolution: {integrity: sha512-h2z5mrROTxce56S+pnvAV890uu7ls7f1kEvVGJbw1OlFH3/mlJ5bkXu0KRyW94v37zzHPiUd55iLn3DA7TjWpw==}
@ -4231,7 +4231,6 @@ packages:
/get-stream/6.0.1: /get-stream/6.0.1:
resolution: {integrity: sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==} resolution: {integrity: sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==}
engines: {node: '>=10'} engines: {node: '>=10'}
dev: true
/get-symbol-description/1.0.0: /get-symbol-description/1.0.0:
resolution: {integrity: sha512-2EmdH1YvIQiZpltCNgkuiUnyukzxM/R6NDJX31Ke3BG1Nq5b0S2PhX59UKi9vZpPDQVdqn+1IcaAwnzTT5vCjw==} resolution: {integrity: sha512-2EmdH1YvIQiZpltCNgkuiUnyukzxM/R6NDJX31Ke3BG1Nq5b0S2PhX59UKi9vZpPDQVdqn+1IcaAwnzTT5vCjw==}
@ -4565,7 +4564,6 @@ packages:
/human-signals/2.1.0: /human-signals/2.1.0:
resolution: {integrity: sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==} resolution: {integrity: sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==}
engines: {node: '>=10.17.0'} engines: {node: '>=10.17.0'}
dev: true
/iconv-lite/0.4.24: /iconv-lite/0.4.24:
resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==} resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==}
@ -5988,7 +5986,6 @@ packages:
/merge-stream/2.0.0: /merge-stream/2.0.0:
resolution: {integrity: sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==} resolution: {integrity: sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==}
dev: true
/merge2/1.4.1: /merge2/1.4.1:
resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==} resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==}
@ -6066,7 +6063,6 @@ packages:
/mimic-fn/2.1.0: /mimic-fn/2.1.0:
resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==} resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==}
engines: {node: '>=6'} engines: {node: '>=6'}
dev: true
/minimalistic-assert/1.0.1: /minimalistic-assert/1.0.1:
resolution: {integrity: sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==} resolution: {integrity: sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==}
@ -6246,7 +6242,6 @@ packages:
engines: {node: '>=8'} engines: {node: '>=8'}
dependencies: dependencies:
path-key: 3.1.1 path-key: 3.1.1
dev: true
/nth-check/2.0.0: /nth-check/2.0.0:
resolution: {integrity: sha512-i4sc/Kj8htBrAiH1viZ0TgU8Y5XqCaV/FziYK6TBczxmeKm3AEFWqqF3195yKudrarqy7Zu80Ra5dobFjn9X/Q==} resolution: {integrity: sha512-i4sc/Kj8htBrAiH1viZ0TgU8Y5XqCaV/FziYK6TBczxmeKm3AEFWqqF3195yKudrarqy7Zu80Ra5dobFjn9X/Q==}
@ -6367,7 +6362,6 @@ packages:
engines: {node: '>=6'} engines: {node: '>=6'}
dependencies: dependencies:
mimic-fn: 2.1.0 mimic-fn: 2.1.0
dev: true
/open/7.4.2: /open/7.4.2:
resolution: {integrity: sha512-MVHddDVweXZF3awtlAS+6pgKLlm/JgxZ90+/NBurBoQctVOOB/zDdVjcyPzQ+0laDGbsWgrRkflI65sQeOgT9Q==} resolution: {integrity: sha512-MVHddDVweXZF3awtlAS+6pgKLlm/JgxZ90+/NBurBoQctVOOB/zDdVjcyPzQ+0laDGbsWgrRkflI65sQeOgT9Q==}
@ -6592,7 +6586,6 @@ packages:
/path-key/3.1.1: /path-key/3.1.1:
resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==} resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==}
engines: {node: '>=8'} engines: {node: '>=8'}
dev: true
/path-parse/1.0.7: /path-parse/1.0.7:
resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==} resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==}
@ -7663,7 +7656,6 @@ packages:
engines: {node: '>=8'} engines: {node: '>=8'}
dependencies: dependencies:
shebang-regex: 3.0.0 shebang-regex: 3.0.0
dev: true
/shebang-regex/1.0.0: /shebang-regex/1.0.0:
resolution: {integrity: sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=} resolution: {integrity: sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=}
@ -7673,7 +7665,6 @@ packages:
/shebang-regex/3.0.0: /shebang-regex/3.0.0:
resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==} resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==}
engines: {node: '>=8'} engines: {node: '>=8'}
dev: true
/shell-quote/1.7.2: /shell-quote/1.7.2:
resolution: {integrity: sha512-mRz/m/JVscCrkMyPqHc/bczi3OQHkLTqXHEFu0zDhK/qfv3UcOA4SVmRCLmos4bhjr9ekVQubj/R7waKapmiQg==} resolution: {integrity: sha512-mRz/m/JVscCrkMyPqHc/bczi3OQHkLTqXHEFu0zDhK/qfv3UcOA4SVmRCLmos4bhjr9ekVQubj/R7waKapmiQg==}
@ -7714,7 +7705,6 @@ packages:
/signal-exit/3.0.3: /signal-exit/3.0.3:
resolution: {integrity: sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==} resolution: {integrity: sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==}
dev: true
/sisteransi/1.0.5: /sisteransi/1.0.5:
resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==} resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==}
@ -7994,7 +7984,6 @@ packages:
/strip-final-newline/2.0.0: /strip-final-newline/2.0.0:
resolution: {integrity: sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==} resolution: {integrity: sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==}
engines: {node: '>=6'} engines: {node: '>=6'}
dev: true
/strip-json-comments/1.0.4: /strip-json-comments/1.0.4:
resolution: {integrity: sha1-HhX7ysl9Pumb8tc7TGVrCCu6+5E=} resolution: {integrity: sha1-HhX7ysl9Pumb8tc7TGVrCCu6+5E=}

View File

@ -1,5 +1,5 @@
/* eslint-disable require-atomic-updates */ /* eslint-disable require-atomic-updates */
import spawn from "cross-spawn" import execa from "execa"
import { existsSync } from "fs" import { existsSync } from "fs"
import { dirname } from "path" import { dirname } from "path"
import which from "which" import which from "which"
@ -30,14 +30,9 @@ export function setupChocolatey(
} }
// https://docs.chocolatey.org/en-us/choco/setup#install-with-cmd.exe // https://docs.chocolatey.org/en-us/choco/setup#install-with-cmd.exe
const exit = spawn.sync( execa.commandSync(
`@"%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"`, `@"%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"`
{ stdio: "inherit" } )
).status
if (exit !== 0) {
throw new Error(`Failed to install chocolatey`)
}
const maybeChoco = which.sync("choco", { nothrow: true }) const maybeChoco = which.sync("choco", { nothrow: true })
if (maybeChoco !== null) { if (maybeChoco !== null) {

View File

@ -1,7 +1,7 @@
import { addPath as ghAddPath } from "@actions/core" import { addPath as ghAddPath } from "@actions/core"
import { delimiter } from "path" import { delimiter } from "path"
import * as core from "@actions/core" import * as core from "@actions/core"
import { exec } from "@actions/exec" import execa from "execa"
/** An add path function that works locally or inside GitHub Actions */ /** An add path function that works locally or inside GitHub Actions */
export async function addPath(path: string) { export async function addPath(path: string) {
@ -11,13 +11,13 @@ export async function addPath(path: string) {
core.error(err as Error) core.error(err as Error)
switch (process.platform) { switch (process.platform) {
case "win32": { case "win32": {
await exec(`setx PATH=${path};%PATH%`) await execa(`setx PATH=${path};%PATH%`)
break break
} }
case "linux": case "linux":
case "darwin": { case "darwin": {
await exec(`echo "export PATH=${path}:$PATH" >> ~/.profile`) await execa.command(`echo "export PATH=${path}:$PATH" >> ~/.profile`)
await exec(`source ~/.profile`) await execa.command(`source ~/.profile`)
core.info(`${path} was added to ~/.profile`) core.info(`${path} was added to ~/.profile`)
break break
} }

View File

@ -1,12 +1,9 @@
import { exec } from "@actions/exec" import execa from "execa"
import { mkdirP } from "@actions/io" import { mkdirP } from "@actions/io"
export { extractTar, extractXar, extract7z, extractZip } from "@actions/tool-cache" export { extractTar, extractXar, extract7z, extractZip } from "@actions/tool-cache"
export async function extractExe(file: string, dest: string) { export async function extractExe(file: string, dest: string) {
const exit = await exec("7z", ["x", file, `-o${dest}`]) await execa("7z", ["x", file, `-o${dest}`])
if (exit !== 0) {
throw new Error(`Failed to extract ${file} to ${dest} with 7z`)
}
return dest return dest
} }
@ -16,9 +13,6 @@ export async function extractTarByExe(file: string, dest: string, flags = ["--st
} catch { } catch {
// ignore // ignore
} }
const exit = await exec("tar", ["xf", file, "-C", dest, ...flags]) await execa("tar", ["xf", file, "-C", dest, ...flags])
if (exit !== 0) {
throw new Error(`Failed to extract ${file} to ${dest} with tar`)
}
return dest return dest
} }

View File

@ -1,7 +1,7 @@
/* eslint-disable require-atomic-updates */ /* eslint-disable require-atomic-updates */
import { exec } from "@actions/exec" import execa from "execa"
import { InstallationInfo } from "./setupBin" import { InstallationInfo } from "./setupBin"
import { mightSudo } from "./sudo" // import { mightSudo } from "./sudo"
let didUpdate: boolean = false let didUpdate: boolean = false
@ -11,31 +11,25 @@ export async function setupAptPack(
version?: string, version?: string,
repository: boolean | string = true repository: boolean | string = true
): Promise<InstallationInfo> { ): Promise<InstallationInfo> {
const apt = mightSudo("apt-get") const apt = "apt-get" // mightSudo
let exit: number | null = 0
if (typeof repository === "string") { if (typeof repository === "string") {
exit = await exec(mightSudo("add-apt-repository"), ["--update", "-y", repository]) await execa("add-apt-repository", ["--update", "-y", repository])
} }
if (!didUpdate || repository === true) { if (!didUpdate || repository === true) {
exit = await exec(apt, ["update", "-y"]) await execa(apt, ["update", "-y"])
didUpdate = true didUpdate = true
} }
if (version !== undefined && version !== "") { if (version !== undefined && version !== "") {
try { try {
exit = await exec(apt, ["install", "-y", `${name}=${version}`]) await execa(apt, ["install", "-y", `${name}=${version}`])
} catch { } catch {
exit = await exec(apt, ["install", "-y", `${name}-${version}`]) await execa(apt, ["install", "-y", `${name}-${version}`])
} }
} else { } else {
exit = await exec(apt, ["install", "-y", name]) await execa(apt, ["install", "-y", name])
}
if (exit !== 0) {
throw new Error(`Failed to install ${name} ${version}`)
} }
return { binDir: "/usr/bin/" } return { binDir: "/usr/bin/" }

View File

@ -1,5 +1,5 @@
/* eslint-disable require-atomic-updates */ /* eslint-disable require-atomic-updates */
import spawn from "cross-spawn" import execa from "execa"
import which from "which" import which from "which"
import { setupBrew } from "../../brew/brew" import { setupBrew } from "../../brew/brew"
import { InstallationInfo } from "./setupBin" import { InstallationInfo } from "./setupBin"
@ -14,9 +14,7 @@ export function setupBrewPack(name: string, version?: string): InstallationInfo
} }
// brew is not thread-safe // brew is not thread-safe
spawn.sync("brew", ["install", version !== undefined && version !== "" ? `${name}@${version}` : name], { execa.sync("brew", ["install", version !== undefined && version !== "" ? `${name}@${version}` : name])
stdio: "inherit",
})
return { binDir: "/usr/local/bin/" } return { binDir: "/usr/local/bin/" }
} }

View File

@ -3,7 +3,7 @@ import { addPath } from "../path/addPath"
import which from "which" import which from "which"
import { setupChocolatey } from "../../chocolatey/chocolatey" import { setupChocolatey } from "../../chocolatey/chocolatey"
import { InstallationInfo } from "./setupBin" import { InstallationInfo } from "./setupBin"
import spawn from "cross-spawn" import execa from "execa"
let hasChoco = false let hasChoco = false
@ -14,15 +14,10 @@ export async function setupChocoPack(name: string, version?: string, args: strin
hasChoco = true hasChoco = true
} }
let exit
if (version !== undefined && version !== "") { if (version !== undefined && version !== "") {
exit = spawn.sync("choco", ["install", "-y", name, `--version=${version}`, ...args], { stdio: "inherit" }).status execa.sync("choco", ["install", "-y", name, `--version=${version}`, ...args])
} else { } else {
exit = spawn.sync("choco", ["install", "-y", name, ...args], { stdio: "inherit" }).status execa.sync("choco", ["install", "-y", name, ...args])
}
if (exit !== 0) {
throw new Error(`Failed to install ${name} ${version}`)
} }
const binDir = "C:/ProgramData/Chocolatey/bin/" const binDir = "C:/ProgramData/Chocolatey/bin/"

View File

@ -1,6 +1,6 @@
/* eslint-disable require-atomic-updates */ /* eslint-disable require-atomic-updates */
import { getExecOutput } from "@actions/exec" import { getExecOutput } from "@actions/exec"
import spawn from "cross-spawn" import execa from "execa"
import which from "which" import which from "which"
import { info } from "@actions/core" import { info } from "@actions/core"
import { addPath } from "../path/addPath" import { addPath } from "../path/addPath"
@ -26,12 +26,7 @@ export async function setupPipPack(name: string, version?: string) {
} }
} }
const exit = spawn.sync(pip, ["install", version !== undefined && version !== "" ? `${name}==${version}` : name], { execa.sync(pip, ["install", version !== undefined && version !== "" ? `${name}==${version}` : name])
stdio: "inherit",
}).status
if (exit !== 0) {
throw new Error(`Failed to install ${name} ${version}`)
}
if (binDir === undefined) { if (binDir === undefined) {
if (process.platform === "linux") { if (process.platform === "linux") {