From f57ea8787c522dd5912cb9acb3635725e920aa49 Mon Sep 17 00:00:00 2001 From: Parker Brown <17183625+parkerbxyz@users.noreply.github.com> Date: Fri, 22 Aug 2025 13:43:20 -0700 Subject: [PATCH] Move proxy setup to request.js and update entrypoint Proxy environment setup previously in bootstrap.js is now handled in lib/request.js for better encapsulation. The action entrypoint is updated from dist/bootstrap.cjs to dist/main.cjs, and bootstrap.js is removed. Build script is updated to exclude bootstrap.js. --- action.yml | 2 +- bootstrap.js | 7 ------- lib/request.js | 22 ++++++++++++++++++++++ package.json | 2 +- 4 files changed, 24 insertions(+), 9 deletions(-) delete mode 100644 bootstrap.js diff --git a/action.yml b/action.yml index 2b5d045..2461e2a 100644 --- a/action.yml +++ b/action.yml @@ -133,5 +133,5 @@ outputs: description: "GitHub App slug" runs: using: "node24" - main: "dist/bootstrap.cjs" + main: "dist/main.cjs" post: "dist/post.cjs" diff --git a/bootstrap.js b/bootstrap.js deleted file mode 100644 index 123b816..0000000 --- a/bootstrap.js +++ /dev/null @@ -1,7 +0,0 @@ -// Enable env-based proxy support unless caller explicitly set NODE_USE_ENV_PROXY -if (process.env.NODE_USE_ENV_PROXY == null) { - process.env.NODE_USE_ENV_PROXY = 1; -} - -// Import main after environment prepared. Using dynamic import so this executes first even when bundled. -import("./main.js"); diff --git a/lib/request.js b/lib/request.js index 14bd74f..a46ff9b 100644 --- a/lib/request.js +++ b/lib/request.js @@ -1,6 +1,28 @@ import core from "@actions/core"; import { request } from "@octokit/request"; +/* c8 ignore start -- proxy setup depends on external runner env */ +// Ensure env-based proxying for Node core agents unless explicitly disabled. +if (process.env.NODE_USE_ENV_PROXY == null) { + process.env.NODE_USE_ENV_PROXY = "1"; +} +// Attempt to configure undici global dispatcher (used by octokit under the hood) +// if a proxy environment variable is present. Failures are non-fatal. +const __proxyUrl = + process.env.HTTPS_PROXY || process.env.HTTP_PROXY || process.env.ALL_PROXY; +if (__proxyUrl) { + (async () => { + try { + const { setGlobalDispatcher, ProxyAgent } = await import("undici"); + setGlobalDispatcher(new ProxyAgent(__proxyUrl)); + } catch (e) { + // eslint-disable-next-line no-console + console.warn("Proxy setup failed:", e.message); + } + })(); +} +/* c8 ignore stop */ + // Get the GitHub API URL from the action input and remove any trailing slash const baseUrl = core.getInput("github-api-url").replace(/\/$/, ""); diff --git a/package.json b/package.json index 2123f18..928ab6d 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "node": ">=24.4.0" }, "scripts": { - "build": "esbuild bootstrap.js main.js post.js --bundle --outdir=dist --out-extension:.js=.cjs --platform=node --packages=bundle", + "build": "esbuild main.js post.js --bundle --outdir=dist --out-extension:.js=.cjs --platform=node --packages=bundle", "test": "c8 --100 ava tests/index.js", "coverage": "c8 report --reporter html", "postcoverage": "open-cli coverage/index.html"