mirror of https://github.com/actions/toolkit
takost/update-github-package
parent
774f139bef
commit
f699b96ecf
|
@ -1,6 +1,7 @@
|
||||||
import * as http from 'http'
|
import * as http from 'http'
|
||||||
import * as https from 'https'
|
import * as https from 'https'
|
||||||
import proxy from 'proxy'
|
import { ProxyServer, createProxy } from "proxy";
|
||||||
|
import { ProxyAgent, fetch as undiciFetch } from "undici";
|
||||||
|
|
||||||
// Default values are set when the module is imported, so we need to set proxy first.
|
// Default values are set when the module is imported, so we need to set proxy first.
|
||||||
const proxyUrl = 'http://127.0.0.1:8081'
|
const proxyUrl = 'http://127.0.0.1:8081'
|
||||||
|
@ -16,7 +17,7 @@ describe('@actions/github', () => {
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
// Start proxy server
|
// Start proxy server
|
||||||
proxyServer = proxy()
|
proxyServer = createProxy()
|
||||||
await new Promise<void>(resolve => {
|
await new Promise<void>(resolve => {
|
||||||
const port = Number(proxyUrl.split(':')[2])
|
const port = Number(proxyUrl.split(':')[2])
|
||||||
proxyServer.listen(port, () => resolve())
|
proxyServer.listen(port, () => resolve())
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import * as http from 'http'
|
import * as http from 'http'
|
||||||
import proxy from 'proxy'
|
import { createProxy } from 'proxy'
|
||||||
import {getOctokit} from '../src/github'
|
import {getOctokit} from '../src/github'
|
||||||
import {GitHub, getOctokitOptions} from '../src/utils'
|
import {GitHub, getOctokitOptions} from '../src/utils'
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ describe('@actions/github', () => {
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
// Start proxy server
|
// Start proxy server
|
||||||
proxyServer = proxy()
|
proxyServer = createProxy()
|
||||||
await new Promise<void>(resolve => {
|
await new Promise<void>(resolve => {
|
||||||
const port = Number(proxyUrl.split(':')[2])
|
const port = Number(proxyUrl.split(':')[2])
|
||||||
proxyServer.listen(port, () => resolve())
|
proxyServer.listen(port, () => resolve())
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@actions/github",
|
"name": "@actions/github",
|
||||||
"version": "5.1.1",
|
"version": "6.0.0",
|
||||||
"description": "Actions github lib",
|
"description": "Actions github lib",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"github",
|
"github",
|
||||||
|
@ -38,12 +38,14 @@
|
||||||
"url": "https://github.com/actions/toolkit/issues"
|
"url": "https://github.com/actions/toolkit/issues"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/http-client": "^2.0.1",
|
"@actions/http-client": "file:../actions-http-client-3.0.1.tgz",
|
||||||
"@octokit/core": "^3.6.0",
|
"@octokit/core": "^4.2.4",
|
||||||
"@octokit/plugin-paginate-rest": "^2.17.0",
|
"@octokit/plugin-paginate-rest": "^6.1.2",
|
||||||
"@octokit/plugin-rest-endpoint-methods": "^5.13.0"
|
"@octokit/plugin-rest-endpoint-methods": "^7.2.3",
|
||||||
|
"undici": "^5.25.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"proxy": "^1.0.2"
|
"@types/proxy": "^1.0.1",
|
||||||
|
"proxy": "^2.1.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import * as http from 'http'
|
import * as http from 'http'
|
||||||
import * as httpClient from '@actions/http-client'
|
import * as httpClient from '@actions/http-client'
|
||||||
import {OctokitOptions} from '@octokit/core/dist-types/types'
|
import {OctokitOptions} from '@octokit/core/dist-types/types'
|
||||||
|
import { ProxyAgent, Agent, fetch as undiciFetch } from "undici";
|
||||||
|
|
||||||
export function getAuthString(
|
export function getAuthString(
|
||||||
token: string,
|
token: string,
|
||||||
|
@ -20,6 +21,22 @@ export function getProxyAgent(destinationUrl: string): http.Agent {
|
||||||
return hc.getAgent(destinationUrl)
|
return hc.getAgent(destinationUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getProxyAgentDispatcher(destinationUrl: string): ProxyAgent | undefined {
|
||||||
|
const hc = new httpClient.HttpClient()
|
||||||
|
return hc.getAgentDispatcher(destinationUrl)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getProxyFetch(destinationUrl): any {
|
||||||
|
const httpAgent = getProxyAgentDispatcher(destinationUrl)
|
||||||
|
const proxyFetch: typeof undiciFetch = (url, opts) => {
|
||||||
|
return undiciFetch(url, {
|
||||||
|
...opts,
|
||||||
|
dispatcher: httpAgent,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
return proxyFetch;
|
||||||
|
}
|
||||||
|
|
||||||
export function getApiBaseUrl(): string {
|
export function getApiBaseUrl(): string {
|
||||||
return process.env['GITHUB_API_URL'] || 'https://api.github.com'
|
return process.env['GITHUB_API_URL'] || 'https://api.github.com'
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,8 @@ const baseUrl = Utils.getApiBaseUrl()
|
||||||
export const defaults: OctokitOptions = {
|
export const defaults: OctokitOptions = {
|
||||||
baseUrl,
|
baseUrl,
|
||||||
request: {
|
request: {
|
||||||
agent: Utils.getProxyAgent(baseUrl)
|
agent: Utils.getProxyAgent(baseUrl),
|
||||||
|
fetch: Utils.getProxyFetch(baseUrl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -299,7 +299,7 @@ describe('proxy', () => {
|
||||||
it('proxy settings return ProxyAgent', async () => {
|
it('proxy settings return ProxyAgent', async () => {
|
||||||
process.env['https_proxy'] = 'http://127.0.0.1:8080'
|
process.env['https_proxy'] = 'http://127.0.0.1:8080'
|
||||||
const httpClient = new httpm.HttpClient()
|
const httpClient = new httpm.HttpClient()
|
||||||
const agent: Agent | ProxyAgent = httpClient.getAgentDispatcher('https://some-url')
|
const agent = httpClient.getAgentDispatcher('https://some-url')
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log(agent)
|
console.log(agent)
|
||||||
expect(agent instanceof ProxyAgent).toBe(true)
|
expect(agent instanceof ProxyAgent).toBe(true)
|
||||||
|
@ -307,10 +307,10 @@ describe('proxy', () => {
|
||||||
|
|
||||||
it('proxyAuth is set in tunnel agent when authentication is provided', async () => {
|
it('proxyAuth is set in tunnel agent when authentication is provided', async () => {
|
||||||
const httpClient = new httpm.HttpClient()
|
const httpClient = new httpm.HttpClient()
|
||||||
const agent: Agent | ProxyAgent = httpClient.getAgentDispatcher('https://some-url')
|
const agent = httpClient.getAgentDispatcher('https://some-url')
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log(agent)
|
console.log(agent)
|
||||||
expect(agent instanceof Agent).toBe(true)
|
expect(agent).toBe(undefined)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@actions/http-client",
|
"name": "@actions/http-client",
|
||||||
"version": "3.0.0",
|
"version": "3.0.1",
|
||||||
"description": "Actions Http Client",
|
"description": "Actions Http Client",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"github",
|
"github",
|
||||||
|
|
|
@ -567,16 +567,14 @@ export class HttpClient {
|
||||||
return this._getAgent(parsedUrl)
|
return this._getAgent(parsedUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
getAgentDispatcher(serverUrl: string): ProxyAgent | Agent {
|
getAgentDispatcher(serverUrl: string): ProxyAgent | undefined {
|
||||||
const parsedUrl = new URL(serverUrl)
|
const parsedUrl = new URL(serverUrl)
|
||||||
const proxyUrl = pm.getProxyUrl(parsedUrl)
|
const proxyUrl = pm.getProxyUrl(parsedUrl)
|
||||||
const useProxy = proxyUrl && proxyUrl.hostname
|
const useProxy = proxyUrl && proxyUrl.hostname
|
||||||
if (useProxy) {
|
if (useProxy) {
|
||||||
return this._getProxyAgentDispatcher(parsedUrl, proxyUrl)
|
return this._getProxyAgentDispatcher(parsedUrl, proxyUrl)
|
||||||
}
|
}
|
||||||
else {
|
return;
|
||||||
return this._getAgentDispatcher(parsedUrl)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _prepareRequest(
|
private _prepareRequest(
|
||||||
|
@ -763,46 +761,6 @@ export class HttpClient {
|
||||||
return proxyAgent
|
return proxyAgent
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getAgentDispatcher(parsedUrl: URL): Agent {
|
|
||||||
let agent;
|
|
||||||
|
|
||||||
if (this._keepAlive) {
|
|
||||||
agent = this._agentDispatcher
|
|
||||||
}
|
|
||||||
|
|
||||||
// if agent is already assigned use that agent.
|
|
||||||
if (agent) {
|
|
||||||
return agent
|
|
||||||
}
|
|
||||||
|
|
||||||
const usingSsl = parsedUrl.protocol === 'https:'
|
|
||||||
let maxSockets = 100
|
|
||||||
if (this.requestOptions) {
|
|
||||||
maxSockets = this.requestOptions.maxSockets || http.globalAgent.maxSockets
|
|
||||||
}
|
|
||||||
|
|
||||||
// if reusing agent across request and tunneling agent isn't assigned create a new agent
|
|
||||||
if (!agent) {
|
|
||||||
agent = new Agent(
|
|
||||||
{
|
|
||||||
pipelining: (!this._keepAlive ? 0 : 1),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
this._agentDispatcher = agent
|
|
||||||
}
|
|
||||||
|
|
||||||
if (usingSsl && this._ignoreSslError) {
|
|
||||||
// we don't want to set NODE_TLS_REJECT_UNAUTHORIZED=0 since that will affect request for entire process
|
|
||||||
// http.RequestOptions doesn't expose a way to modify RequestOptions.agent.options
|
|
||||||
// we have to cast it to any and change it directly
|
|
||||||
agent.options = Object.assign(agent.options.connect || {}, {
|
|
||||||
rejectUnauthorized: false
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return agent
|
|
||||||
}
|
|
||||||
|
|
||||||
private async _performExponentialBackoff(retryNumber: number): Promise<void> {
|
private async _performExponentialBackoff(retryNumber: number): Promise<void> {
|
||||||
retryNumber = Math.min(ExponentialBackoffCeiling, retryNumber)
|
retryNumber = Math.min(ExponentialBackoffCeiling, retryNumber)
|
||||||
const ms: number = ExponentialBackoffTimeSlice * Math.pow(2, retryNumber)
|
const ms: number = ExponentialBackoffTimeSlice * Math.pow(2, retryNumber)
|
||||||
|
|
Loading…
Reference in New Issue