* feat: fallback arm64 to x64 architecture for win32 platform closes https://github.com/oven-sh/setup-bun/issues/130 * [autofix.ci] apply automated fixes * ci: test on windows-11-arm runner * refactor: move logic to getEffectiveArch func * [autofix.ci] apply automated fixes * feat: add warning message for windows arm64 fallback to x64 * [autofix.ci] apply automated fixes * feat: don't mention arch in warning msg aboout fallback * [autofix.ci] apply automated fixes * debug time * [autofix.ci] apply automated fixes * feat: force baseline for win32 arm fallback to x64 * [autofix.ci] apply automated fixes * ci: dont use windows-11-arm on setup bun from download url * fix * [autofix.ci] apply automated fixes * fix * [autofix.ci] apply automated fixes * fix * [autofix.ci] apply automated fixes * fix * [autofix.ci] apply automated fixes * fix * [autofix.ci] apply automated fixes * apply changes Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * [autofix.ci] apply automated fixes * docs: clarify * [autofix.ci] apply automated fixes * test: add unit tests for getAvx2 Windows ARM64 fallback logic (#154) * Initial plan * Add unit tests for getAvx2 function Co-authored-by: xhyrom <56601352+xhyrom@users.noreply.github.com> * Consolidate duplicate test assertions in getAvx2 tests Co-authored-by: xhyrom <56601352+xhyrom@users.noreply.github.com> * Fix whitespace formatting in test file Co-authored-by: xhyrom <56601352+xhyrom@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: xhyrom <56601352+xhyrom@users.noreply.github.com> * test: add unit tests for getArchitecture and getAvx2 Windows ARM64 fallback logic (#153) * Initial plan * Add unit tests for getArchitecture function Co-authored-by: xhyrom <56601352+xhyrom@users.noreply.github.com> * Remove unused import in utils.spec.ts Co-authored-by: xhyrom <56601352+xhyrom@users.noreply.github.com> * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Merge pr-131 and resolve test file conflicts Co-authored-by: xhyrom <56601352+xhyrom@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: xhyrom <56601352+xhyrom@users.noreply.github.com> Co-authored-by: Jozef Steinhübl <generalkubo@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
123 lines
3.2 KiB
TypeScript
123 lines
3.2 KiB
TypeScript
import { debug, warning } from "@actions/core";
|
|
import { info } from "node:console";
|
|
import { existsSync, readFileSync, renameSync } from "node:fs";
|
|
import { resolve, basename } from "node:path";
|
|
|
|
export async function request(
|
|
url: string,
|
|
init?: RequestInit,
|
|
): Promise<Response> {
|
|
const headers = new Headers(init?.headers);
|
|
if (!headers.has("User-Agent")) {
|
|
headers.set("User-Agent", "@oven-sh/setup-bun");
|
|
}
|
|
|
|
const res = await fetch(url, {
|
|
...init,
|
|
headers,
|
|
});
|
|
if (!res.ok) {
|
|
const body = await res.text().catch(() => "");
|
|
throw new Error(
|
|
`Failed to fetch url ${url}. (status code: ${res.status}, status text: ${res.statusText})${body ? `\n${body}` : ""}`,
|
|
);
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
export function addExtension(path: string, ext: string): string {
|
|
if (!path.endsWith(ext)) {
|
|
renameSync(path, path + ext);
|
|
return path + ext;
|
|
}
|
|
|
|
return path;
|
|
}
|
|
|
|
export function getPlatform(): string {
|
|
const platform = process.platform;
|
|
if (platform === "win32") return "windows";
|
|
|
|
return platform;
|
|
}
|
|
|
|
export function getArchitecture(os: string, arch: string): string {
|
|
if (os === "windows" && (arch === "aarch64" || arch === "arm64")) {
|
|
warning(
|
|
[
|
|
"⚠️ Bun does not provide native arm64 builds for Windows.",
|
|
"Using x64 baseline build which will run through Microsoft's x64 emulation layer.",
|
|
"This may result in reduced performance and potential compatibility issues.",
|
|
"💡 For best performance, consider using x64 Windows runners or other platforms with native support.",
|
|
].join("\n"),
|
|
);
|
|
|
|
return "x64";
|
|
}
|
|
|
|
if (arch === "arm64") return "aarch64";
|
|
return arch;
|
|
}
|
|
|
|
export function getAvx2(os: string, arch: string, avx2?: boolean): boolean {
|
|
// Temporary workaround for absence of arm64 builds on Windows (#130)
|
|
if (os === "windows" && (arch === "aarch64" || arch === "arm64")) {
|
|
return false;
|
|
}
|
|
|
|
return avx2 ?? true;
|
|
}
|
|
|
|
const FILE_VERSION_READERS = {
|
|
"package.json": (content: string) => {
|
|
const pkg = JSON.parse(content);
|
|
return pkg.packageManager?.split("bun@")?.[1] ?? pkg.engines?.bun;
|
|
},
|
|
".tool-versions": (content: string) =>
|
|
content.match(/^bun\s*(?<version>.*?)$/m)?.groups?.version,
|
|
".bumrc": (content: string) => content, // https://github.com/owenizedd/bum
|
|
".bun-version": (content: string) => content,
|
|
};
|
|
|
|
export function readVersionFromFile(file: string): string | undefined {
|
|
const cwd = process.env.GITHUB_WORKSPACE;
|
|
if (!cwd) {
|
|
return;
|
|
}
|
|
|
|
if (!file) {
|
|
return;
|
|
}
|
|
|
|
debug(`Reading version from ${file}`);
|
|
|
|
const path = resolve(cwd, file);
|
|
const base = basename(file);
|
|
|
|
if (!existsSync(path)) {
|
|
warning(`File ${path} not found`);
|
|
return;
|
|
}
|
|
|
|
const reader = FILE_VERSION_READERS[base] ?? (() => undefined);
|
|
|
|
let output: string | undefined;
|
|
try {
|
|
output = reader(readFileSync(path, "utf8"))?.trim();
|
|
|
|
if (!output) {
|
|
warning(`Failed to read version from ${file}`);
|
|
return;
|
|
}
|
|
} catch (error) {
|
|
const { message } = error as Error;
|
|
warning(`Failed to read ${file}: ${message}`);
|
|
} finally {
|
|
if (output) {
|
|
info(`Obtained version ${output} from ${file}`);
|
|
return output;
|
|
}
|
|
}
|
|
}
|