feat: support .tool-versions (#68)

* feat: support .tool-versions

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Jozef Steinhübl 2024-04-02 10:26:15 +02:00 committed by GitHub
parent 194c60efc3
commit 9e6479509b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 81 additions and 26 deletions

View file

@ -36,8 +36,32 @@ function readVersionFromPackageJson(): string | undefined {
}
}
function readVersionFromToolVersions(): string | undefined {
const cwd = process.env.GITHUB_WORKSPACE;
if (!cwd) {
return;
}
const path = join(cwd, ".tool-versions");
try {
if (!existsSync(path)) {
return;
}
const match = readFileSync(path, "utf8").match(/^bun\s(?<version>.*?)$/m);
return match?.groups?.version;
} catch (error) {
const { message } = error as Error;
warning(`Failed to read .tool-versions: ${message}`);
}
}
runAction({
version: getInput("bun-version") || readVersionFromPackageJson() || undefined,
version:
getInput("bun-version") ||
readVersionFromPackageJson() ||
readVersionFromToolVersions() ||
undefined,
customUrl: getInput("bun-download-url") || undefined,
registryUrl: getInput("registry-url") || undefined,
scope: getInput("scope") || undefined,