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

@ -76,3 +76,34 @@ jobs:
echo "Expected version to be 1.0.0, got ${{ steps.bun.outputs.version }}"
exit 1
fi
setup-bun-from-tool-versions:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
content:
- "bun 1.0.0"
- "bun1.0.0"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup package.json
run: |
echo "bun ${{ matrix.content }}" > .tool-versions
- name: Setup Bun
uses: ./
- name: Run Bun
id: bun
run: |
bun --version
echo "version=$(bun --version)" >> $GITHUB_OUTPUT
- name: Check version
run: |
if [[ "${{ steps.bun.outputs.version }}" == "1.0.0" ]]; then
echo "Version is 1.0.0"
else
echo "Expected version to be 1.0.0, got ${{ steps.bun.outputs.version }}"
exit 1
fi

50
dist/setup/index.js generated vendored

File diff suppressed because one or more lines are too long

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,