neiam /action-setup-beam
action-setup-beam
public · Issues · Pulls · Labels · Forks · Compare · Actions queued
⭐
Log in to mark this repository.
Use @actions/http-client (#195)
94b8820 · Eric Meadows-Jönsson · 2023-05-02 16:40
Files changed
modified
dist/index.js
+44
−41
@@ -2461,6 +2461,10 @@ function checkBypass(reqUrl) {
| 2461 | 2461 | if (!reqUrl.hostname) { |
| 2462 | 2462 | return false; |
| 2463 | 2463 | } |
| 2464 | + const reqHost = reqUrl.hostname; | |
| 2465 | + if (isLoopbackAddress(reqHost)) { | |
| 2466 | + return true; | |
| 2467 | + } | |
| 2464 | 2468 | const noProxy = process.env['no_proxy'] || process.env['NO_PROXY'] || ''; |
| 2465 | 2469 | if (!noProxy) { |
| 2466 | 2470 | return false; |
@@ -2486,13 +2490,24 @@ function checkBypass(reqUrl) {
| 2486 | 2490 | .split(',') |
| 2487 | 2491 | .map(x => x.trim().toUpperCase()) |
| 2488 | 2492 | .filter(x => x)) { |
| 2489 | − if (upperReqHosts.some(x => x === upperNoProxyItem)) { | |
| 2493 | + if (upperNoProxyItem === '*' || | |
| 2494 | + upperReqHosts.some(x => x === upperNoProxyItem || | |
| 2495 | + x.endsWith(`.${upperNoProxyItem}`) || | |
| 2496 | + (upperNoProxyItem.startsWith('.') && | |
| 2497 | + x.endsWith(`${upperNoProxyItem}`)))) { | |
| 2490 | 2498 | return true; |
| 2491 | 2499 | } |
| 2492 | 2500 | } |
| 2493 | 2501 | return false; |
| 2494 | 2502 | } |
| 2495 | 2503 | exports.checkBypass = checkBypass; |
| 2504 | +function isLoopbackAddress(host) { | |
| 2505 | + const hostLower = host.toLowerCase(); | |
| 2506 | + return (hostLower === 'localhost' || | |
| 2507 | + hostLower.startsWith('127.') || | |
| 2508 | + hostLower.startsWith('[::1]') || | |
| 2509 | + hostLower.startsWith('[0:0:0:0:0:0:0:1]')); | |
| 2510 | +} | |
| 2496 | 2511 | //# sourceMappingURL=proxy.js.map |
| 2497 | 2512 | |
| 2498 | 2513 | /***/ }), |
@@ -7193,10 +7208,10 @@ module.exports = {
| 7193 | 7208 | |
| 7194 | 7209 | const core = __nccwpck_require__(2186) |
| 7195 | 7210 | const { exec } = __nccwpck_require__(1514) |
| 7211 | +const http = __nccwpck_require__(6255) | |
| 7196 | 7212 | const os = __nccwpck_require__(2037) |
| 7197 | 7213 | const path = __nccwpck_require__(1017) |
| 7198 | 7214 | const semver = __nccwpck_require__(1383) |
| 7199 | −const https = __nccwpck_require__(5687) | |
| 7200 | 7215 | const fs = __nccwpck_require__(7147) |
| 7201 | 7216 | const installer = __nccwpck_require__(2127) |
| 7202 | 7217 |
@@ -7606,51 +7621,39 @@ function getRunnerOSVersion() {
| 7606 | 7621 | } |
| 7607 | 7622 | |
| 7608 | 7623 | async function get(url0, pageIdxs) { |
| 7609 | − function getPage(pageIdx) { | |
| 7610 | − return new Promise((resolve, reject) => { | |
| 7611 | − const url = new URL(url0) | |
| 7612 | − const headers = { | |
| 7613 | − 'user-agent': 'setup-beam', | |
| 7614 | − } | |
| 7615 | − const GithubToken = getInput('github-token', false) | |
| 7624 | + async function getPage(pageIdx) { | |
| 7625 | + const url = new URL(url0) | |
| 7626 | + const headers = {} | |
| 7627 | + const GithubToken = getInput('github-token', false) | |
| 7616 | 7628 | |
| 7617 | − if (GithubToken) { | |
| 7618 | − headers.authorization = `Bearer ${GithubToken}` | |
| 7619 | − } | |
| 7629 | + if (GithubToken && url.host === 'api.github.com') { | |
| 7630 | + headers.authorization = `Bearer ${GithubToken}` | |
| 7631 | + } | |
| 7620 | 7632 | |
| 7621 | − if (pageIdx !== null) { | |
| 7622 | − url.searchParams.append('page', pageIdx) | |
| 7623 | − } | |
| 7624 | − https | |
| 7625 | − .get(url, { headers }, (res) => { | |
| 7626 | − let data = '' | |
| 7627 | − res.on('data', (chunk) => { | |
| 7628 | − data += chunk | |
| 7629 | − }) | |
| 7630 | − res.on('end', () => { | |
| 7631 | − if (res.statusCode >= 400 && res.statusCode <= 599) { | |
| 7632 | − reject( | |
| 7633 | − new Error( | |
| 7634 | − `Got ${res.statusCode} from ${url}. Exiting with error`, | |
| 7635 | − ), | |
| 7636 | − ) | |
| 7637 | − } else { | |
| 7638 | − resolve(data) | |
| 7639 | − } | |
| 7640 | − }) | |
| 7641 | − }) | |
| 7642 | − .on('error', (err) => { | |
| 7643 | − reject(err) | |
| 7644 | − }) | |
| 7633 | + if (pageIdx !== null) { | |
| 7634 | + url.searchParams.append('page', pageIdx) | |
| 7635 | + } | |
| 7636 | + | |
| 7637 | + const httpClient = new http.HttpClient('setup-beam', [], { | |
| 7638 | + allowRetries: true, | |
| 7639 | + maxRetries: 3, | |
| 7645 | 7640 | }) |
| 7641 | + | |
| 7642 | + const response = await httpClient.get(url, headers) | |
| 7643 | + | |
| 7644 | + if (response.statusCode >= 400 && response.statusCode <= 599) { | |
| 7645 | + throw new Error( | |
| 7646 | + `Got ${response.statusCode} from ${url}. Exiting with error`, | |
| 7647 | + ) | |
| 7648 | + } | |
| 7649 | + | |
| 7650 | + return response.readBody() | |
| 7646 | 7651 | } |
| 7647 | − let ret | |
| 7652 | + | |
| 7648 | 7653 | if (pageIdxs[0] === null) { |
| 7649 | − ret = getPage(null) | |
| 7650 | − } else { | |
| 7651 | − ret = Promise.all(pageIdxs.map((pageIdx) => getPage(pageIdx))) | |
| 7654 | + return getPage(null) | |
| 7652 | 7655 | } |
| 7653 | − return ret | |
| 7656 | + return Promise.all(pageIdxs.map(getPage)) | |
| 7654 | 7657 | } |
| 7655 | 7658 | |
| 7656 | 7659 | function maybePrependWithV(v) { |
modified
package-lock.json
+7
−6
@@ -9,6 +9,7 @@
| 9 | 9 | "dependencies": { |
| 10 | 10 | "@actions/core": "1.10.0", |
| 11 | 11 | "@actions/exec": "1.1.1", |
| 12 | + "@actions/http-client": "^2.1.0", | |
| 12 | 13 | "semver": "7.3.8" |
| 13 | 14 | }, |
| 14 | 15 | "devDependencies": { |
@@ -47,9 +48,9 @@
| 47 | 48 | } |
| 48 | 49 | }, |
| 49 | 50 | "node_modules/@actions/http-client": { |
| 50 | − "version": "2.0.1", | |
| 51 | − "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz", | |
| 52 | − "integrity": "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==", | |
| 51 | + "version": "2.1.0", | |
| 52 | + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.1.0.tgz", | |
| 53 | + "integrity": "sha512-BonhODnXr3amchh4qkmjPMUO8mFi/zLaaCeCAJZqch8iQqyDnVIkySjB38VHAC8IJ+bnlgfOqlhpyCUZHlQsqw==", | |
| 53 | 54 | "dependencies": { |
| 54 | 55 | "tunnel": "^0.0.6" |
| 55 | 56 | } |
@@ -3012,9 +3013,9 @@
| 3012 | 3013 | } |
| 3013 | 3014 | }, |
| 3014 | 3015 | "@actions/http-client": { |
| 3015 | − "version": "2.0.1", | |
| 3016 | − "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz", | |
| 3017 | − "integrity": "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==", | |
| 3016 | + "version": "2.1.0", | |
| 3017 | + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.1.0.tgz", | |
| 3018 | + "integrity": "sha512-BonhODnXr3amchh4qkmjPMUO8mFi/zLaaCeCAJZqch8iQqyDnVIkySjB38VHAC8IJ+bnlgfOqlhpyCUZHlQsqw==", | |
| 3018 | 3019 | "requires": { |
| 3019 | 3020 | "tunnel": "^0.0.6" |
| 3020 | 3021 | } |
modified
package.json
+1
−0
@@ -21,6 +21,7 @@
| 21 | 21 | "dependencies": { |
| 22 | 22 | "@actions/core": "1.10.0", |
| 23 | 23 | "@actions/exec": "1.1.1", |
| 24 | + "@actions/http-client": "2.1.0", | |
| 24 | 25 | "semver": "7.3.8" |
| 25 | 26 | }, |
| 26 | 27 | "devDependencies": { |
modified
src/setup-beam.js
+28
−40
@@ -1,9 +1,9 @@
| 1 | 1 | const core = require('@actions/core') |
| 2 | 2 | const { exec } = require('@actions/exec') |
| 3 | +const http = require('@actions/http-client') | |
| 3 | 4 | const os = require('os') |
| 4 | 5 | const path = require('path') |
| 5 | 6 | const semver = require('semver') |
| 6 | −const https = require('https') | |
| 7 | 7 | const fs = require('fs') |
| 8 | 8 | const installer = require('./installer') |
| 9 | 9 |
@@ -413,51 +413,39 @@ function getRunnerOSVersion() {
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | async function get(url0, pageIdxs) { |
| 416 | − function getPage(pageIdx) { | |
| 417 | − return new Promise((resolve, reject) => { | |
| 418 | − const url = new URL(url0) | |
| 419 | − const headers = { | |
| 420 | − 'user-agent': 'setup-beam', | |
| 421 | − } | |
| 422 | − const GithubToken = getInput('github-token', false) | |
| 416 | + async function getPage(pageIdx) { | |
| 417 | + const url = new URL(url0) | |
| 418 | + const headers = {} | |
| 419 | + const GithubToken = getInput('github-token', false) | |
| 423 | 420 | |
| 424 | − if (GithubToken) { | |
| 425 | − headers.authorization = `Bearer ${GithubToken}` | |
| 426 | − } | |
| 421 | + if (GithubToken && url.host === 'api.github.com') { | |
| 422 | + headers.authorization = `Bearer ${GithubToken}` | |
| 423 | + } | |
| 427 | 424 | |
| 428 | − if (pageIdx !== null) { | |
| 429 | − url.searchParams.append('page', pageIdx) | |
| 430 | − } | |
| 431 | − https | |
| 432 | − .get(url, { headers }, (res) => { | |
| 433 | − let data = '' | |
| 434 | − res.on('data', (chunk) => { | |
| 435 | − data += chunk | |
| 436 | − }) | |
| 437 | − res.on('end', () => { | |
| 438 | − if (res.statusCode >= 400 && res.statusCode <= 599) { | |
| 439 | − reject( | |
| 440 | − new Error( | |
| 441 | − `Got ${res.statusCode} from ${url}. Exiting with error`, | |
| 442 | − ), | |
| 443 | − ) | |
| 444 | − } else { | |
| 445 | − resolve(data) | |
| 446 | − } | |
| 447 | − }) | |
| 448 | − }) | |
| 449 | − .on('error', (err) => { | |
| 450 | − reject(err) | |
| 451 | − }) | |
| 425 | + if (pageIdx !== null) { | |
| 426 | + url.searchParams.append('page', pageIdx) | |
| 427 | + } | |
| 428 | + | |
| 429 | + const httpClient = new http.HttpClient('setup-beam', [], { | |
| 430 | + allowRetries: true, | |
| 431 | + maxRetries: 3, | |
| 452 | 432 | }) |
| 433 | + | |
| 434 | + const response = await httpClient.get(url, headers) | |
| 435 | + | |
| 436 | + if (response.statusCode >= 400 && response.statusCode <= 599) { | |
| 437 | + throw new Error( | |
| 438 | + `Got ${response.statusCode} from ${url}. Exiting with error`, | |
| 439 | + ) | |
| 440 | + } | |
| 441 | + | |
| 442 | + return response.readBody() | |
| 453 | 443 | } |
| 454 | − let ret | |
| 444 | + | |
| 455 | 445 | if (pageIdxs[0] === null) { |
| 456 | − ret = getPage(null) | |
| 457 | − } else { | |
| 458 | − ret = Promise.all(pageIdxs.map((pageIdx) => getPage(pageIdx))) | |
| 446 | + return getPage(null) | |
| 459 | 447 | } |
| 460 | − return ret | |
| 448 | + return Promise.all(pageIdxs.map(getPage)) | |
| 461 | 449 | } |
| 462 | 450 | |
| 463 | 451 | function maybePrependWithV(v) { |
Parents: c2e02f7