feat: use packageManager from package.json as default bun version (#152)

* Initial plan

* feat: make packageManager from package.json the default bun version

Co-authored-by: xhyrom <56601352+xhyrom@users.noreply.github.com>

* test: improve cross-platform compatibility and cleanup in utils tests

Co-authored-by: xhyrom <56601352+xhyrom@users.noreply.github.com>

* docs: update README to document automatic package.json version detection

Co-authored-by: xhyrom <56601352+xhyrom@users.noreply.github.com>

* conflicts

* ci: setup-bun-from-package-json-without-specified-field

* ci: setup-bun-from-package-json-without-specified-field

* ci: no cache

---------

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 <contact@xhyrom.dev>
This commit is contained in:
Copilot
2026-01-05 12:45:25 +01:00
committed by GitHub
parent b02f8a8a6e
commit 563911925f
6 changed files with 181 additions and 108 deletions

View File

@@ -26,6 +26,7 @@ runAction({
version:
getInput("bun-version") ||
readVersionFromFile(getInput("bun-version-file")) ||
readVersionFromFile("package.json", true) ||
undefined,
customUrl: getInput("bun-download-url") || undefined,
registries: registries,

View File

@@ -80,7 +80,10 @@ const FILE_VERSION_READERS = {
".bun-version": (content: string) => content,
};
export function readVersionFromFile(file: string): string | undefined {
export function readVersionFromFile(
file: string,
silent = false,
): string | undefined {
const cwd = process.env.GITHUB_WORKSPACE;
if (!cwd) {
return;
@@ -96,7 +99,9 @@ export function readVersionFromFile(file: string): string | undefined {
const base = basename(file);
if (!existsSync(path)) {
warning(`File ${path} not found`);
if (!silent) {
warning(`File ${path} not found`);
}
return;
}
@@ -107,12 +112,16 @@ export function readVersionFromFile(file: string): string | undefined {
output = reader(readFileSync(path, "utf8"))?.trim();
if (!output) {
warning(`Failed to read version from ${file}`);
if (!silent) {
warning(`Failed to read version from ${file}`);
}
return;
}
} catch (error) {
const { message } = error as Error;
warning(`Failed to read ${file}: ${message}`);
if (!silent) {
warning(`Failed to read ${file}: ${message}`);
}
} finally {
if (output) {
info(`Obtained version ${output} from ${file}`);