Skip to content

Commit

Permalink
fix: add .zip extension if it's not present
Browse files Browse the repository at this point in the history
Workaround for actions/toolkit#1179

Fixes #79
  • Loading branch information
xhyrom committed May 8, 2024
1 parent 77ae171 commit f885433
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -119,7 +119,7 @@ async function downloadBun(
url: string,
bunPath: string
): Promise<string | undefined> {
const zipPath = await downloadTool(url);
const zipPath = addExtension(await downloadTool(url), ".zip");
const extractedZipPath = await extractZip(zipPath);
const extractedBunPath = await extractBun(extractedZipPath);
try {
Expand Down
11 changes: 10 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -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<T>(
Expand All @@ -18,6 +18,15 @@ export function retry<T>(
});
}

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],
Expand Down

0 comments on commit f885433

Please sign in to comment.