forked from actions/create-github-app-token
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add proxy support (actions#102)
Adds support for the following environment variables: - `https_proxy` - `HTTPS_PROXY` - `http_proxy` - `HTTP_PROXY` - `no_proxy` - `NO_PROXY`
- Loading branch information
1 parent
1f18aab
commit 1f82f7d
Showing
8 changed files
with
34,737 additions
and
67 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,41 @@ | ||
import core from "@actions/core"; | ||
import { request } from "@octokit/request"; | ||
import { ProxyAgent, fetch as undiciFetch } from "undici"; | ||
|
||
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 */ | ||
|
||
export default request.defaults({ | ||
headers: { | ||
"user-agent": "actions/create-github-app-token", | ||
}, | ||
baseUrl, | ||
/* c8 ignore next */ | ||
request: proxyUrl ? { fetch: proxyFetch } : {}, | ||
}); |
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
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
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