diff --git a/packages/cache/src/internal/downloadUtils.ts b/packages/cache/src/internal/downloadUtils.ts index 265c34f7..5cee37d7 100644 --- a/packages/cache/src/internal/downloadUtils.ts +++ b/packages/cache/src/internal/downloadUtils.ts @@ -161,6 +161,26 @@ export class DownloadProgress { } } +async function displayDownloadProgress(socket: any, startTime: number): Promise { + while(!socket.complete) { + const transferredBytes = socket.bytesRead + const totalBytes = 100000 + const percentage = (100 * (transferredBytes / totalBytes)).toFixed( + 1 + ) + const elapsedTime = Date.now() - startTime + const downloadSpeed = ( + transferredBytes / + (1024 * 1024) / + (elapsedTime / 1000) + ).toFixed(1) + + core.info( + `Received ${transferredBytes} of ${totalBytes} (${percentage}%), ${downloadSpeed} MBs/sec` + ) + } +} + /** * Download the cache using the Actions toolkit http-client * @@ -171,6 +191,7 @@ export async function downloadCacheHttpClient( archiveLocation: string, archivePath: string ): Promise { + const startTime = Date.now() const writeStream = fs.createWriteStream(archivePath) const httpClient = new HttpClient('actions/cache') const downloadResponse = await retryHttpClientResponse( @@ -184,6 +205,8 @@ export async function downloadCacheHttpClient( core.debug(`Aborting download, socket timed out after ${SocketTimeout} ms`) }) + await displayDownloadProgress(downloadResponse.message.socket, startTime) + await pipeResponseToStream(downloadResponse, writeStream) // Validate download size.