fix: retry installing three times, add windows for testing (#72)

* ci: test windows

* ci: specify shell

* ci: we don't have >1.1.0

* fix: retry installing version three times

* [autofix.ci] apply automated fixes

* build: bump version to 1.2.1

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Jozef Steinhübl 2024-04-02 11:24:51 +02:00 committed by GitHub
parent 9e6479509b
commit 932c3b236c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 93 additions and 59 deletions

View file

@ -13,6 +13,7 @@ import { downloadTool, extractZip } from "@actions/tool-cache";
import { getExecOutput } from "@actions/exec";
import { writeBunfig } from "./bunfig";
import { saveState } from "@actions/core";
import { retry } from "./utils";
export type Input = {
customUrl?: string;
@ -86,17 +87,8 @@ export default async (options: Input): Promise<Output> => {
if (!cacheHit) {
info(`Downloading a new version of Bun: ${url}`);
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);
}
revision = await getRevision(bunPath);
// TODO: remove this, temporary fix for https://github.com/oven-sh/setup-bun/issues/73
revision = await retry(async () => await downloadBun(url, bunPath), 3);
}
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 {
const { customUrl, version, noCache } = options;
if (noCache) {

8
src/utils.ts Normal file
View 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);
});
}