From 15050a763274a83491c4538073ae045351c05ee9 Mon Sep 17 00:00:00 2001 From: Ashcon Partovi Date: Wed, 22 Feb 2023 18:19:00 -0800 Subject: [PATCH] Actually fix double zip issue --- dist/setup.js | 18 +++++++++++------- src/setup.ts | 23 ++++++++++++----------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/dist/setup.js b/dist/setup.js index 1b65dae..0a2d5af 100644 --- a/dist/setup.js +++ b/dist/setup.js @@ -74,14 +74,18 @@ function getDownloadUrl(options) { } async function extractBun(path) { for (const entry of await readdir(path, { withFileTypes: true })) { - const entryPath = join(path, entry.name); - action.debug(`Looking: ${entryPath}`); - if (entry.name === "bun" && entry.isFile()) { - action.debug(`Found: ${entryPath}`); - return entryPath; + const { name } = entry; + const entryPath = join(path, name); + if (entry.isFile()) { + if (name === "bun") { + return entryPath; + } + if (/^bun.*\.zip/.test(name)) { + const extractedPath = await extractZip(entryPath); + return extractBun(extractedPath); + } } - if (entry.name.startsWith("bun") && entry.isDirectory()) { - action.debug(`Continue looking: ${entryPath}`); + if (/^bun/.test(name) && entry.isDirectory()) { return extractBun(entryPath); } } diff --git a/src/setup.ts b/src/setup.ts index d533260..1d760d7 100644 --- a/src/setup.ts +++ b/src/setup.ts @@ -39,10 +39,7 @@ export default async (options?: { if (!cacheHit) { action.info(`Downloading a new version of Bun: ${url}`); const zipPath = await downloadTool(url); - let extractedPath = await extractZip(zipPath); - if (extractedPath.endsWith(".zip")) { - extractedPath = await extractZip(extractedPath); - } + const extractedPath = await extractZip(zipPath); const exePath = await extractBun(extractedPath); await mv(exePath, path); version = await verifyBun(path); @@ -101,14 +98,18 @@ function getDownloadUrl(options?: { async function extractBun(path: string): Promise { for (const entry of await readdir(path, { withFileTypes: true })) { - const entryPath = join(path, entry.name); - action.debug(`Looking: ${entryPath}`); - if (entry.name === "bun" && entry.isFile()) { - action.debug(`Found: ${entryPath}`); - return entryPath; + const { name } = entry; + const entryPath = join(path, name); + if (entry.isFile()) { + if (name === "bun") { + return entryPath; + } + if (/^bun.*\.zip/.test(name)) { + const extractedPath = await extractZip(entryPath); + return extractBun(extractedPath); + } } - if (entry.name.startsWith("bun") && entry.isDirectory()) { - action.debug(`Continue looking: ${entryPath}`); + if (/^bun/.test(name) && entry.isDirectory()) { return extractBun(entryPath); } }