-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #171 from cloudflare/cina/refactor-subprocess-exec
Refactor subprocess execution to use `@actions/exec`
- Loading branch information
Showing
6 changed files
with
166 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"wrangler-action": patch | ||
--- | ||
|
||
Fixed issues that caused the action to fail if any secret or var values contained shell metacharacters. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"wrangler-action": patch | ||
--- | ||
|
||
Bumped `DEFAULT_WRANGLER_VERSION` to 3.13.2 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { | ||
exec as _childProcessExec, | ||
type ExecException, | ||
} from "node:child_process"; | ||
import { EOL } from "node:os"; | ||
import { promisify } from "node:util"; | ||
|
||
export { exec } from "@actions/exec"; | ||
|
||
const childProcessExec = promisify(_childProcessExec); | ||
|
||
type ExecAsyncException = ExecException & { | ||
stderr: string; | ||
stdout: string; | ||
}; | ||
|
||
function isExecAsyncException(err: unknown): err is ExecAsyncException { | ||
return err instanceof Error && "code" in err && "stderr" in err; | ||
} | ||
|
||
export async function execShell( | ||
command: string, | ||
{ | ||
silent = false, | ||
...options | ||
}: Parameters<typeof childProcessExec>[1] & { silent?: boolean } = {}, | ||
) { | ||
if (!silent) { | ||
process.stdout.write("[command]" + command + EOL); | ||
} | ||
|
||
try { | ||
const promise = childProcessExec(command, { | ||
...options, | ||
}); | ||
|
||
const { child } = promise; | ||
|
||
if (!silent) { | ||
child.stdout?.on("data", (data: Buffer) => process.stdout.write(data)); | ||
child.stderr?.on("data", (data: Buffer) => process.stderr.write(data)); | ||
} | ||
|
||
await promise; | ||
return child.exitCode; | ||
} catch (err: any) { | ||
if (isExecAsyncException(err)) { | ||
process.stderr.write(err.stderr); | ||
throw new Error(`Process failed with exit code ${err.code}`); | ||
} | ||
|
||
throw err; | ||
} | ||
} |
Oops, something went wrong.