mirror of
https://github.com/erlef/setup-beam.git
synced 2026-07-31 11:06:09 +00:00
Use @actions/http-client (#195)
This commit is contained in:
committed by
GitHub
parent
c2e02f777c
commit
94b8820fed
Vendored
+44
-41
@@ -2461,6 +2461,10 @@ function checkBypass(reqUrl) {
|
|||||||
if (!reqUrl.hostname) {
|
if (!reqUrl.hostname) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
const reqHost = reqUrl.hostname;
|
||||||
|
if (isLoopbackAddress(reqHost)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
const noProxy = process.env['no_proxy'] || process.env['NO_PROXY'] || '';
|
const noProxy = process.env['no_proxy'] || process.env['NO_PROXY'] || '';
|
||||||
if (!noProxy) {
|
if (!noProxy) {
|
||||||
return false;
|
return false;
|
||||||
@@ -2486,13 +2490,24 @@ function checkBypass(reqUrl) {
|
|||||||
.split(',')
|
.split(',')
|
||||||
.map(x => x.trim().toUpperCase())
|
.map(x => x.trim().toUpperCase())
|
||||||
.filter(x => x)) {
|
.filter(x => x)) {
|
||||||
if (upperReqHosts.some(x => x === upperNoProxyItem)) {
|
if (upperNoProxyItem === '*' ||
|
||||||
|
upperReqHosts.some(x => x === upperNoProxyItem ||
|
||||||
|
x.endsWith(`.${upperNoProxyItem}`) ||
|
||||||
|
(upperNoProxyItem.startsWith('.') &&
|
||||||
|
x.endsWith(`${upperNoProxyItem}`)))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
exports.checkBypass = checkBypass;
|
exports.checkBypass = checkBypass;
|
||||||
|
function isLoopbackAddress(host) {
|
||||||
|
const hostLower = host.toLowerCase();
|
||||||
|
return (hostLower === 'localhost' ||
|
||||||
|
hostLower.startsWith('127.') ||
|
||||||
|
hostLower.startsWith('[::1]') ||
|
||||||
|
hostLower.startsWith('[0:0:0:0:0:0:0:1]'));
|
||||||
|
}
|
||||||
//# sourceMappingURL=proxy.js.map
|
//# sourceMappingURL=proxy.js.map
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
@@ -7193,10 +7208,10 @@ module.exports = {
|
|||||||
|
|
||||||
const core = __nccwpck_require__(2186)
|
const core = __nccwpck_require__(2186)
|
||||||
const { exec } = __nccwpck_require__(1514)
|
const { exec } = __nccwpck_require__(1514)
|
||||||
|
const http = __nccwpck_require__(6255)
|
||||||
const os = __nccwpck_require__(2037)
|
const os = __nccwpck_require__(2037)
|
||||||
const path = __nccwpck_require__(1017)
|
const path = __nccwpck_require__(1017)
|
||||||
const semver = __nccwpck_require__(1383)
|
const semver = __nccwpck_require__(1383)
|
||||||
const https = __nccwpck_require__(5687)
|
|
||||||
const fs = __nccwpck_require__(7147)
|
const fs = __nccwpck_require__(7147)
|
||||||
const installer = __nccwpck_require__(2127)
|
const installer = __nccwpck_require__(2127)
|
||||||
|
|
||||||
@@ -7606,51 +7621,39 @@ function getRunnerOSVersion() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function get(url0, pageIdxs) {
|
async function get(url0, pageIdxs) {
|
||||||
function getPage(pageIdx) {
|
async function getPage(pageIdx) {
|
||||||
return new Promise((resolve, reject) => {
|
const url = new URL(url0)
|
||||||
const url = new URL(url0)
|
const headers = {}
|
||||||
const headers = {
|
const GithubToken = getInput('github-token', false)
|
||||||
'user-agent': 'setup-beam',
|
|
||||||
}
|
|
||||||
const GithubToken = getInput('github-token', false)
|
|
||||||
|
|
||||||
if (GithubToken) {
|
if (GithubToken && url.host === 'api.github.com') {
|
||||||
headers.authorization = `Bearer ${GithubToken}`
|
headers.authorization = `Bearer ${GithubToken}`
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pageIdx !== null) {
|
if (pageIdx !== null) {
|
||||||
url.searchParams.append('page', pageIdx)
|
url.searchParams.append('page', pageIdx)
|
||||||
}
|
}
|
||||||
https
|
|
||||||
.get(url, { headers }, (res) => {
|
const httpClient = new http.HttpClient('setup-beam', [], {
|
||||||
let data = ''
|
allowRetries: true,
|
||||||
res.on('data', (chunk) => {
|
maxRetries: 3,
|
||||||
data += chunk
|
|
||||||
})
|
|
||||||
res.on('end', () => {
|
|
||||||
if (res.statusCode >= 400 && res.statusCode <= 599) {
|
|
||||||
reject(
|
|
||||||
new Error(
|
|
||||||
`Got ${res.statusCode} from ${url}. Exiting with error`,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
resolve(data)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.on('error', (err) => {
|
|
||||||
reject(err)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const response = await httpClient.get(url, headers)
|
||||||
|
|
||||||
|
if (response.statusCode >= 400 && response.statusCode <= 599) {
|
||||||
|
throw new Error(
|
||||||
|
`Got ${response.statusCode} from ${url}. Exiting with error`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.readBody()
|
||||||
}
|
}
|
||||||
let ret
|
|
||||||
if (pageIdxs[0] === null) {
|
if (pageIdxs[0] === null) {
|
||||||
ret = getPage(null)
|
return getPage(null)
|
||||||
} else {
|
|
||||||
ret = Promise.all(pageIdxs.map((pageIdx) => getPage(pageIdx)))
|
|
||||||
}
|
}
|
||||||
return ret
|
return Promise.all(pageIdxs.map(getPage))
|
||||||
}
|
}
|
||||||
|
|
||||||
function maybePrependWithV(v) {
|
function maybePrependWithV(v) {
|
||||||
|
|||||||
Generated
+7
-6
@@ -9,6 +9,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "1.10.0",
|
"@actions/core": "1.10.0",
|
||||||
"@actions/exec": "1.1.1",
|
"@actions/exec": "1.1.1",
|
||||||
|
"@actions/http-client": "^2.1.0",
|
||||||
"semver": "7.3.8"
|
"semver": "7.3.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -47,9 +48,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@actions/http-client": {
|
"node_modules/@actions/http-client": {
|
||||||
"version": "2.0.1",
|
"version": "2.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.1.0.tgz",
|
||||||
"integrity": "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==",
|
"integrity": "sha512-BonhODnXr3amchh4qkmjPMUO8mFi/zLaaCeCAJZqch8iQqyDnVIkySjB38VHAC8IJ+bnlgfOqlhpyCUZHlQsqw==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tunnel": "^0.0.6"
|
"tunnel": "^0.0.6"
|
||||||
}
|
}
|
||||||
@@ -3012,9 +3013,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@actions/http-client": {
|
"@actions/http-client": {
|
||||||
"version": "2.0.1",
|
"version": "2.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.1.0.tgz",
|
||||||
"integrity": "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==",
|
"integrity": "sha512-BonhODnXr3amchh4qkmjPMUO8mFi/zLaaCeCAJZqch8iQqyDnVIkySjB38VHAC8IJ+bnlgfOqlhpyCUZHlQsqw==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"tunnel": "^0.0.6"
|
"tunnel": "^0.0.6"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "1.10.0",
|
"@actions/core": "1.10.0",
|
||||||
"@actions/exec": "1.1.1",
|
"@actions/exec": "1.1.1",
|
||||||
|
"@actions/http-client": "2.1.0",
|
||||||
"semver": "7.3.8"
|
"semver": "7.3.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
+28
-40
@@ -1,9 +1,9 @@
|
|||||||
const core = require('@actions/core')
|
const core = require('@actions/core')
|
||||||
const { exec } = require('@actions/exec')
|
const { exec } = require('@actions/exec')
|
||||||
|
const http = require('@actions/http-client')
|
||||||
const os = require('os')
|
const os = require('os')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const semver = require('semver')
|
const semver = require('semver')
|
||||||
const https = require('https')
|
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const installer = require('./installer')
|
const installer = require('./installer')
|
||||||
|
|
||||||
@@ -413,51 +413,39 @@ function getRunnerOSVersion() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function get(url0, pageIdxs) {
|
async function get(url0, pageIdxs) {
|
||||||
function getPage(pageIdx) {
|
async function getPage(pageIdx) {
|
||||||
return new Promise((resolve, reject) => {
|
const url = new URL(url0)
|
||||||
const url = new URL(url0)
|
const headers = {}
|
||||||
const headers = {
|
const GithubToken = getInput('github-token', false)
|
||||||
'user-agent': 'setup-beam',
|
|
||||||
}
|
|
||||||
const GithubToken = getInput('github-token', false)
|
|
||||||
|
|
||||||
if (GithubToken) {
|
if (GithubToken && url.host === 'api.github.com') {
|
||||||
headers.authorization = `Bearer ${GithubToken}`
|
headers.authorization = `Bearer ${GithubToken}`
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pageIdx !== null) {
|
if (pageIdx !== null) {
|
||||||
url.searchParams.append('page', pageIdx)
|
url.searchParams.append('page', pageIdx)
|
||||||
}
|
}
|
||||||
https
|
|
||||||
.get(url, { headers }, (res) => {
|
const httpClient = new http.HttpClient('setup-beam', [], {
|
||||||
let data = ''
|
allowRetries: true,
|
||||||
res.on('data', (chunk) => {
|
maxRetries: 3,
|
||||||
data += chunk
|
|
||||||
})
|
|
||||||
res.on('end', () => {
|
|
||||||
if (res.statusCode >= 400 && res.statusCode <= 599) {
|
|
||||||
reject(
|
|
||||||
new Error(
|
|
||||||
`Got ${res.statusCode} from ${url}. Exiting with error`,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
resolve(data)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.on('error', (err) => {
|
|
||||||
reject(err)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const response = await httpClient.get(url, headers)
|
||||||
|
|
||||||
|
if (response.statusCode >= 400 && response.statusCode <= 599) {
|
||||||
|
throw new Error(
|
||||||
|
`Got ${response.statusCode} from ${url}. Exiting with error`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.readBody()
|
||||||
}
|
}
|
||||||
let ret
|
|
||||||
if (pageIdxs[0] === null) {
|
if (pageIdxs[0] === null) {
|
||||||
ret = getPage(null)
|
return getPage(null)
|
||||||
} else {
|
|
||||||
ret = Promise.all(pageIdxs.map((pageIdx) => getPage(pageIdx)))
|
|
||||||
}
|
}
|
||||||
return ret
|
return Promise.all(pageIdxs.map(getPage))
|
||||||
}
|
}
|
||||||
|
|
||||||
function maybePrependWithV(v) {
|
function maybePrependWithV(v) {
|
||||||
|
|||||||
Reference in New Issue
Block a user