mirror of
https://github.com/actions/cache.git
synced 2025-04-23 06:30:47 +00:00
Format cache size and display on info
This commit is contained in:
parent
bc821d0c12
commit
97bd406ab6
3 changed files with 11 additions and 3 deletions
|
@ -219,7 +219,7 @@ test("restore with cache found", async () => {
|
||||||
const setCacheStateMock = jest.spyOn(actionUtils, "setCacheState");
|
const setCacheStateMock = jest.spyOn(actionUtils, "setCacheState");
|
||||||
const downloadCacheMock = jest.spyOn(cacheHttpClient, "downloadCache");
|
const downloadCacheMock = jest.spyOn(cacheHttpClient, "downloadCache");
|
||||||
|
|
||||||
const fileSize = 142;
|
const fileSize = 62915000;
|
||||||
const getArchiveFileSizeMock = jest
|
const getArchiveFileSizeMock = jest
|
||||||
.spyOn(actionUtils, "getArchiveFileSize")
|
.spyOn(actionUtils, "getArchiveFileSize")
|
||||||
.mockReturnValue(fileSize);
|
.mockReturnValue(fileSize);
|
||||||
|
@ -236,6 +236,7 @@ test("restore with cache found", async () => {
|
||||||
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1);
|
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1);
|
||||||
expect(downloadCacheMock).toHaveBeenCalledWith(cacheEntry, archivePath);
|
expect(downloadCacheMock).toHaveBeenCalledWith(cacheEntry, archivePath);
|
||||||
expect(getArchiveFileSizeMock).toHaveBeenCalledWith(archivePath);
|
expect(getArchiveFileSizeMock).toHaveBeenCalledWith(archivePath);
|
||||||
|
expect(infoMock).toHaveBeenCalledWith(`Cache Size: ~60 MB (62915000 B)`);
|
||||||
expect(mkdirMock).toHaveBeenCalledWith(cachePath);
|
expect(mkdirMock).toHaveBeenCalledWith(cachePath);
|
||||||
|
|
||||||
const IS_WINDOWS = process.platform === "win32";
|
const IS_WINDOWS = process.platform === "win32";
|
||||||
|
@ -312,6 +313,7 @@ test("restore with cache found for restore key", async () => {
|
||||||
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1);
|
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1);
|
||||||
expect(downloadCacheMock).toHaveBeenCalledWith(cacheEntry, archivePath);
|
expect(downloadCacheMock).toHaveBeenCalledWith(cacheEntry, archivePath);
|
||||||
expect(getArchiveFileSizeMock).toHaveBeenCalledWith(archivePath);
|
expect(getArchiveFileSizeMock).toHaveBeenCalledWith(archivePath);
|
||||||
|
expect(infoMock).toHaveBeenCalledWith(`Cache Size: ~0 MB (142 B)`);
|
||||||
expect(mkdirMock).toHaveBeenCalledWith(cachePath);
|
expect(mkdirMock).toHaveBeenCalledWith(cachePath);
|
||||||
|
|
||||||
const IS_WINDOWS = process.platform === "win32";
|
const IS_WINDOWS = process.platform === "win32";
|
||||||
|
|
|
@ -72,7 +72,11 @@ async function run() {
|
||||||
await cacheHttpClient.downloadCache(cacheEntry, archivePath);
|
await cacheHttpClient.downloadCache(cacheEntry, archivePath);
|
||||||
|
|
||||||
const archiveFileSize = utils.getArchiveFileSize(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);
|
io.mkdirP(cachePath);
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,9 @@ async function run() {
|
||||||
core.debug(`File Size: ${archiveFileSize}`);
|
core.debug(`File Size: ${archiveFileSize}`);
|
||||||
if (archiveFileSize > fileSizeLimit) {
|
if (archiveFileSize > fileSizeLimit) {
|
||||||
core.warning(
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue