From 97bd406ab6f15159e76c1a2273a78bf3db0fd8ed Mon Sep 17 00:00:00 2001 From: Josh Gross Date: Tue, 12 Nov 2019 15:24:55 -0500 Subject: [PATCH] Format cache size and display on info --- __tests__/restore.test.ts | 4 +++- src/restore.ts | 6 +++++- src/save.ts | 4 +++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/__tests__/restore.test.ts b/__tests__/restore.test.ts index e854f6c..8104ac1 100644 --- a/__tests__/restore.test.ts +++ b/__tests__/restore.test.ts @@ -219,7 +219,7 @@ test("restore with cache found", async () => { const setCacheStateMock = jest.spyOn(actionUtils, "setCacheState"); const downloadCacheMock = jest.spyOn(cacheHttpClient, "downloadCache"); - const fileSize = 142; + const fileSize = 62915000; const getArchiveFileSizeMock = jest .spyOn(actionUtils, "getArchiveFileSize") .mockReturnValue(fileSize); @@ -236,6 +236,7 @@ test("restore with cache found", async () => { expect(createTempDirectoryMock).toHaveBeenCalledTimes(1); expect(downloadCacheMock).toHaveBeenCalledWith(cacheEntry, archivePath); expect(getArchiveFileSizeMock).toHaveBeenCalledWith(archivePath); + expect(infoMock).toHaveBeenCalledWith(`Cache Size: ~60 MB (62915000 B)`); expect(mkdirMock).toHaveBeenCalledWith(cachePath); const IS_WINDOWS = process.platform === "win32"; @@ -312,6 +313,7 @@ test("restore with cache found for restore key", async () => { expect(createTempDirectoryMock).toHaveBeenCalledTimes(1); expect(downloadCacheMock).toHaveBeenCalledWith(cacheEntry, archivePath); expect(getArchiveFileSizeMock).toHaveBeenCalledWith(archivePath); + expect(infoMock).toHaveBeenCalledWith(`Cache Size: ~0 MB (142 B)`); expect(mkdirMock).toHaveBeenCalledWith(cachePath); const IS_WINDOWS = process.platform === "win32"; diff --git a/src/restore.ts b/src/restore.ts index 4080098..15861f2 100644 --- a/src/restore.ts +++ b/src/restore.ts @@ -72,7 +72,11 @@ async function run() { await cacheHttpClient.downloadCache(cacheEntry, archivePath); const archiveFileSize = utils.getArchiveFileSize(archivePath); - core.debug(`File Size: ${archiveFileSize}`); + core.info( + `Cache Size: ~${Math.round( + archiveFileSize / (1024 * 1024) + )} MB (${archiveFileSize} B)` + ); io.mkdirP(cachePath); diff --git a/src/save.ts b/src/save.ts index 69e44cf..a63ce06 100644 --- a/src/save.ts +++ b/src/save.ts @@ -59,7 +59,9 @@ async function run() { core.debug(`File Size: ${archiveFileSize}`); if (archiveFileSize > fileSizeLimit) { core.warning( - `Cache size of ${archiveFileSize} bytes is over the 400MB limit, not saving cache.` + `Cache size of ~${Math.round( + archiveFileSize / (1024 * 1024) + )} MB (${archiveFileSize} B) is over the 400MB limit, not saving cache.` ); return; }