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:
Ashcon Partovi 2023-11-17 15:58:17 -08:00 committed by GitHub
parent 830e319e28
commit a93230df19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 994 additions and 78881 deletions

46
src/index.ts Normal file
View 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);
});