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: remove custom proxy handling #143

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ jobs:

- uses: actions/setup-node@v4
with:
node-version-file: .node-version
node-version-file: package.json
cache: 'npm'

- run: npm ci
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ jobs:

- uses: actions/setup-node@v4
with:
node-version-file: .node-version
node-version-file: package.json
cache: 'npm'

- run: npm ci
1 change: 0 additions & 1 deletion .node-version

This file was deleted.

12,455 changes: 7,029 additions & 5,426 deletions dist/main.cjs

Large diffs are not rendered by default.

12,455 changes: 7,029 additions & 5,426 deletions dist/post.cjs

Large diffs are not rendered by default.

41 changes: 9 additions & 32 deletions lib/request.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,18 @@
import core from "@actions/core";
import { request } from "@octokit/request";
import { ProxyAgent, fetch as undiciFetch } from "undici";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we need to explicitly use EnvHttpProxyAgent?
https://github.com/nodejs/undici/blob/7f635e51f6170f4b59abedc7cb45e6bcda7f056d/docs/docs/api/EnvHttpProxyAgent.md#L4

See this comment: nodejs/undici#1650 (comment)

I just wanted to leave that not for when we have another look at it, I don't have time to dig into it now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that in 5cb4b2f, but several tests started failing as a result. After reading through nodejs/undici#2994, I got the impression it was unnecessary to do this.

Added EnvHttpProxyAgent and made it the default global dispatcher.

Automatically detect/support HTTP_PROXY, HTTPS_PROXY, & NO_PROXY

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super random drive-by comment. I got here from that issue. 😅

According to this commit, they ended up not using this as the default agent:
nodejs/undici@f31d3f9

Reasoning:
nodejs/undici#2994 (comment)

So it appears the PR description is wrong. Looks like they'll consider making it the default in a major release.

For now, I was able to get HTTPS_PROXY env variable to work via:

import { EnvHttpProxyAgent, setGlobalDispatcher } from "undici";

setGlobalDispatcher(new EnvHttpProxyAgent());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import { EnvHttpProxyAgent, setGlobalDispatcher } from "undici";

// Get the GitHub API URL from the action input and remove any trailing slash
const baseUrl = core.getInput("github-api-url").replace(/\/$/, "");

// https://docs.github.com/actions/hosting-your-own-runners/managing-self-hosted-runners/using-a-proxy-server-with-self-hosted-runners
const proxyUrl =
process.env.https_proxy ||
process.env.HTTPS_PROXY ||
process.env.http_proxy ||
process.env.HTTP_PROXY;

/* c8 ignore start */
// Native support for proxies in Undici is under consideration: https://github.com/nodejs/undici/issues/1650
// Until then, we need to use a custom fetch function to add proxy support.
const proxyFetch = (url, options) => {
const urlHost = new URL(url).hostname;
const noProxy = (process.env.no_proxy || process.env.NO_PROXY || "").split(
","
);

if (!noProxy.includes(urlHost)) {
options = {
...options,
dispatcher: new ProxyAgent(String(proxyUrl)),
};
}

return undiciFetch(url, options);
};
/* c8 ignore stop */
// Automatically detect/support proxy configuration from environment variables
// This may be the default global dispatcher in a future release of Node.js
// https://github.com/nodejs/node/issues/43187
const envHttpProxyAgent = new EnvHttpProxyAgent();
setGlobalDispatcher(envHttpProxyAgent);

// Configure the default settings for GitHub API requests
export default request.defaults({
headers: {
"user-agent": "actions/create-github-app-token",
},
headers: { "user-agent": "actions/create-github-app-token" },
baseUrl,
/* c8 ignore next */
request: proxyUrl ? { fetch: proxyFetch } : {},
});
1,231 changes: 460 additions & 771 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -4,9 +4,12 @@
"type": "module",
"version": "1.11.0",
"description": "GitHub Action for creating a GitHub App Installation Access Token",
"engines": {
"node": ">=20.16.0"
},
"scripts": {
"build": "esbuild main.js post.js --bundle --outdir=dist --out-extension:.js=.cjs --platform=node --target=node20.0.0 --packages=bundle",
"test": "c8 --100 ava tests/index.js",
"build": "esbuild main.js post.js --bundle --outdir=dist --out-extension:.js=.cjs --platform=node --target=node20 --packages=bundle",
"test": "c8 --100 ava tests/index.js NODE_OPTIONS=--disable-warning=UNDICI-EHPA",
"coverage": "c8 report --reporter html",
"postcoverage": "open-cli coverage/index.html"
},
@@ -16,7 +19,7 @@
"@octokit/auth-app": "^7.1.1",
"@octokit/request": "^9.1.3",
"p-retry": "^6.2.0",
"undici": "^6.19.8"
"undici": "^v7.0.0-alpha.3"
},
"devDependencies": {
"@sinonjs/fake-timers": "^13.0.2",
65 changes: 45 additions & 20 deletions tests/snapshots/index.js.md
Original file line number Diff line number Diff line change
@@ -20,7 +20,8 @@ Generated by [AVA](https://avajs.dev).

> stderr
''
`(node:93330) [UNDICI-EHPA] Warning: EnvHttpProxyAgent is experimental, expect them to change at any time.␊
(Use \`node --trace-warnings ...\` to show where the warning was created)`

> stdout
@@ -39,7 +40,9 @@ Generated by [AVA](https://avajs.dev).

> stderr
'Input required and not supplied: app-id'
`Input required and not supplied: app-id␊
(node:93340) [UNDICI-EHPA] Warning: EnvHttpProxyAgent is experimental, expect them to change at any time.␊
(Use \`node --trace-warnings ...\` to show where the warning was created)`

> stdout
@@ -49,7 +52,9 @@ Generated by [AVA](https://avajs.dev).

> stderr
'GITHUB_REPOSITORY_OWNER missing, must be set to \'<owner>\''
`GITHUB_REPOSITORY_OWNER missing, must be set to '<owner>'␊
(node:93349) [UNDICI-EHPA] Warning: EnvHttpProxyAgent is experimental, expect them to change at any time.␊
(Use \`node --trace-warnings ...\` to show where the warning was created)`

> stdout
@@ -59,7 +64,9 @@ Generated by [AVA](https://avajs.dev).

> stderr
'Input required and not supplied: private-key'
`Input required and not supplied: private-key␊
(node:93358) [UNDICI-EHPA] Warning: EnvHttpProxyAgent is experimental, expect them to change at any time.␊
(Use \`node --trace-warnings ...\` to show where the warning was created)`

> stdout
@@ -69,7 +76,9 @@ Generated by [AVA](https://avajs.dev).

> stderr
'GITHUB_REPOSITORY missing, must be set to \'<owner>/<repo>\''
`GITHUB_REPOSITORY missing, must be set to '<owner>/<repo>'␊
(node:93367) [UNDICI-EHPA] Warning: EnvHttpProxyAgent is experimental, expect them to change at any time.␊
(Use \`node --trace-warnings ...\` to show where the warning was created)`

> stdout
@@ -79,7 +88,8 @@ Generated by [AVA](https://avajs.dev).

> stderr
''
`(node:93376) [UNDICI-EHPA] Warning: EnvHttpProxyAgent is experimental, expect them to change at any time.␊
(Use \`node --trace-warnings ...\` to show where the warning was created)`

> stdout
@@ -98,7 +108,9 @@ Generated by [AVA](https://avajs.dev).

> stderr
`'Issued at' claim ('iat') must be an Integer representing the time that the assertion was issued.␊
`(node:93385) [UNDICI-EHPA] Warning: EnvHttpProxyAgent is experimental, expect them to change at any time.␊
(Use \`node --trace-warnings ...\` to show where the warning was created)␊
'Issued at' claim ('iat') must be an Integer representing the time that the assertion was issued.␊
[@octokit/auth-app] GitHub API time and system time are different by 30 seconds. Retrying request with the difference accounted for.`

> stdout
@@ -118,7 +130,8 @@ Generated by [AVA](https://avajs.dev).

> stderr
''
`(node:93394) [UNDICI-EHPA] Warning: EnvHttpProxyAgent is experimental, expect them to change at any time.␊
(Use \`node --trace-warnings ...\` to show where the warning was created)`

> stdout
@@ -138,7 +151,8 @@ Generated by [AVA](https://avajs.dev).

> stderr
''
`(node:93403) [UNDICI-EHPA] Warning: EnvHttpProxyAgent is experimental, expect them to change at any time.␊
(Use \`node --trace-warnings ...\` to show where the warning was created)`

> stdout
@@ -158,7 +172,8 @@ Generated by [AVA](https://avajs.dev).

> stderr
''
`(node:93412) [UNDICI-EHPA] Warning: EnvHttpProxyAgent is experimental, expect them to change at any time.␊
(Use \`node --trace-warnings ...\` to show where the warning was created)`

> stdout
@@ -177,7 +192,8 @@ Generated by [AVA](https://avajs.dev).

> stderr
''
`(node:93421) [UNDICI-EHPA] Warning: EnvHttpProxyAgent is experimental, expect them to change at any time.␊
(Use \`node --trace-warnings ...\` to show where the warning was created)`

> stdout
@@ -196,7 +212,8 @@ Generated by [AVA](https://avajs.dev).

> stderr
''
`(node:93430) [UNDICI-EHPA] Warning: EnvHttpProxyAgent is experimental, expect them to change at any time.␊
(Use \`node --trace-warnings ...\` to show where the warning was created)`

> stdout
@@ -215,7 +232,8 @@ Generated by [AVA](https://avajs.dev).

> stderr
''
`(node:93439) [UNDICI-EHPA] Warning: EnvHttpProxyAgent is experimental, expect them to change at any time.␊
(Use \`node --trace-warnings ...\` to show where the warning was created)`

> stdout
@@ -234,7 +252,8 @@ Generated by [AVA](https://avajs.dev).

> stderr
''
`(node:93448) [UNDICI-EHPA] Warning: EnvHttpProxyAgent is experimental, expect them to change at any time.␊
(Use \`node --trace-warnings ...\` to show where the warning was created)`

> stdout
@@ -253,7 +272,8 @@ Generated by [AVA](https://avajs.dev).

> stderr
''
`(node:93457) [UNDICI-EHPA] Warning: EnvHttpProxyAgent is experimental, expect them to change at any time.␊
(Use \`node --trace-warnings ...\` to show where the warning was created)`

> stdout
@@ -272,7 +292,8 @@ Generated by [AVA](https://avajs.dev).

> stderr
''
`(node:93466) [UNDICI-EHPA] Warning: EnvHttpProxyAgent is experimental, expect them to change at any time.␊
(Use \`node --trace-warnings ...\` to show where the warning was created)`

> stdout
@@ -282,7 +303,8 @@ Generated by [AVA](https://avajs.dev).

> stderr
''
`(node:93475) [UNDICI-EHPA] Warning: EnvHttpProxyAgent is experimental, expect them to change at any time.␊
(Use \`node --trace-warnings ...\` to show where the warning was created)`

> stdout
@@ -292,7 +314,8 @@ Generated by [AVA](https://avajs.dev).

> stderr
''
`(node:93484) [UNDICI-EHPA] Warning: EnvHttpProxyAgent is experimental, expect them to change at any time.␊
(Use \`node --trace-warnings ...\` to show where the warning was created)`

> stdout
@@ -302,7 +325,8 @@ Generated by [AVA](https://avajs.dev).

> stderr
''
`(node:93493) [UNDICI-EHPA] Warning: EnvHttpProxyAgent is experimental, expect them to change at any time.␊
(Use \`node --trace-warnings ...\` to show where the warning was created)`

> stdout
@@ -312,7 +336,8 @@ Generated by [AVA](https://avajs.dev).

> stderr
''
`(node:93502) [UNDICI-EHPA] Warning: EnvHttpProxyAgent is experimental, expect them to change at any time.␊
(Use \`node --trace-warnings ...\` to show where the warning was created)`

> stdout
Binary file modified tests/snapshots/index.js.snap
Binary file not shown.