mirror of
https://github.com/oven-sh/setup-bun.git
synced 2026-05-21 13:50:14 +00:00
feat: add bun- prefix to cache keys (#160)
* feat: add bun- prefix to cache keys Extract cache key generation into a shared `getCacheKey` function in utils.ts that both action.ts and cache-save.ts import. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * [autofix.ci] apply automated fixes --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
+35
-35
File diff suppressed because one or more lines are too long
+43
-43
File diff suppressed because one or more lines are too long
+2
-3
@@ -1,4 +1,3 @@
|
|||||||
import { createHash } from "node:crypto";
|
|
||||||
import { homedir } from "node:os";
|
import { homedir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import {
|
import {
|
||||||
@@ -16,7 +15,7 @@ import { getExecOutput } from "@actions/exec";
|
|||||||
import { Registry } from "./registry";
|
import { Registry } from "./registry";
|
||||||
import { writeBunfig } from "./bunfig";
|
import { writeBunfig } from "./bunfig";
|
||||||
import { saveState } from "@actions/core";
|
import { saveState } from "@actions/core";
|
||||||
import { addExtension } from "./utils";
|
import { addExtension, getCacheKey } from "./utils";
|
||||||
import { getDownloadUrl } from "./download-url";
|
import { getDownloadUrl } from "./download-url";
|
||||||
import { cwd } from "node:process";
|
import { cwd } from "node:process";
|
||||||
|
|
||||||
@@ -90,7 +89,7 @@ export default async (options: Input): Promise<Output> => {
|
|||||||
|
|
||||||
if (!revision) {
|
if (!revision) {
|
||||||
if (cacheEnabled) {
|
if (cacheEnabled) {
|
||||||
const cacheKey = createHash("sha1").update(url).digest("base64");
|
const cacheKey = getCacheKey(url);
|
||||||
|
|
||||||
const cacheRestored = await restoreCache([bunPath], cacheKey);
|
const cacheRestored = await restoreCache([bunPath], cacheKey);
|
||||||
if (cacheRestored) {
|
if (cacheRestored) {
|
||||||
|
|||||||
+2
-2
@@ -1,11 +1,11 @@
|
|||||||
import { saveCache } from "@actions/cache";
|
import { saveCache } from "@actions/cache";
|
||||||
import { getState, warning } from "@actions/core";
|
import { getState, warning } from "@actions/core";
|
||||||
import { CacheState } from "./action";
|
import { CacheState } from "./action";
|
||||||
import { createHash } from "node:crypto";
|
import { getCacheKey } from "./utils";
|
||||||
(async () => {
|
(async () => {
|
||||||
const state: CacheState = JSON.parse(getState("cache"));
|
const state: CacheState = JSON.parse(getState("cache"));
|
||||||
if (state.cacheEnabled && !state.cacheHit) {
|
if (state.cacheEnabled && !state.cacheHit) {
|
||||||
const cacheKey = createHash("sha1").update(state.url).digest("base64");
|
const cacheKey = getCacheKey(state.url);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await saveCache([state.bunPath], cacheKey);
|
await saveCache([state.bunPath], cacheKey);
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
import { debug, warning } from "@actions/core";
|
import { debug, warning } from "@actions/core";
|
||||||
import { info } from "node:console";
|
import { info } from "node:console";
|
||||||
|
import { createHash } from "node:crypto";
|
||||||
import { existsSync, readFileSync, renameSync } from "node:fs";
|
import { existsSync, readFileSync, renameSync } from "node:fs";
|
||||||
import { resolve, basename } from "node:path";
|
import { resolve, basename } from "node:path";
|
||||||
|
|
||||||
|
export function getCacheKey(url: string): string {
|
||||||
|
return `bun-${createHash("sha1").update(url).digest("base64")}`;
|
||||||
|
}
|
||||||
|
|
||||||
export async function request(
|
export async function request(
|
||||||
url: string,
|
url: string,
|
||||||
init?: RequestInit,
|
init?: RequestInit,
|
||||||
|
|||||||
Reference in New Issue
Block a user