mirror of
https://github.com/oven-sh/setup-bun.git
synced 2025-02-23 18:50:10 +08:00
Fix not being added to path
This commit is contained in:
parent
9c14b74b45
commit
3f252a86a6
14
dist/action.js
vendored
14
dist/action.js
vendored
@ -2,16 +2,16 @@ import { tmpdir } from "node:os";
|
|||||||
import * as action from "@actions/core";
|
import * as action from "@actions/core";
|
||||||
import setup from "./setup.js";
|
import setup from "./setup.js";
|
||||||
if (!process.env.RUNNER_TEMP) {
|
if (!process.env.RUNNER_TEMP) {
|
||||||
process.env.RUNNER_TEMP = tmpdir();
|
process.env.RUNNER_TEMP = tmpdir();
|
||||||
}
|
}
|
||||||
setup({
|
setup({
|
||||||
version: action.getInput("bun-version") || undefined,
|
version: action.getInput("bun-version") || undefined,
|
||||||
customUrl: action.getInput("bun-download-url") || undefined,
|
customUrl: action.getInput("bun-download-url") || undefined,
|
||||||
})
|
})
|
||||||
.then(({ version, cacheHit }) => {
|
.then(({ version, cacheHit }) => {
|
||||||
action.setOutput("bun-version", version);
|
action.setOutput("bun-version", version);
|
||||||
action.setOutput("cache-hit", cacheHit ? "1" : "0");
|
action.setOutput("cache-hit", cacheHit ? "1" : "0");
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
action.setFailed(error);
|
action.setFailed(error);
|
||||||
});
|
});
|
||||||
|
143
dist/setup.js
vendored
143
dist/setup.js
vendored
@ -8,88 +8,85 @@ import { restoreCache, saveCache } from "@actions/cache";
|
|||||||
import { mv } from "@actions/io";
|
import { mv } from "@actions/io";
|
||||||
import { getExecOutput } from "@actions/exec";
|
import { getExecOutput } from "@actions/exec";
|
||||||
export default async (options) => {
|
export default async (options) => {
|
||||||
const { url, cacheKey } = getDownloadUrl(options);
|
const { url, cacheKey } = getDownloadUrl(options);
|
||||||
const cacheEnabled = cacheKey && cache.isFeatureAvailable();
|
const cacheEnabled = cacheKey && cache.isFeatureAvailable();
|
||||||
const path = join(homedir(), ".bun", "bin", "bun");
|
const dir = join(homedir(), ".bun", "bin");
|
||||||
let version;
|
action.addPath(dir);
|
||||||
let cacheHit = false;
|
const path = join(dir, "bun");
|
||||||
if (cacheEnabled) {
|
let version;
|
||||||
const cacheRestored = await restoreCache([path], cacheKey);
|
let cacheHit = false;
|
||||||
if (cacheRestored) {
|
if (cacheEnabled) {
|
||||||
version = await verifyBun(path);
|
const cacheRestored = await restoreCache([path], cacheKey);
|
||||||
if (version) {
|
if (cacheRestored) {
|
||||||
cacheHit = true;
|
version = await verifyBun(path);
|
||||||
action.info("Using a cached version of Bun.");
|
if (version) {
|
||||||
} else {
|
cacheHit = true;
|
||||||
action.warning(
|
action.info("Using a cached version of Bun.");
|
||||||
"Found a cached version of Bun, but it appears to be corrupted? Attempting to download a new version."
|
}
|
||||||
);
|
else {
|
||||||
}
|
action.warning("Found a cached version of Bun, but it appears to be corrupted? Attempting to download a new version.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (!cacheHit) {
|
||||||
if (!cacheHit) {
|
action.info(`Downloading a new version of Bun: ${url}`);
|
||||||
action.info(`Downloading a new version of Bun: ${url}`);
|
const zipPath = await downloadTool(url);
|
||||||
const zipPath = await downloadTool(url);
|
const extractedPath = await extractZip(zipPath);
|
||||||
const extractedPath = await extractZip(zipPath);
|
const exePath = await extractBun(extractedPath);
|
||||||
const exePath = await extractBun(extractedPath);
|
await mv(exePath, path);
|
||||||
await mv(exePath, path);
|
version = await verifyBun(path);
|
||||||
version = await verifyBun(path);
|
|
||||||
}
|
|
||||||
if (!version) {
|
|
||||||
throw new Error(
|
|
||||||
"Downloaded a new version of Bun, but failed to check its version? Try again in debug mode."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (cacheEnabled) {
|
|
||||||
try {
|
|
||||||
await saveCache([path], cacheKey);
|
|
||||||
} catch (error) {
|
|
||||||
action.warning("Failed to save Bun to cache.");
|
|
||||||
}
|
}
|
||||||
}
|
if (!version) {
|
||||||
return {
|
throw new Error("Downloaded a new version of Bun, but failed to check its version? Try again in debug mode.");
|
||||||
version,
|
}
|
||||||
cacheHit,
|
if (cacheEnabled) {
|
||||||
};
|
try {
|
||||||
|
await saveCache([path], cacheKey);
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
action.warning("Failed to save Bun to cache.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
version,
|
||||||
|
cacheHit,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
function getDownloadUrl(options) {
|
function getDownloadUrl(options) {
|
||||||
if (options?.customUrl) {
|
if (options?.customUrl) {
|
||||||
|
return {
|
||||||
|
url: options.customUrl,
|
||||||
|
cacheKey: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const release = options?.version ?? "latest";
|
||||||
|
const os = options?.os ?? process.platform;
|
||||||
|
const arch = options?.arch ?? process.arch;
|
||||||
|
const avx2 = options?.avx2 ?? true;
|
||||||
|
const profile = options?.profile ?? false;
|
||||||
|
const { href } = new URL(`${release}/${os}/${arch}?avx2=${avx2}&profile=${profile}`, "https://bun.sh/download/");
|
||||||
return {
|
return {
|
||||||
url: options.customUrl,
|
url: href,
|
||||||
cacheKey: null,
|
cacheKey: /^canary|latest$/i.test(release)
|
||||||
|
? null
|
||||||
|
: `bun-${release}-${os}-${arch}-${avx2}-${profile}`,
|
||||||
};
|
};
|
||||||
}
|
|
||||||
const release = options?.version ?? "latest";
|
|
||||||
const os = options?.os ?? process.platform;
|
|
||||||
const arch = options?.arch ?? process.arch;
|
|
||||||
const avx2 = options?.avx2 ?? true;
|
|
||||||
const profile = options?.profile ?? false;
|
|
||||||
const { href } = new URL(
|
|
||||||
`${release}/${os}/${arch}?avx2=${avx2}&profile=${profile}`,
|
|
||||||
"https://bun.sh/download/"
|
|
||||||
);
|
|
||||||
return {
|
|
||||||
url: href,
|
|
||||||
cacheKey: /^canary|latest$/i.test(release)
|
|
||||||
? null
|
|
||||||
: `bun-${release}-${os}-${arch}-${avx2}-${profile}`,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
async function extractBun(path) {
|
async function extractBun(path) {
|
||||||
for (const entry of await readdir(path, { withFileTypes: true })) {
|
for (const entry of await readdir(path, { withFileTypes: true })) {
|
||||||
const entryPath = join(path, entry.name);
|
const entryPath = join(path, entry.name);
|
||||||
if (entry.name === "bun" && entry.isFile()) {
|
if (entry.name === "bun" && entry.isFile()) {
|
||||||
return entryPath;
|
return entryPath;
|
||||||
|
}
|
||||||
|
if (entry.isDirectory()) {
|
||||||
|
return extractBun(entryPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (entry.isDirectory()) {
|
throw new Error("Could not find executable: bun");
|
||||||
return extractBun(entryPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new Error("Could not find executable: bun");
|
|
||||||
}
|
}
|
||||||
async function verifyBun(path) {
|
async function verifyBun(path) {
|
||||||
const { exitCode, stdout } = await getExecOutput(path, ["--version"], {
|
const { exitCode, stdout } = await getExecOutput(path, ["--version"], {
|
||||||
ignoreReturnCode: true,
|
ignoreReturnCode: true,
|
||||||
});
|
});
|
||||||
return exitCode === 0 ? stdout.trim() : undefined;
|
return exitCode === 0 ? stdout.trim() : undefined;
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,9 @@ export default async (options?: {
|
|||||||
}> => {
|
}> => {
|
||||||
const { url, cacheKey } = getDownloadUrl(options);
|
const { url, cacheKey } = getDownloadUrl(options);
|
||||||
const cacheEnabled = cacheKey && cache.isFeatureAvailable();
|
const cacheEnabled = cacheKey && cache.isFeatureAvailable();
|
||||||
const path = join(homedir(), ".bun", "bin", "bun");
|
const dir = join(homedir(), ".bun", "bin");
|
||||||
|
action.addPath(dir);
|
||||||
|
const path = join(dir, "bun");
|
||||||
let version: string | undefined;
|
let version: string | undefined;
|
||||||
let cacheHit = false;
|
let cacheHit = false;
|
||||||
if (cacheEnabled) {
|
if (cacheEnabled) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user