feat: Check for existing bun before downloading
Check for existing bun with same version number, if it exists we skip any futher actions. This avoids downloading cache or bun over the network.
This commit is contained in:
parent
22457c87c1
commit
8876d4f857
194
dist/setup/index.js
generated
vendored
194
dist/setup/index.js
generated
vendored
File diff suppressed because one or more lines are too long
@ -7,6 +7,7 @@ import {
|
||||
symlinkSync,
|
||||
renameSync,
|
||||
copyFileSync,
|
||||
existsSync,
|
||||
} from "node:fs";
|
||||
import { addPath, info, warning } from "@actions/core";
|
||||
import { isFeatureAvailable, restoreCache } from "@actions/cache";
|
||||
@ -73,6 +74,18 @@ export default async (options: Input): Promise<Output> => {
|
||||
|
||||
let revision: string | undefined;
|
||||
let cacheHit = false;
|
||||
|
||||
// Check if Bun executable already exists and matches requested version
|
||||
if (!options.customUrl && existsSync(bunPath)) {
|
||||
const existingRevision = await getRevision(bunPath);
|
||||
if (existingRevision && isVersionMatch(existingRevision, options.version)) {
|
||||
revision = existingRevision;
|
||||
cacheHit = true; // Treat as cache hit to avoid unnecessary network requests
|
||||
info(`Using existing Bun installation: ${revision}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (!revision) {
|
||||
if (cacheEnabled) {
|
||||
const cacheKey = createHash("sha1").update(url).digest("base64");
|
||||
|
||||
@ -95,6 +108,7 @@ export default async (options: Input): Promise<Output> => {
|
||||
// TODO: remove this, temporary fix for https://github.com/oven-sh/setup-bun/issues/73
|
||||
revision = await retry(async () => await downloadBun(url, bunPath), 3);
|
||||
}
|
||||
}
|
||||
|
||||
if (!revision) {
|
||||
throw new Error(
|
||||
@ -122,6 +136,27 @@ export default async (options: Input): Promise<Output> => {
|
||||
};
|
||||
};
|
||||
|
||||
function isVersionMatch(
|
||||
existingRevision: string,
|
||||
requestedVersion?: string,
|
||||
): boolean {
|
||||
// If no version specified, default is "latest" - don't match existing
|
||||
if (!requestedVersion) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Non-pinned versions should never match existing installations
|
||||
if (/^(latest|canary|action)$/i.test(requestedVersion)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const [existingVersion] = existingRevision.split("+");
|
||||
|
||||
const normalizeVersion = (v: string) => v.replace(/^v/i, "");
|
||||
|
||||
return normalizeVersion(existingVersion) === normalizeVersion(requestedVersion);
|
||||
}
|
||||
|
||||
async function downloadBun(
|
||||
url: string,
|
||||
bunPath: string,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user