mirror of
https://github.com/oven-sh/setup-bun.git
synced 2025-02-23 10:40:10 +08:00
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:
parent
194c60efc3
commit
9e6479509b
31
.github/workflows/test.yml
vendored
31
.github/workflows/test.yml
vendored
@ -76,3 +76,34 @@ jobs:
|
|||||||
echo "Expected version to be 1.0.0, got ${{ steps.bun.outputs.version }}"
|
echo "Expected version to be 1.0.0, got ${{ steps.bun.outputs.version }}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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
50
dist/setup/index.js
generated
vendored
File diff suppressed because one or more lines are too long
26
src/index.ts
26
src/index.ts
@ -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({
|
runAction({
|
||||||
version: getInput("bun-version") || readVersionFromPackageJson() || undefined,
|
version:
|
||||||
|
getInput("bun-version") ||
|
||||||
|
readVersionFromPackageJson() ||
|
||||||
|
readVersionFromToolVersions() ||
|
||||||
|
undefined,
|
||||||
customUrl: getInput("bun-download-url") || undefined,
|
customUrl: getInput("bun-download-url") || undefined,
|
||||||
registryUrl: getInput("registry-url") || undefined,
|
registryUrl: getInput("registry-url") || undefined,
|
||||||
scope: getInput("scope") || undefined,
|
scope: getInput("scope") || undefined,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user