Migrate and improve extractBun
This commit is contained in:
parent
5b522d11b3
commit
5018e2b092
@ -1,9 +1,12 @@
|
|||||||
import { renameSync, rmSync } from "node:fs";
|
import { renameSync, rmSync } from "node:fs";
|
||||||
import { basename, dirname, join, resolve } from "node:path";
|
import { basename, dirname, join, resolve } from "node:path";
|
||||||
|
|
||||||
import { debug, error, info, warning } from "@actions/core";
|
import { debug, error, info, warning } from "@actions/core";
|
||||||
import type { AnnotationProperties } from "@actions/core";
|
import type { AnnotationProperties } from "@actions/core";
|
||||||
import { downloadTool, extractZip } from "@actions/tool-cache";
|
import { downloadTool, extractZip } from "@actions/tool-cache";
|
||||||
import { addExtension, extractBun, getCacheKey } from "./utils";
|
|
||||||
|
import { extractBun } from "./extract-bun";
|
||||||
|
import { addExtension, getCacheKey } from "./utils";
|
||||||
import { verifyAsset } from "./verify";
|
import { verifyAsset } from "./verify";
|
||||||
|
|
||||||
// This type covers info, debug, notice, warning, and error
|
// This type covers info, debug, notice, warning, and error
|
||||||
|
|||||||
32
src/utils.ts
32
src/utils.ts
@ -1,16 +1,10 @@
|
|||||||
import { info } from "node:console";
|
import { info } from "node:console";
|
||||||
import { createHash } from "node:crypto";
|
import { createHash } from "node:crypto";
|
||||||
import {
|
import { copyFileSync, existsSync, readFileSync, renameSync } from "node:fs";
|
||||||
copyFileSync,
|
import { resolve, basename } from "node:path";
|
||||||
existsSync,
|
|
||||||
readdirSync,
|
|
||||||
readFileSync,
|
|
||||||
renameSync,
|
|
||||||
} from "node:fs";
|
|
||||||
import { join, resolve, basename } from "node:path";
|
|
||||||
import { debug, warning } from "@actions/core";
|
import { debug, warning } from "@actions/core";
|
||||||
import { getExecOutput } from "@actions/exec";
|
import { getExecOutput } from "@actions/exec";
|
||||||
import { extractZip } from "@actions/tool-cache";
|
|
||||||
import { compareVersions, validate } from "compare-versions";
|
import { compareVersions, validate } from "compare-versions";
|
||||||
|
|
||||||
import { getStoredResponse, setStoredResponse } from "./response-storage";
|
import { getStoredResponse, setStoredResponse } from "./response-storage";
|
||||||
@ -250,26 +244,6 @@ export function isVersionMatch(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function extractBun(path: string): Promise<string> {
|
|
||||||
for (const entry of readdirSync(path, { withFileTypes: true })) {
|
|
||||||
const { name } = entry;
|
|
||||||
const entryPath = join(path, name);
|
|
||||||
if (entry.isFile()) {
|
|
||||||
if ("bun" === name || "bun.exe" === name) {
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getRevision(exe: string): Promise<string | undefined> {
|
export async function getRevision(exe: string): Promise<string | undefined> {
|
||||||
const revision = await getExecOutput(exe, ["--revision"], {
|
const revision = await getExecOutput(exe, ["--revision"], {
|
||||||
ignoreReturnCode: true,
|
ignoreReturnCode: true,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user