mirror of
https://github.com/oven-sh/setup-bun.git
synced 2025-07-18 04:28:28 +02:00
feat: read from all known files if not specified
This commit is contained in:
parent
116db8199a
commit
e95e252b85
1 changed files with 25 additions and 11 deletions
18
src/utils.ts
18
src/utils.ts
|
@ -1,4 +1,4 @@
|
||||||
import { warning } from "@actions/core";
|
import { debug, warning } from "@actions/core";
|
||||||
import { existsSync, readFileSync } from "node:fs";
|
import { existsSync, readFileSync } from "node:fs";
|
||||||
import { join, basename } from "node:path";
|
import { join, basename } from "node:path";
|
||||||
|
|
||||||
|
@ -25,12 +25,25 @@ const FILE_VERSION_READERS = {
|
||||||
".bumrc": (content: string) => content,
|
".bumrc": (content: string) => content,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function readVersionFromFile(file: string): string | undefined {
|
export function readVersionFromFile(
|
||||||
|
files: string | string[]
|
||||||
|
): string | undefined {
|
||||||
const cwd = process.env.GITHUB_WORKSPACE;
|
const cwd = process.env.GITHUB_WORKSPACE;
|
||||||
if (!cwd) {
|
if (!cwd) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!files) {
|
||||||
|
warning("No version file specified, trying all known files.");
|
||||||
|
readVersionFromFile(Object.keys(FILE_VERSION_READERS));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Array.isArray(files)) files = [files];
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
debug(`Reading version from ${file}`);
|
||||||
|
|
||||||
const path = join(cwd, file);
|
const path = join(cwd, file);
|
||||||
const base = basename(file);
|
const base = basename(file);
|
||||||
|
|
||||||
|
@ -45,3 +58,4 @@ export function readVersionFromFile(file: string): string | undefined {
|
||||||
warning(`Failed to read ${file}: ${message}`);
|
warning(`Failed to read ${file}: ${message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue