diff --git a/dist/index.js b/dist/index.js index 27da48c..f157573 100644 --- a/dist/index.js +++ b/dist/index.js @@ -82703,8 +82703,8 @@ class GitHubActionsCacheStore { this.save = save; } async read(cacheKey) { - await this.restore([this.baseDir], cacheKey); const dir = (0,external_node_path_namespaceObject.join)(this.baseDir, cacheKey); + await this.restore([dir], cacheKey); try { const etag = await (0,promises_namespaceObject.readFile)((0,external_node_path_namespaceObject.join)(dir, "etag"), "utf-8"); const data = await (0,promises_namespaceObject.readFile)((0,external_node_path_namespaceObject.join)(dir, "data"), "utf-8"); @@ -82721,7 +82721,7 @@ class GitHubActionsCacheStore { await (0,promises_namespaceObject.writeFile)((0,external_node_path_namespaceObject.join)(dir, "etag"), cache.etag); } await (0,promises_namespaceObject.writeFile)((0,external_node_path_namespaceObject.join)(dir, "data"), JSON.stringify(cache.data)); - await this.save([this.baseDir], cacheKey); + await this.save([dir], cacheKey); } } diff --git a/src/GitHubActionsCacheStore.ts b/src/GitHubActionsCacheStore.ts index f8d2bae..728f531 100644 --- a/src/GitHubActionsCacheStore.ts +++ b/src/GitHubActionsCacheStore.ts @@ -32,9 +32,9 @@ export class GitHubActionsCacheStore implements CacheStore { ) {} async read(cacheKey: string): Promise { - await this.restore([this.baseDir], cacheKey); - const dir = join(this.baseDir, cacheKey); + await this.restore([dir], cacheKey); + try { const etag = await readFile(join(dir, "etag"), "utf-8"); const data = await readFile(join(dir, "data"), "utf-8"); @@ -51,6 +51,6 @@ export class GitHubActionsCacheStore implements CacheStore { await writeFile(join(dir, "etag"), cache.etag); } await writeFile(join(dir, "data"), JSON.stringify(cache.data)); - await this.save([this.baseDir], cacheKey); + await this.save([dir], cacheKey); } } diff --git a/tests/GitHubActionsCacheStore.test.ts b/tests/GitHubActionsCacheStore.test.ts index 813c1dc..ea6563e 100644 --- a/tests/GitHubActionsCacheStore.test.ts +++ b/tests/GitHubActionsCacheStore.test.ts @@ -22,7 +22,7 @@ describe("GitHubActionsCacheStore", () => { const store = new GitHubActionsCacheStore(workdir, restore); const cache = await store.read("key"); expect(cache).toBeNull(); - expect(restore).toHaveBeenCalledWith([workdir], "key"); + expect(restore).toHaveBeenCalledWith([join(workdir, "key")], "key"); }); it("should return cache if cache exists", async () => { @@ -36,7 +36,7 @@ describe("GitHubActionsCacheStore", () => { const store = new GitHubActionsCacheStore(workdir, restore); const cache = await store.read("key"); expect(cache).toEqual({ etag: "etag1", data: { field: 1 } }); - expect(restore).toHaveBeenCalledWith([workdir], "key"); + expect(restore).toHaveBeenCalledWith([join(workdir, "key")], "key"); }); }); @@ -50,7 +50,7 @@ describe("GitHubActionsCacheStore", () => { const data = await readFile(join(workdir, "key", "data"), "utf-8"); expect(etag).toEqual("e"); expect(JSON.parse(data)).toEqual({ my: "field" }); - expect(save).toHaveBeenCalledWith([workdir], "key"); + expect(save).toHaveBeenCalledWith([join(workdir, "key")], "key"); }); }); });