1
0
Fork 0
mirror of https://code.forgejo.org/actions/cache.git synced 2025-06-07 14:50:24 +02:00

Attempt to delete the archive after extraction

This reduces storage space used once the Action has finished executing.
This commit is contained in:
Henry Mercer 2020-03-10 14:04:04 +00:00
parent 826785142a
commit 15c6d81aaa
6 changed files with 70 additions and 18 deletions

View file

@ -1,4 +1,5 @@
import * as core from "@actions/core";
import * as fs from "fs";
import * as os from "os";
import * as path from "path";
@ -234,3 +235,15 @@ test("isValidEvent returns true for pull request event", () => {
expect(isValidEvent).toBe(true);
});
test("unlinkFile unlinks file", async () => {
const testDirectory = fs.mkdtempSync("unlinkFileTest");
const testFile = path.join(testDirectory, "test.txt");
fs.writeFileSync(testFile, "hello world");
await actionUtils.unlinkFile(testFile);
expect(fs.existsSync(testFile)).toBe(false);
fs.rmdirSync(testDirectory);
});

View file

@ -240,6 +240,7 @@ test("restore with cache found", async () => {
.mockReturnValue(fileSize);
const extractTarMock = jest.spyOn(tar, "extractTar");
const unlinkFileMock = jest.spyOn(actionUtils, "unlinkFile");
const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput");
await run();
@ -257,6 +258,9 @@ test("restore with cache found", async () => {
expect(extractTarMock).toHaveBeenCalledTimes(1);
expect(extractTarMock).toHaveBeenCalledWith(archivePath, cachePath);
expect(unlinkFileMock).toHaveBeenCalledTimes(1);
expect(unlinkFileMock).toHaveBeenCalledWith(archivePath);
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
expect(setCacheHitOutputMock).toHaveBeenCalledWith(true);