mirror of
https://github.com/oven-sh/setup-bun.git
synced 2025-07-02 08:13:20 +08:00
feat: remove retry attempts
This commit is contained in:
parent
4bc047ad25
commit
54abc74d5b
@ -13,7 +13,7 @@ import { downloadTool, extractZip } from "@actions/tool-cache";
|
|||||||
import { getExecOutput } from "@actions/exec";
|
import { getExecOutput } from "@actions/exec";
|
||||||
import { writeBunfig } from "./bunfig";
|
import { writeBunfig } from "./bunfig";
|
||||||
import { saveState } from "@actions/core";
|
import { saveState } from "@actions/core";
|
||||||
import { addExtension, retry } from "./utils";
|
import { addExtension } from "./utils";
|
||||||
|
|
||||||
export type Input = {
|
export type Input = {
|
||||||
customUrl?: string;
|
customUrl?: string;
|
||||||
@ -89,8 +89,7 @@ export default async (options: Input): Promise<Output> => {
|
|||||||
|
|
||||||
if (!cacheHit) {
|
if (!cacheHit) {
|
||||||
info(`Downloading a new version of Bun: ${url}`);
|
info(`Downloading a new version of Bun: ${url}`);
|
||||||
// TODO: remove this, temporary fix for https://github.com/oven-sh/setup-bun/issues/73
|
revision = await downloadBun(url, bunPath);
|
||||||
revision = await retry(async () => await downloadBun(url, bunPath), 3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!revision) {
|
if (!revision) {
|
||||||
|
15
src/utils.ts
15
src/utils.ts
@ -3,21 +3,6 @@ import { info } from "node:console";
|
|||||||
import { existsSync, readFileSync, renameSync } from "node:fs";
|
import { existsSync, readFileSync, renameSync } from "node:fs";
|
||||||
import { join, basename } from "node:path";
|
import { join, 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 function addExtension(path: string, ext: string): string {
|
export function addExtension(path: string, ext: string): string {
|
||||||
if (!path.endsWith(ext)) {
|
if (!path.endsWith(ext)) {
|
||||||
renameSync(path, path + ext);
|
renameSync(path, path + ext);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user