setup-bun/src/cache-save.ts
Jozef Steinhübl a8913c42f4
fix: use hash instead of url for primary cache key (#102) (#103)
* fix: use hash instead of url for primary cache key (#102)

* Update cache-save.ts

* Update action.ts

* Update cache-save.ts

* build

* format

* [autofix.ci] apply automated fixes

---------

Co-authored-by: Daniil Zotov <142039751+zoto-ff@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-10-08 15:19:42 +02:00

19 lines
543 B
TypeScript

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], cacheKey);
process.exit(0);
} catch (error) {
warning("Failed to save Bun to cache.");
}
}
})();