Skip to content

Commit

Permalink
Change the restore/save dir
Browse files Browse the repository at this point in the history
  • Loading branch information
yykamei committed Mar 30, 2024
1 parent cfacf99 commit 8997d85
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/GitHubActionsCacheStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ export class GitHubActionsCacheStore implements CacheStore {
) {}

async read(cacheKey: string): Promise<OctokitCachedData | null> {
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");
Expand All @@ -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);
}
}
6 changes: 3 additions & 3 deletions tests/GitHubActionsCacheStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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");
});
});

Expand All @@ -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");
});
});
});

0 comments on commit 8997d85

Please sign in to comment.