mirror of
https://github.com/oven-sh/setup-bun.git
synced 2025-07-18 04:28:28 +02:00
Various improvements and fixes to setup-bun (#40)
* Do not save cache on hit * Support Windows (canary only) * Support `registry-url` and `scope`
This commit is contained in:
parent
830e319e28
commit
a93230df19
14 changed files with 994 additions and 78881 deletions
46
src/index.ts
Normal file
46
src/index.ts
Normal file
|
@ -0,0 +1,46 @@
|
|||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { existsSync, readFileSync } from "node:fs";
|
||||
import { getInput, setOutput, setFailed, warning } from "@actions/core";
|
||||
import runAction from "./action.js";
|
||||
|
||||
if (!process.env.RUNNER_TEMP) {
|
||||
process.env.RUNNER_TEMP = tmpdir();
|
||||
}
|
||||
|
||||
function readVersionFromPackageJson(): string | undefined {
|
||||
const cwd = process.env.GITHUB_WORKSPACE;
|
||||
if (!cwd) {
|
||||
return;
|
||||
}
|
||||
const path = join(cwd, "package.json");
|
||||
try {
|
||||
if (!existsSync(path)) {
|
||||
return;
|
||||
}
|
||||
const { packageManager } = JSON.parse(readFileSync(path, "utf8"));
|
||||
if (!packageManager?.startsWith("bun@")) {
|
||||
return;
|
||||
}
|
||||
const [_, version] = packageManager.split("bun@");
|
||||
return version;
|
||||
} catch (error) {
|
||||
const { message } = error as Error;
|
||||
warning(`Failed to read package.json: ${message}`);
|
||||
}
|
||||
}
|
||||
|
||||
runAction({
|
||||
version: getInput("bun-version") || readVersionFromPackageJson() || undefined,
|
||||
customUrl: getInput("bun-download-url") || undefined,
|
||||
registryUrl: getInput("registry-url") || undefined,
|
||||
scope: getInput("scope") || undefined,
|
||||
})
|
||||
.then(({ version, revision, cacheHit }) => {
|
||||
setOutput("bun-version", version);
|
||||
setOutput("bun-revision", revision);
|
||||
setOutput("cache-hit", cacheHit);
|
||||
})
|
||||
.catch((error) => {
|
||||
setFailed(error);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue