Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use shell matching platform when running scripts #5034

Merged
merged 6 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/src/plugins/exec/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ execProvider.addHandler("prepareEnvironment", async ({ ctx, log }) => {
}

throw new RuntimeError({
message: `exec provider init script exited with code ${error.exitCode}`,
message: dedent`exec provider init script exited with code ${error.exitCode}. Script output:
${error.all}`,
detail: {
exitCode: error.exitCode,
stdout: error.stdout,
Expand Down
53 changes: 23 additions & 30 deletions core/src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -709,40 +709,33 @@ export async function runScript({
script: string
envVars?: PrimitiveMap
}) {
envVars = envVars || {}

// Workaround for https://github.com/vercel/pkg/issues/897
envVars.PKG_EXECPATH = ""

// Run the script, capturing any errors
const proc = execa("bash", ["-s"], {
all: true,
cwd,
// The script is piped to stdin
input: script,
// Set a very large max buffer (we only hold one of these at a time, and want to avoid overflow errors)
buffer: true,
maxBuffer: 100 * 1024 * 1024,
env: toEnvVars(envVars || {}),
const env = toEnvVars(envVars || {})
const outputStream = split2()
outputStream.on("error", (line: Buffer) => {
log.error(line.toString())
})

// Stream output to `log`, splitting by line
const stdout = split2()
const stderr = split2()

stdout.on("error", () => {})
stdout.on("data", (line: Buffer) => {
outputStream.on("data", (line: Buffer) => {
log.info(line.toString())
})
stderr.on("error", () => {})
stderr.on("data", (line: Buffer) => {
log.info(line.toString())
const errorStream = split2()
errorStream.on("error", (line: Buffer) => {
log.error(line.toString())
})

proc.stdout!.pipe(stdout)
proc.stderr!.pipe(stderr)

return await proc
errorStream.on("data", (line: Buffer) => {
log.error(line.toString())
})
// Workaround for https://github.com/vercel/pkg/issues/897
env.PKG_EXECPATH = ""
// script can be either a command or path to an executable
// shell script since we use the shell option.
const result = await exec(script, [], {
shell: true,
cwd,
env,
stdout: outputStream,
stderr: errorStream,
})
return result
}

export async function streamToString(stream: Readable) {
Expand Down