mirror of
https://github.com/oven-sh/setup-bun.git
synced 2025-07-18 04:28:28 +02:00
Use bun's bundler instead of node_modules
This commit is contained in:
parent
4573031972
commit
5a4722c39d
6 changed files with 51918 additions and 121 deletions
12
.github/workflows/action.yml
vendored
12
.github/workflows/action.yml
vendored
|
@ -20,7 +20,15 @@ jobs:
|
|||
- latest
|
||||
- canary
|
||||
- "0.5.6"
|
||||
- "0.5.x"
|
||||
- ">=0.5.7"
|
||||
- "9be68ac2350b965037f408ce4d47c3b9d9a76b63"
|
||||
baseline:
|
||||
- "true"
|
||||
- "false"
|
||||
profile:
|
||||
- "true"
|
||||
- "false"
|
||||
steps:
|
||||
- id: checkout
|
||||
name: Checkout
|
||||
|
@ -30,7 +38,11 @@ jobs:
|
|||
uses: ./
|
||||
with:
|
||||
bun-version: ${{ matrix.bun-version }}
|
||||
baseline: ${{ matrix.baseline }}
|
||||
profile: ${{ matrix.profile }}
|
||||
- id: verify-bun
|
||||
name: Verify Bun
|
||||
run: |
|
||||
which bun
|
||||
which bunx
|
||||
bun --version
|
||||
|
|
19
action.yml
19
action.yml
|
@ -6,14 +6,29 @@ branding:
|
|||
color: white
|
||||
inputs:
|
||||
bun-version:
|
||||
description: 'The version of Bun to install. (e.g. "latest", "canary", "0.5.6", <sha>)'
|
||||
description: 'The version of Bun to download. (e.g. "latest", "canary", "0.5.6", ">0.6.0", <sha>)'
|
||||
default: latest
|
||||
required: false
|
||||
bun-download-url:
|
||||
description: "A custom URL to download Bun as a .zip file."
|
||||
required: false
|
||||
check-latest:
|
||||
description: "If it should always check for a new version of Bun."
|
||||
default: "false"
|
||||
required: false
|
||||
baseline:
|
||||
description: "If a baseline build of Bun should be used."
|
||||
default: "false"
|
||||
required: false
|
||||
profile:
|
||||
description: "If a profile build of Bun should be used."
|
||||
default: "false"
|
||||
required: false
|
||||
outputs:
|
||||
bun-version:
|
||||
description: The version of Bun that was installed.
|
||||
cache-hit:
|
||||
description: If the version of Bun was cached.
|
||||
description: If the version of Bun was cached. (e.g. "true" or "false")
|
||||
runs:
|
||||
using: node16
|
||||
main: dist/action.js
|
||||
|
|
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
51901
dist/action.js
vendored
51901
dist/action.js
vendored
File diff suppressed because one or more lines are too long
99
dist/setup.js
vendored
99
dist/setup.js
vendored
|
@ -1,99 +0,0 @@
|
|||
import { homedir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { readdir } from "node:fs/promises";
|
||||
import * as action from "@actions/core";
|
||||
import { downloadTool, extractZip } from "@actions/tool-cache";
|
||||
import * as cache from "@actions/cache";
|
||||
import { restoreCache, saveCache } from "@actions/cache";
|
||||
import { mv } from "@actions/io";
|
||||
import { getExecOutput } from "@actions/exec";
|
||||
export default async (options) => {
|
||||
const { url, cacheKey } = getDownloadUrl(options);
|
||||
const cacheEnabled = cacheKey && cache.isFeatureAvailable();
|
||||
const dir = join(homedir(), ".bun", "bin");
|
||||
action.addPath(dir);
|
||||
const path = join(dir, "bun");
|
||||
let version;
|
||||
let cacheHit = false;
|
||||
if (cacheEnabled) {
|
||||
const cacheRestored = await restoreCache([path], cacheKey);
|
||||
if (cacheRestored) {
|
||||
version = await verifyBun(path);
|
||||
if (version) {
|
||||
cacheHit = true;
|
||||
action.info("Using a cached version of Bun.");
|
||||
}
|
||||
else {
|
||||
action.warning("Found a cached version of Bun, but it appears to be corrupted? Attempting to download a new version.");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!cacheHit) {
|
||||
action.info(`Downloading a new version of Bun: ${url}`);
|
||||
const zipPath = await downloadTool(url);
|
||||
const extractedPath = await extractZip(zipPath);
|
||||
const exePath = await extractBun(extractedPath);
|
||||
await mv(exePath, 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.");
|
||||
}
|
||||
}
|
||||
return {
|
||||
version,
|
||||
cacheHit,
|
||||
};
|
||||
};
|
||||
function getDownloadUrl(options) {
|
||||
if (options?.customUrl) {
|
||||
return {
|
||||
url: options.customUrl,
|
||||
cacheKey: null,
|
||||
};
|
||||
}
|
||||
const release = encodeURIComponent(options?.version ?? "latest");
|
||||
const os = encodeURIComponent(options?.os ?? process.platform);
|
||||
const arch = encodeURIComponent(options?.arch ?? process.arch);
|
||||
const avx2 = encodeURIComponent(options?.avx2 ?? true);
|
||||
const profile = encodeURIComponent(options?.profile ?? false);
|
||||
const { href } = new URL(`${release}/${os}/${arch}?avx2=${avx2}&profile=${profile}`, "https://bun.sh/download/");
|
||||
return {
|
||||
url: href,
|
||||
cacheKey: /^latest|canary|action/i.test(release)
|
||||
? null
|
||||
: `bun-${release}-${os}-${arch}-${avx2}-${profile}`,
|
||||
};
|
||||
}
|
||||
async function extractBun(path) {
|
||||
for (const entry of await readdir(path, { withFileTypes: true })) {
|
||||
const { name } = entry;
|
||||
const entryPath = join(path, name);
|
||||
if (entry.isFile()) {
|
||||
if (name === "bun") {
|
||||
return entryPath;
|
||||
}
|
||||
if (/^bun.*\.zip/.test(name)) {
|
||||
const extractedPath = await extractZip(entryPath);
|
||||
return extractBun(extractedPath);
|
||||
}
|
||||
}
|
||||
if (/^bun/.test(name) && entry.isDirectory()) {
|
||||
return extractBun(entryPath);
|
||||
}
|
||||
}
|
||||
throw new Error("Could not find executable: bun");
|
||||
}
|
||||
async function verifyBun(path) {
|
||||
const { exitCode, stdout } = await getExecOutput(path, ["--version"], {
|
||||
ignoreReturnCode: true,
|
||||
});
|
||||
return exitCode === 0 ? stdout.trim() : undefined;
|
||||
}
|
|
@ -19,7 +19,7 @@
|
|||
"author": "xHyroM",
|
||||
"scripts": {
|
||||
"format": "prettier --write src",
|
||||
"build": "tsc -p .",
|
||||
"build": "bun build src/action.ts --outdir dist --target=node",
|
||||
"start": "ts-node-esm src/action.ts",
|
||||
"start:dist": "node dist/action.js"
|
||||
},
|
||||
|
@ -33,11 +33,11 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"prettier": "^2.8.4",
|
||||
"typescript": "^4.9.5",
|
||||
"ts-node": "^10.9.1",
|
||||
"esbuild": "^0.17.10"
|
||||
"typescript": "^4.9.5",
|
||||
"bun": "^0.6.0-canary"
|
||||
},
|
||||
"prettier": {
|
||||
"quoteProps": "preserve"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue