mirror of
https://github.com/oven-sh/setup-bun.git
synced 2025-07-18 12:38:24 +02:00
fix: retry installing version three times
This commit is contained in:
parent
6a11bac1d8
commit
ef6fb13bf3
4 changed files with 398 additions and 96 deletions
198
dist/cache-save/index.js
generated
vendored
198
dist/cache-save/index.js
generated
vendored
File diff suppressed because one or more lines are too long
256
dist/setup/index.js
generated
vendored
256
dist/setup/index.js
generated
vendored
File diff suppressed because one or more lines are too long
|
@ -13,6 +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 { retry } from "./utils";
|
||||||
|
|
||||||
export type Input = {
|
export type Input = {
|
||||||
customUrl?: string;
|
customUrl?: string;
|
||||||
|
@ -86,17 +87,8 @@ 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}`);
|
||||||
const zipPath = await downloadTool(url);
|
// TODO: remove this, temporary fix for https://github.com/oven-sh/setup-bun/issues/73
|
||||||
const extractedZipPath = await extractZip(zipPath);
|
revision = await retry(async () => await downloadBun(url, bunPath), 3);
|
||||||
const extractedBunPath = await extractBun(extractedZipPath);
|
|
||||||
try {
|
|
||||||
renameSync(extractedBunPath, bunPath);
|
|
||||||
} catch {
|
|
||||||
// If mv does not work, try to copy the file instead.
|
|
||||||
// For example: EXDEV: cross-device link not permitted
|
|
||||||
copyFileSync(extractedBunPath, bunPath);
|
|
||||||
}
|
|
||||||
revision = await getRevision(bunPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!revision) {
|
if (!revision) {
|
||||||
|
@ -123,6 +115,24 @@ export default async (options: Input): Promise<Output> => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function downloadBun(
|
||||||
|
url: string,
|
||||||
|
bunPath: string
|
||||||
|
): Promise<string | undefined> {
|
||||||
|
const zipPath = await downloadTool(url);
|
||||||
|
const extractedZipPath = await extractZip(zipPath);
|
||||||
|
const extractedBunPath = await extractBun(extractedZipPath);
|
||||||
|
try {
|
||||||
|
renameSync(extractedBunPath, bunPath);
|
||||||
|
} catch {
|
||||||
|
// If mv does not work, try to copy the file instead.
|
||||||
|
// For example: EXDEV: cross-device link not permitted
|
||||||
|
copyFileSync(extractedBunPath, bunPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await getRevision(bunPath);
|
||||||
|
}
|
||||||
|
|
||||||
function isCacheEnabled(options: Input): boolean {
|
function isCacheEnabled(options: Input): boolean {
|
||||||
const { customUrl, version, noCache } = options;
|
const { customUrl, version, noCache } = options;
|
||||||
if (noCache) {
|
if (noCache) {
|
||||||
|
|
8
src/utils.ts
Normal file
8
src/utils.ts
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
export function retry<T>(fn: () => Promise<T>, retries: number): Promise<T> {
|
||||||
|
return fn().catch((err) => {
|
||||||
|
if (retries <= 0) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
return retry(fn, retries - 1);
|
||||||
|
});
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue