feat: implement wildcard resolution into the action (#93)
* feat: remove retry attempts * [autofix.ci] apply automated fixes * feat: get download url from github's api * [autofix.ci] apply automated fixes * fix: add token property to action definition & fix satisfies params * [autofix.ci] apply automated fixes * fix: getPlatform, getArchitecture + eversion * [autofix.ci] apply automated fixes * fix: duplicate v * [autofix.ci] apply automated fixes * fix: check if valid semver and add bun-v * [autofix.ci] apply automated fixes * refactor: wrap validation * [autofix.ci] apply automated fixes * ci(format): use bun bun install is rqeuired for patches * ci(format): use bun bun install is rqeuired for patches * [autofix.ci] apply automated fixes * feat: bring back support for sha downloads * [autofix.ci] apply automated fixes * fix: add bearer prefix for token * [autofix.ci] apply automated fixes * fix: proper error when artifact is not found * [autofix.ci] apply automated fixes * conflicts * autofix build * fix * fix * fix * fix * fix * autofix build * fix * [autofix.ci] apply automated fixes * fix * [autofix.ci] apply automated fixes * fix * [autofix.ci] apply automated fixes * fix * fix * [autofix.ci] apply automated fixes * fix * fix * [autofix.ci] apply automated fixes * fix: drop sha support for now * [autofix.ci] apply automated fixes * fix: filter tags * [autofix.ci] apply automated fixes * docs: token * docs: token * docs: token * refactor: cleanup * [autofix.ci] apply automated fixes * refactor: cleanup --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
46
src/utils.ts
46
src/utils.ts
@@ -3,19 +3,27 @@ import { info } from "node:console";
|
||||
import { existsSync, readFileSync, renameSync } from "node:fs";
|
||||
import { resolve, basename } from "node:path";
|
||||
|
||||
export function retry<T>(
|
||||
fn: () => Promise<T>,
|
||||
retries: number,
|
||||
timeout = 10000,
|
||||
): Promise<T> {
|
||||
return fn().catch((err) => {
|
||||
if (retries <= 0) {
|
||||
throw err;
|
||||
}
|
||||
return new Promise((resolve) => setTimeout(resolve, timeout)).then(() =>
|
||||
retry(fn, retries - 1, timeout),
|
||||
);
|
||||
export async function request(
|
||||
url: string,
|
||||
init?: RequestInit,
|
||||
): Promise<Response> {
|
||||
const headers = new Headers(init?.headers);
|
||||
if (!headers.has("User-Agent")) {
|
||||
headers.set("User-Agent", "@oven-sh/setup-bun");
|
||||
}
|
||||
|
||||
const res = await fetch(url, {
|
||||
...init,
|
||||
headers,
|
||||
});
|
||||
if (!res.ok) {
|
||||
const body = await res.text().catch(() => "");
|
||||
throw new Error(
|
||||
`Failed to fetch url ${url}. (status code: ${res.status}, status text: ${res.statusText})${body ? `\n${body}` : ""}`,
|
||||
);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
export function addExtension(path: string, ext: string): string {
|
||||
@@ -27,6 +35,20 @@ export function addExtension(path: string, ext: string): string {
|
||||
return path;
|
||||
}
|
||||
|
||||
export function getPlatform(): string {
|
||||
const platform = process.platform;
|
||||
if (platform === "win32") return "windows";
|
||||
|
||||
return platform;
|
||||
}
|
||||
|
||||
export function getArchitecture(): string {
|
||||
const arch = process.arch;
|
||||
if (arch === "arm64") return "aarch64";
|
||||
|
||||
return arch;
|
||||
}
|
||||
|
||||
const FILE_VERSION_READERS = {
|
||||
"package.json": (content: string) => {
|
||||
const pkg = JSON.parse(content);
|
||||
|
||||
Reference in New Issue
Block a user