fix: use hash instead of url for primary cache key (#102)

* Update cache-save.ts

* Update action.ts

* Update cache-save.ts

* build

* format
This commit is contained in:
Daniil Zotov 2024-10-04 23:28:43 +03:00 committed by GitHub
parent b9d34de66d
commit e44c52ab01
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 377 additions and 87 deletions

198
dist/cache-save/index.js generated vendored

File diff suppressed because one or more lines are too long

256
dist/setup/index.js generated vendored

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,4 @@
import { createHash } from "node:crypto";
import { homedir } from "node:os";
import { join } from "node:path";
import {
@ -73,7 +74,9 @@ export default async (options: Input): Promise<Output> => {
let revision: string | undefined;
let cacheHit = false;
if (cacheEnabled) {
const cacheRestored = await restoreCache([bunPath], url);
const cacheKey = createHash("sha1").update(url).digest("base64");
const cacheRestored = await restoreCache([bunPath], cacheKey);
if (cacheRestored) {
revision = await getRevision(bunPath);
if (revision) {

View File

@ -1,12 +1,15 @@
import { saveCache } from "@actions/cache";
import { getState, warning } from "@actions/core";
import { CacheState } from "./action";
import { createHash } from "node:crypto";
(async () => {
const state: CacheState = JSON.parse(getState("cache"));
if (state.cacheEnabled && !state.cacheHit) {
const cacheKey = createHash("sha1").update(state.url).digest("base64");
try {
await saveCache([state.bunPath], state.url);
await saveCache([state.bunPath], cacheKey);
process.exit(0);
} catch (error) {
warning("Failed to save Bun to cache.");