From f885433d158bb48fb60219f855edcabde644a49e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Wed, 8 May 2024 10:18:01 +0200 Subject: [PATCH] fix: add .zip extension if it's not present Workaround for https://github.com/actions/toolkit/issues/1179 Fixes https://github.com/oven-sh/setup-bun/issues/79 --- src/action.ts | 4 ++-- src/utils.ts | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/action.ts b/src/action.ts index 2f655a2..da8a580 100644 --- a/src/action.ts +++ b/src/action.ts @@ -13,7 +13,7 @@ import { downloadTool, extractZip } from "@actions/tool-cache"; import { getExecOutput } from "@actions/exec"; import { writeBunfig } from "./bunfig"; import { saveState } from "@actions/core"; -import { retry } from "./utils"; +import { addExtension, retry } from "./utils"; export type Input = { customUrl?: string; @@ -119,7 +119,7 @@ async function downloadBun( url: string, bunPath: string ): Promise { - const zipPath = await downloadTool(url); + const zipPath = addExtension(await downloadTool(url), ".zip"); const extractedZipPath = await extractZip(zipPath); const extractedBunPath = await extractBun(extractedZipPath); try { diff --git a/src/utils.ts b/src/utils.ts index 26a7c6b..e757dc9 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,6 +1,6 @@ import { debug, warning } from "@actions/core"; import { info } from "node:console"; -import { existsSync, readFileSync } from "node:fs"; +import { existsSync, readFileSync, renameSync } from "node:fs"; import { join, basename } from "node:path"; export function retry( @@ -18,6 +18,15 @@ export function retry( }); } +export function addExtension(path: string, ext: string): string { + if (!path.endsWith(ext)) { + renameSync(path, path + ext); + return path + ext; + } + + return path; +} + const FILE_VERSION_READERS = { "package.json": (content: string) => JSON.parse(content).packageManager?.split("bun@")?.[1],