-
Notifications
You must be signed in to change notification settings - Fork 115
WIP proxy support #284
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
base: beta
Are you sure you want to change the base?
WIP proxy support #284
Changes from 4 commits
473bd6e
38b2e04
7830ec2
b024073
e8f719d
470e131
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,32 +15,58 @@ if (!process.env.GITHUB_REPOSITORY_OWNER) { | |||||||||||||||||||||||||||
| throw new Error("GITHUB_REPOSITORY_OWNER missing, must be set to '<owner>'"); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const appId = core.getInput("app-id"); | ||||||||||||||||||||||||||||
| const privateKey = core.getInput("private-key"); | ||||||||||||||||||||||||||||
| const owner = core.getInput("owner"); | ||||||||||||||||||||||||||||
| const repositories = core | ||||||||||||||||||||||||||||
| .getInput("repositories") | ||||||||||||||||||||||||||||
| .split(/[\n,]+/) | ||||||||||||||||||||||||||||
| .map((s) => s.trim()) | ||||||||||||||||||||||||||||
| .filter((x) => x !== ""); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const skipTokenRevoke = core.getBooleanInput("skip-token-revoke"); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const permissions = getPermissionsFromInputs(process.env); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // Export promise for testing | ||||||||||||||||||||||||||||
| export default main( | ||||||||||||||||||||||||||||
| appId, | ||||||||||||||||||||||||||||
| privateKey, | ||||||||||||||||||||||||||||
| owner, | ||||||||||||||||||||||||||||
| repositories, | ||||||||||||||||||||||||||||
| permissions, | ||||||||||||||||||||||||||||
| core, | ||||||||||||||||||||||||||||
| createAppAuth, | ||||||||||||||||||||||||||||
| request, | ||||||||||||||||||||||||||||
| skipTokenRevoke, | ||||||||||||||||||||||||||||
| ).catch((error) => { | ||||||||||||||||||||||||||||
| /* c8 ignore next 3 */ | ||||||||||||||||||||||||||||
| console.error(error); | ||||||||||||||||||||||||||||
| core.setFailed(error.message); | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
| async function run() { | ||||||||||||||||||||||||||||
| // spawn a child process if proxy is set | ||||||||||||||||||||||||||||
| const httpProxyEnvVars = [ | ||||||||||||||||||||||||||||
| "https_proxy", | ||||||||||||||||||||||||||||
| "HTTPS_PROXY", | ||||||||||||||||||||||||||||
| "http_proxy", | ||||||||||||||||||||||||||||
| "HTTP_PROXY", | ||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||
| const nodeHasProxySupportEnabled = process.env.NODE_USE_ENV_PROXY === "1"; | ||||||||||||||||||||||||||||
| const shouldUseProxy = httpProxyEnvVars.some((v) => process.env[v]); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (!nodeHasProxySupportEnabled && shouldUseProxy) { | ||||||||||||||||||||||||||||
| const { spawn } = await import("node:child_process"); | ||||||||||||||||||||||||||||
| // spawn itself with NODE_USE_ENV_PROXY=1 | ||||||||||||||||||||||||||||
| const child = spawn(process.execPath, process.argv.slice(1), { | ||||||||||||||||||||||||||||
| env: { ...process.env, NODE_USE_ENV_PROXY: "1" }, | ||||||||||||||||||||||||||||
| stdio: "inherit", | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
| child.on("exit", (code) => process.exit(code)); | ||||||||||||||||||||||||||||
| // TODO: return promise that resolves once sub process exits (for testing) | ||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
| child.on("exit", (code) => process.exit(code)); | |
| // TODO: return promise that resolves once sub process exits (for testing) | |
| return; | |
| // Return a promise that resolves once sub process exits (for testing) | |
| return new Promise((resolve, reject) => { | |
| child.on("exit", (code) => { | |
| process.exit(code); | |
| resolve(code); | |
| }); | |
| child.on("error", (err) => { | |
| reject(err); | |
| }); | |
| }); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,21 @@ | ||||||
| import test from "node:test"; | ||||||
|
|
||||||
| test("spawns a child process if proxy is set and NODE_USE_ENV_PROXY is not set", async (t) => { | ||||||
| // https://nodejs.org/api/test.html#class-mocktracker | ||||||
| // TODO: why u not work | ||||||
|
||||||
| // TODO: why u not work | |
| // TODO: Mock not working as expected |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exit code could be null when the child process is terminated by a signal. This should handle null values:
child.on('exit', (code) => process.exit(code || 1));