Skip to content

Commit

Permalink
fix: getPlatform, getArchitecture + eversion
Browse files Browse the repository at this point in the history
  • Loading branch information
xhyrom committed Jul 29, 2024
1 parent c3e2edf commit 528c470
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
12 changes: 6 additions & 6 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 { addExtension, request } from "./utils";
import { addExtension, getArchitecture, getPlatform, request } from "./utils";
import { compareVersions, satisfies, validate } from "compare-versions";

export type Input = {
Expand Down Expand Up @@ -179,18 +179,18 @@ async function getDownloadUrl(options: Input): Promise<string> {
if (!tag) {
tags = tags.filter((t) => validate(t)).sort(compareVersions);

if (version === "latest") tag = tags.at(-1);
else tag = tags.filter((t) => satisfies(t, version)).at(-1);
if (version === "latest") tag = `bun-v${tags.at(-1)}`;
else tag = `bun-${tags.filter((t) => satisfies(t, version)).at(-1)}`;
}

const eversion = encodeURIComponent(tag ?? version);
const eos = encodeURIComponent(os ?? process.platform);
const earch = encodeURIComponent(arch ?? process.arch);
const eos = encodeURIComponent(os ?? getPlatform());
const earch = encodeURIComponent(arch ?? getArchitecture());
const eavx2 = encodeURIComponent(avx2 ? "-baseline" : "");
const eprofile = encodeURIComponent(profile ? "-profile" : "");

const { href } = new URL(
`bun-${eversion}/bun-${eos}-${earch}${eavx2}${eprofile}.zip`,
`${eversion}/bun-${eos}-${earch}${eavx2}${eprofile}.zip`,
"https://github.com/oven-sh/bun/releases/download/"
);

Expand Down
14 changes: 14 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ export function addExtension(path: string, ext: string): string {
return path;
}

export function getPlatform(): string {
const platform = process.platform;
if (platform === "win32") return "windows";

return platform;
}

export function getArchitecture(): string {
const arch = process.arch;
if (arch === "arm64") return "aarch64";

return arch;
}

const FILE_VERSION_READERS = {
"package.json": (content: string) =>
JSON.parse(content).packageManager?.split("bun@")?.[1],
Expand Down

0 comments on commit 528c470

Please sign in to comment.