fix: getPlatform, getArchitecture + eversion

This commit is contained in:
Jozef Steinhübl 2024-07-29 20:58:56 +02:00
parent c3e2edf950
commit 528c4707b7
No known key found for this signature in database
GPG Key ID: E6BC90C91973B08F
2 changed files with 20 additions and 6 deletions

View File

@ -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 = {
@ -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/"
);

View File

@ -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],