From 10b7b9a787f6a4b01cec7941ddac1d50d0b0f13e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Kautler?= Date: Mon, 30 Dec 2024 18:59:37 +0100 Subject: [PATCH] Retry WSLv2 update up to 5 times due to unreliable download server (#66) --- .../github/action/setup_wsl/Distribution.kt | 14 -------------- .../kautler/github/action/setup_wsl/Retry.kt | 17 +++++++++++++++++ .../kautler/github/action/setup_wsl/SetupWsl.kt | 8 +++++--- 3 files changed, 22 insertions(+), 17 deletions(-) create mode 100644 src/jsMain/kotlin/net/kautler/github/action/setup_wsl/Retry.kt diff --git a/src/jsMain/kotlin/net/kautler/github/action/setup_wsl/Distribution.kt b/src/jsMain/kotlin/net/kautler/github/action/setup_wsl/Distribution.kt index 670b19ca..06fb3765 100644 --- a/src/jsMain/kotlin/net/kautler/github/action/setup_wsl/Distribution.kt +++ b/src/jsMain/kotlin/net/kautler/github/action/setup_wsl/Distribution.kt @@ -17,7 +17,6 @@ package net.kautler.github.action.setup_wsl import actions.core.debug -import actions.core.info import actions.core.isDebug import actions.exec.ExecOptions import actions.exec.exec @@ -487,16 +486,3 @@ object Alpine : ApkBasedDistribution( productId = "9p804crf0395", installerFile = "Alpine.exe" ) - -private suspend inline fun retry(amount: Int, crossinline block: suspend () -> T): T { - (1..amount).map { i -> - runCatching { - return block() - }.onFailure { - if (i != 5) { - debug(it.stackTraceToString()) - info("Failure happened, retrying (${it.message ?: it})") - } - } - }.last().getOrThrow() -} diff --git a/src/jsMain/kotlin/net/kautler/github/action/setup_wsl/Retry.kt b/src/jsMain/kotlin/net/kautler/github/action/setup_wsl/Retry.kt new file mode 100644 index 00000000..bff236b7 --- /dev/null +++ b/src/jsMain/kotlin/net/kautler/github/action/setup_wsl/Retry.kt @@ -0,0 +1,17 @@ +package net.kautler.github.action.setup_wsl + +import actions.core.debug +import actions.core.info + +internal suspend inline fun retry(amount: Int, crossinline block: suspend () -> T): T { + (1..amount).map { i -> + runCatching { + return block() + }.onFailure { + if (i != 5) { + debug(it.stackTraceToString()) + info("Failure happened, retrying (${it.message ?: it})") + } + } + }.last().getOrThrow() +} diff --git a/src/jsMain/kotlin/net/kautler/github/action/setup_wsl/SetupWsl.kt b/src/jsMain/kotlin/net/kautler/github/action/setup_wsl/SetupWsl.kt index e2b22f24..b89a785d 100644 --- a/src/jsMain/kotlin/net/kautler/github/action/setup_wsl/SetupWsl.kt +++ b/src/jsMain/kotlin/net/kautler/github/action/setup_wsl/SetupWsl.kt @@ -375,9 +375,11 @@ suspend fun installDistribution() { wslArguments = arrayOf("--set-default-version", "${wslVersion()}") ) if (wslVersion() != 1u) { - executeWslCommand( - wslArguments = arrayOf("--update") - ) + retry(5) { + executeWslCommand( + wslArguments = arrayOf("--update") + ) + } (2..30) .asFlow()