Compare commits

..
Author SHA1 Message Date
Sampark SharmaandGitHub 14f28534ef Stop progress bar on message.complete 2023-02-10 12:02:26 +00:00
Sampark SharmaandGitHub ae026cf7c6 Fix bugs 2023-02-10 11:52:49 +00:00
Sampark SharmaandGitHub 3d0da1ea1a Add download progress for httpclient method 2023-02-10 11:34:10 +00:00
8 changed files with 45 additions and 208 deletions
+1 -4
View File
@@ -114,7 +114,4 @@
- Fix issue with symlink restoration on windows.
### 3.1.3
- Fix to prevent from setting MYSYS environement variable globally [#1329](https://github.com/actions/toolkit/pull/1329).
### 3.1.4
- Fix zstd not being used due to `zstd --version` output change in zstd 1.5.4 release. See [#1353](https://github.com/actions/toolkit/pull/1353).
- Fix to prevent from setting MYSYS environement variable globally [#1329](https://github.com/actions/toolkit/pull/1329).
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "@actions/cache",
"version": "3.1.4",
"version": "3.1.3",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@actions/cache",
"version": "3.1.4",
"version": "3.1.3",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.10.0",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@actions/cache",
"version": "3.1.4",
"version": "3.1.3",
"preview": true,
"description": "Actions cache lib",
"keywords": [
+11 -11
View File
@@ -71,15 +71,11 @@ export async function unlinkFile(filePath: fs.PathLike): Promise<void> {
return util.promisify(fs.unlink)(filePath)
}
async function getVersion(
app: string,
additionalArgs: string[] = []
): Promise<string> {
async function getVersion(app: string): Promise<string> {
core.debug(`Checking ${app} --version`)
let versionOutput = ''
additionalArgs.push('--version')
core.debug(`Checking ${app} ${additionalArgs.join(' ')}`)
try {
await exec.exec(`${app}`, additionalArgs, {
await exec.exec(`${app} --version`, [], {
ignoreReturnCode: true,
silent: true,
listeners: {
@@ -98,14 +94,18 @@ async function getVersion(
// Use zstandard if possible to maximize cache performance
export async function getCompressionMethod(): Promise<CompressionMethod> {
const versionOutput = await getVersion('zstd', ['--quiet'])
const versionOutput = await getVersion('zstd')
const version = semver.clean(versionOutput)
core.debug(`zstd version: ${version}`)
if (versionOutput === '') {
if (!versionOutput.toLowerCase().includes('zstd command line interface')) {
// zstd is not installed
return CompressionMethod.Gzip
} else {
} else if (!version || semver.lt(version, 'v1.3.2')) {
// zstd is installed but using a version earlier than v1.3.2
// v1.3.2 is required to use the `--long` options in zstd
return CompressionMethod.ZstdWithoutLong
} else {
return CompressionMethod.Zstd
}
}
+26 -1
View File
@@ -10,7 +10,7 @@ import * as util from 'util'
import * as utils from './cacheUtils'
import {SocketTimeout} from './constants'
import {DownloadOptions} from '../options'
import {retryHttpClientResponse} from './requestUtils'
import {retryHttpClientResponse, sleep} from './requestUtils'
import {AbortController} from '@azure/abort-controller'
@@ -161,6 +161,28 @@ export class DownloadProgress {
}
}
async function displayDownloadProgress(message: any, startTime: number): Promise<void> {
const socket = message.socket
while(!message.complete) {
const byteRead = socket.bytesRead
const totalBytes = 100000
const percentage = (100 * (byteRead / totalBytes)).toFixed(
1
)
const elapsedTime = Date.now() - startTime
const downloadSpeed = (
byteRead /
(1024 * 1024) /
(elapsedTime / 1000)
).toFixed(1)
core.info(
`Received ${byteRead} of ${totalBytes} (${percentage}%), ${downloadSpeed} MBs/sec`
)
sleep(100)
}
}
/**
* Download the cache using the Actions toolkit http-client
*
@@ -171,6 +193,7 @@ export async function downloadCacheHttpClient(
archiveLocation: string,
archivePath: string
): Promise<void> {
const startTime = Date.now()
const writeStream = fs.createWriteStream(archivePath)
const httpClient = new HttpClient('actions/cache')
const downloadResponse = await retryHttpClientResponse(
@@ -184,6 +207,8 @@ export async function downloadCacheHttpClient(
core.debug(`Aborting download, socket timed out after ${SocketTimeout} ms`)
})
await displayDownloadProgress(downloadResponse.message, startTime)
await pipeResponseToStream(downloadResponse, writeStream)
// Validate download size.
+1 -1
View File
@@ -33,7 +33,7 @@ export function isRetryableStatusCode(statusCode?: number): boolean {
return retryableStatusCodes.includes(statusCode)
}
async function sleep(milliseconds: number): Promise<void> {
export async function sleep(milliseconds: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, milliseconds))
}
+2 -165
View File
@@ -28,7 +28,7 @@ describe('proxy', () => {
_clearVars()
})
afterEach(() => { })
afterEach(() => {})
afterAll(async () => {
_clearVars()
@@ -145,44 +145,6 @@ describe('proxy', () => {
expect(bypass).toBeFalsy()
})
it('checkBypass returns true if host with subdomain in no_proxy', () => {
process.env['no_proxy'] = 'myserver.com'
const bypass = pm.checkBypass(new URL('https://sub.myserver.com'))
expect(bypass).toBeTruthy()
})
it('checkBypass returns false if no_proxy is subdomain', () => {
process.env['no_proxy'] = 'myserver.com'
const bypass = pm.checkBypass(new URL('https://myserver.com.evil.org'))
expect(bypass).toBeFalsy()
})
it('checkBypass returns false if no_proxy is part of domain', () => {
process.env['no_proxy'] = 'myserver.com'
const bypass = pm.checkBypass(new URL('https://evilmyserver.com'))
expect(bypass).toBeFalsy()
})
// Do not strip leading dots as per https://github.com/actions/runner/blob/97195bad5870e2ad0915ebfef1616083aacf5818/docs/adrs/0263-proxy-support.md
it('checkBypass returns false if host with leading dot in no_proxy', () => {
process.env['no_proxy'] = '.myserver.com'
const bypass = pm.checkBypass(new URL('https://myserver.com'))
expect(bypass).toBeFalsy()
})
it('checkBypass returns true if host with subdomain in no_proxy defined with leading "."', () => {
process.env['no_proxy'] = '.myserver.com'
const bypass = pm.checkBypass(new URL('https://sub.myserver.com'))
expect(bypass).toBeTruthy()
})
// Do not match wildcard ("*") as per https://github.com/actions/runner/blob/97195bad5870e2ad0915ebfef1616083aacf5818/docs/adrs/0263-proxy-support.md
it('checkBypass returns true if no_proxy is "*"', () => {
process.env['no_proxy'] = '*'
const bypass = pm.checkBypass(new URL('https://anything.whatsoever.com'))
expect(bypass).toBeFalsy()
})
it('HttpClient does basic http get request through proxy', async () => {
process.env['http_proxy'] = _proxyUrl
const httpClient = new httpm.HttpClient()
@@ -196,7 +158,7 @@ describe('proxy', () => {
expect(_proxyConnects).toEqual(['httpbin.org:80'])
})
it('HttpClient does basic http get request when bypass proxy', async () => {
it('HttoClient does basic http get request when bypass proxy', async () => {
process.env['http_proxy'] = _proxyUrl
process.env['no_proxy'] = 'httpbin.org'
const httpClient = new httpm.HttpClient()
@@ -258,133 +220,8 @@ describe('proxy', () => {
expect(agent.proxyOptions.port).toBe('8080')
expect(agent.proxyOptions.proxyAuth).toBe('user:password')
})
// unit tests from actions/runner
it('should prefer lowercase over uppercase ENVs', async () => {
process.env['http_proxy'] = 'http://127.0.0.1:7777'
process.env['HTTP_PROXY'] = 'http://127.0.0.1:8888'
process.env['https_proxy'] = 'https://127.0.0.1:8888'
process.env['HTTPS_PROXY'] = 'https://127.0.0.1:7777'
const httpClient = new httpm.HttpClient()
const httpAgent: any = httpClient.getAgent('http://some-url')
expect(httpAgent.proxyOptions.host).toBe('127.0.0.1')
expect(httpAgent.proxyOptions.port).toBe('7777')
const httpsAgent: any = httpClient.getAgent('https://some-url')
expect(httpsAgent.proxyOptions.host).toBe('127.0.0.1')
expect(httpsAgent.proxyOptions.port).toBe('8888')
})
it('should not set proxy on invalid input', async () => {
process.env['http_proxy'] = '127.0.0.1:7777'
process.env['https_proxy'] = '127.0.0.1:8888'
const httpClient = new httpm.HttpClient()
// Different from actions/runner, we throw an error here while the runner proceeds without a proxy
expect(() => httpClient.getAgent('http://some-url')).toThrow()
expect(() => httpClient.getAgent('https://some-url')).toThrow()
})
it('should bypass no_proxy hosts', async () => {
process.env['http_proxy'] = '127.0.0.1:7777'
process.env['https_proxy'] = '127.0.0.1:8888'
process.env['no_proxy'] = 'github.com, .google.com, example.com:444, 192.168.0.123:123, 192.168.1.123'
expect(pm.checkBypass(new URL('https://actions.com'))).toBeFalsy();
expect(pm.checkBypass(new URL('https://ggithub.com'))).toBeFalsy();
expect(pm.checkBypass(new URL('https://github.comm'))).toBeFalsy();
expect(pm.checkBypass(new URL('https://google.com'))).toBeFalsy();
expect(pm.checkBypass(new URL('https://example.com'))).toBeFalsy();
expect(pm.checkBypass(new URL('http://example.com:333'))).toBeFalsy();
expect(pm.checkBypass(new URL('http://192.168.0.123:123'))).toBeTruthy(); // DIFF
expect(pm.checkBypass(new URL('http://192.168.1.123/home'))).toBeTruthy(); // DIFF
expect(pm.checkBypass(new URL('https://github.com'))).toBeTruthy()
expect(pm.checkBypass(new URL('https://GITHUB.COM'))).toBeTruthy()
expect(pm.checkBypass(new URL('https://github.com/owner/repo'))).toBeTruthy()
expect(pm.checkBypass(new URL('https://actions.github.com'))).toBeTruthy()
expect(pm.checkBypass(new URL('https://mails.google.com'))).toBeTruthy()
expect(pm.checkBypass(new URL('https://MAILS.GOOGLE.com'))).toBeTruthy()
expect(pm.checkBypass(new URL('https://mails.v2.google.com'))).toBeTruthy()
expect(pm.checkBypass(new URL('http://mails.v2.v3.google.com/inbox'))).toBeTruthy()
expect(pm.checkBypass(new URL('https://example.com:444'))).toBeTruthy()
expect(pm.checkBypass(new URL('http://example.com:444'))).toBeTruthy()
expect(pm.checkBypass(new URL('http://example.COM:444'))).toBeTruthy()
})
})
it('should not use http_proxy for https requests if https_proxy is not set', async () => {
process.env['http_proxy'] = 'http://127.0.0.1:7777/'
expect(pm.getProxyUrl(new URL('http://example.com'))).toBeDefined()
expect(pm.getProxyUrl(new URL('https://example.com'))).toBeUndefined()
})
it('HttpClient does basic https get request when bypass proxy', async () => {
process.env['https_proxy'] = _proxyUrl
process.env['no_proxy'] = 'httpbin.org'
const httpClient = new httpm.HttpClient()
const res: httpm.HttpClientResponse = await httpClient.get(
'https://httpbin.org/get'
)
expect(res.message.statusCode).toBe(200)
const body: string = await res.readBody()
const obj = JSON.parse(body)
expect(obj.url).toBe('https://httpbin.org/get')
expect(_proxyConnects).toHaveLength(0)
})
it('HttpClient bypasses proxy for loopback addresses (localhost, ::1, 127.*)', async () => {
// setup a server listening on localhost:8091
var server = http.createServer(function (request, response) {
response.writeHead(200);
request.pipe(response);
});
await server.listen(8091)
try {
process.env['http_proxy'] = _proxyUrl
const httpClient = new httpm.HttpClient()
const res: httpm.HttpClientResponse = await httpClient.get(
'http://localhost:8091'
)
expect(res.message.statusCode).toBe(200)
const body: string = await res.readBody()
expect(body).toEqual('');
// proxy at _proxyUrl was ignored
expect(_proxyConnects).toEqual([])
}
finally {
await server.close()
}
})
it('HttpClient does basic https get request when bypass proxy', async () => {
process.env['https_proxy'] = _proxyUrl
process.env['no_proxy'] = 'httpbin.org'
const httpClient = new httpm.HttpClient()
const res: httpm.HttpClientResponse = await httpClient.get(
'https://httpbin.org/get'
)
expect(res.message.statusCode).toBe(200)
const body: string = await res.readBody()
const obj = JSON.parse(body)
expect(obj.url).toBe('https://httpbin.org/get')
expect(_proxyConnects).toHaveLength(0)
})
it('should not use https_proxy for http requests if http_proxy is not set', async () => {
process.env['https_proxy'] = 'https://127.0.0.1:7777/'
expect(pm.getProxyUrl(new URL('http://example.com'))).toBeUndefined()
expect(pm.getProxyUrl(new URL('https://example.com'))).toBeDefined()
})
// it('should detect loopback ip addresses', async () => {
// process.env['http_proxy'] = 'http://nonlocal.faraway.com:7777/'
// expect(pm.getProxyUrl(new URL('http://localhost'))).toBeUndefined()
// })
function _clearVars(): void {
delete process.env.http_proxy
delete process.env.HTTP_PROXY
+1 -23
View File
@@ -25,11 +25,6 @@ export function checkBypass(reqUrl: URL): boolean {
return false
}
const reqHost = reqUrl.hostname
if (isLoopbackAddress(reqHost)) {
return true
}
const noProxy = process.env['no_proxy'] || process.env['NO_PROXY'] || ''
if (!noProxy) {
return false
@@ -56,27 +51,10 @@ export function checkBypass(reqUrl: URL): boolean {
.split(',')
.map(x => x.trim().toUpperCase())
.filter(x => x)) {
if (
upperReqHosts.some(
x =>
x === upperNoProxyItem ||
x.endsWith(`.${upperNoProxyItem}`) ||
(upperNoProxyItem.startsWith('.') &&
x.endsWith(`${upperNoProxyItem}`))
)
) {
if (upperReqHosts.some(x => x === upperNoProxyItem)) {
return true
}
}
return false
}
function isLoopbackAddress(host: string): boolean {
const hostUpper = host.toUpperCase()
return (
hostUpper === 'LOCALHOST' ||
hostUpper.startsWith('127.') ||
hostUpper.startsWith('::1')
)
}