feat: add proxy support (#102)
Adds support for the following environment variables: - `https_proxy` - `HTTPS_PROXY` - `http_proxy` - `HTTP_PROXY` - `no_proxy` - `NO_PROXY`
This commit is contained in:
Vendored
+17352
-31
File diff suppressed because one or more lines are too long
Vendored
+17344
-23
File diff suppressed because one or more lines are too long
@@ -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 } : {},
|
||||
});
|
||||
|
||||
@@ -31,8 +31,6 @@ const skipTokenRevoke = Boolean(
|
||||
core.getInput("skip-token-revoke") || core.getInput("skip_token_revoke")
|
||||
);
|
||||
|
||||
const baseUrl = core.getInput("github-api-url").replace(/\/$/, "");
|
||||
|
||||
main(
|
||||
appId,
|
||||
privateKey,
|
||||
@@ -40,7 +38,7 @@ main(
|
||||
repositories,
|
||||
core,
|
||||
createAppAuth,
|
||||
request.defaults({ baseUrl }),
|
||||
request,
|
||||
skipTokenRevoke
|
||||
).catch((error) => {
|
||||
/* c8 ignore next 3 */
|
||||
|
||||
Generated
+2
-4
@@ -12,7 +12,8 @@
|
||||
"@actions/core": "^1.10.1",
|
||||
"@octokit/auth-app": "^6.0.3",
|
||||
"@octokit/request": "^8.1.6",
|
||||
"p-retry": "^6.2.0"
|
||||
"p-retry": "^6.2.0",
|
||||
"undici": "^6.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sinonjs/fake-timers": "^11.2.2",
|
||||
@@ -22,7 +23,6 @@
|
||||
"esbuild": "^0.20.0",
|
||||
"execa": "^8.0.1",
|
||||
"open-cli": "^8.0.0",
|
||||
"undici": "^6.6.0",
|
||||
"yaml": "^2.3.4"
|
||||
}
|
||||
},
|
||||
@@ -421,7 +421,6 @@
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.0.0.tgz",
|
||||
"integrity": "sha512-JUFJad5lv7jxj926GPgymrWQxxjPYuJNiNjNMzqT+HiuP6Vl3dk5xzG+8sTX96np0ZAluvaMzPsjhHZ5rNuNQQ==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
}
|
||||
@@ -3522,7 +3521,6 @@
|
||||
"version": "6.6.0",
|
||||
"resolved": "https://registry.npmjs.org/undici/-/undici-6.6.0.tgz",
|
||||
"integrity": "sha512-p8VvLAgnx6g9pydV0GG/kciSx3ZCq5PLeEU4yefjoZCc1HSeiMxbrFzYIZlgSMrX3l0CoTJ37C6edu13acE40A==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@fastify/busboy": "^2.0.0"
|
||||
},
|
||||
|
||||
+2
-2
@@ -15,7 +15,8 @@
|
||||
"@actions/core": "^1.10.1",
|
||||
"@octokit/auth-app": "^6.0.3",
|
||||
"@octokit/request": "^8.1.6",
|
||||
"p-retry": "^6.2.0"
|
||||
"p-retry": "^6.2.0",
|
||||
"undici": "^6.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sinonjs/fake-timers": "^11.2.2",
|
||||
@@ -25,7 +26,6 @@
|
||||
"esbuild": "^0.20.0",
|
||||
"execa": "^8.0.1",
|
||||
"open-cli": "^8.0.0",
|
||||
"undici": "^6.6.0",
|
||||
"yaml": "^2.3.4"
|
||||
},
|
||||
"release": {
|
||||
|
||||
@@ -5,9 +5,7 @@ import core from "@actions/core";
|
||||
import { post } from "./lib/post.js";
|
||||
import request from "./lib/request.js";
|
||||
|
||||
const baseUrl = core.getInput("github-api-url").replace(/\/$/, "");
|
||||
|
||||
post(core, request.defaults({ baseUrl })).catch((error) => {
|
||||
post(core, request).catch((error) => {
|
||||
/* c8 ignore next 3 */
|
||||
console.error(error);
|
||||
core.setFailed(error.message);
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ export const DEFAULT_ENV = {
|
||||
GITHUB_REPOSITORY_OWNER: "actions",
|
||||
GITHUB_REPOSITORY: "actions/create-github-app-token",
|
||||
// inputs are set as environment variables with the prefix INPUT_
|
||||
// https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#example-specifying-inputs
|
||||
// https://docs.github.com/actions/creating-actions/metadata-syntax-for-github-actions#example-specifying-inputs
|
||||
"INPUT_GITHUB-API-URL": "https://api.github.com",
|
||||
"INPUT_APP-ID": "123456",
|
||||
// This key is invalidated. It’s from https://github.com/octokit/auth-app.js/issues/465#issuecomment-1564998327.
|
||||
|
||||
Reference in New Issue
Block a user