From 3aa0bb0ccc940e0992cf830a6d262a8bb2a9fcb9 Mon Sep 17 00:00:00 2001 From: Adrien DELSALLE Date: Wed, 20 Oct 2021 09:59:19 +0200 Subject: [PATCH] add retries when downloading umamba --- dist/index.js | 24 +++++++++++++++++++----- index.js | 24 +++++++++++++++++++----- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/dist/index.js b/dist/index.js index ef65be11..b21a2c31 100644 --- a/dist/index.js +++ b/dist/index.js @@ -89,9 +89,9 @@ async function run () { if (process.platform === 'darwin') { // macos try { - await executeNoCatch(`curl -Ls ${baseUrl}/osx-64/${micromambaVersion} | tar -xvjO bin/micromamba > ${micromambaLoc}`) + await executeNoCatch(`curl -Ls --retry 5 --retry-delay 1 ${baseUrl}/osx-64/${micromambaVersion} | tar -xvjO bin/micromamba > ${micromambaLoc}`) } catch (error) { - await execute(`curl -Ls ${baseUrl}/osx-64/${micromambaVersion} | tar -xvzO bin/micromamba > ${micromambaLoc}`) + await execute(`curl -Ls --retry 5 --retry-delay 1 ${baseUrl}/osx-64/${micromambaVersion} | tar -xvzO bin/micromamba > ${micromambaLoc}`) } await execute(`chmod u+x ${micromambaLoc}`) await execute(`${micromambaLoc} shell init -s bash -p ~/micromamba -y`) @@ -101,9 +101,9 @@ async function run () { } else if (process.platform === 'linux') { // linux try { - await executeNoCatch(`wget -qO- ${baseUrl}/linux-64/${micromambaVersion} | tar -xvjO bin/micromamba > ${micromambaLoc}`) + await executeNoCatch(`wget -qO- --retry-connrefused --waitretry=1 -t 5 ${baseUrl}/linux-64/${micromambaVersion} | tar -xvjO bin/micromamba > ${micromambaLoc}`) } catch (error) { - await execute(`wget -qO- ${baseUrl}/linux-64/${micromambaVersion} | tar -xvzO bin/micromamba > ${micromambaLoc}`) + await execute(`wget -qO- --retry-connrefused --waitretry=1 -t 5 ${baseUrl}/linux-64/${micromambaVersion} | tar -xvzO bin/micromamba > ${micromambaLoc}`) } await execute(`chmod u+x ${micromambaLoc}`) @@ -143,11 +143,25 @@ else Add-Content -path $profile -value "CONTENTPLACEHOLDER" Write-Host "Profile already exists and new content added" }` + const powershellDownloader = `$count = 0 +do{ + try + { + Invoke-Webrequest -URI ${baseUrl}/win-64/${micromambaVersion} -OutFile ~\\micromamba.tar.bz2 + $success = $true + } + catch + { + Start-sleep -Seconds 1 + } + $count++ +}until($count -eq 5 -or $success) +if(-not($success)){exit}` const autoactivate = powershellAutoActivateEnv.replace(/CONTENTPLACEHOLDER/g, `micromamba activate ${envName}`) core.startGroup(`Installing environment ${envName} from ${envFilePath} ...`) touch(profile) - await execPwsh(`Invoke-Webrequest -URI ${baseUrl}/win-64/${micromambaVersion} -OutFile ~\\micromamba.tar.bz2`) + await execPwsh(powershellDownloader) await execPwsh( '$env:Path = (get-item (get-command git).Path).Directory.parent.FullName + "\\usr\\bin;" + $env:Path;' + 'tar.exe -xvjf ~/micromamba.tar.bz2 --strip-components 2 -C ~ Library/bin/micromamba.exe' diff --git a/index.js b/index.js index 9d7bc532..eab29b78 100644 --- a/index.js +++ b/index.js @@ -82,9 +82,9 @@ async function run () { if (process.platform === 'darwin') { // macos try { - await executeNoCatch(`curl -Ls ${baseUrl}/osx-64/${micromambaVersion} | tar -xvjO bin/micromamba > ${micromambaLoc}`) + await executeNoCatch(`curl -Ls --retry 5 --retry-delay 1 ${baseUrl}/osx-64/${micromambaVersion} | tar -xvjO bin/micromamba > ${micromambaLoc}`) } catch (error) { - await execute(`curl -Ls ${baseUrl}/osx-64/${micromambaVersion} | tar -xvzO bin/micromamba > ${micromambaLoc}`) + await execute(`curl -Ls --retry 5 --retry-delay 1 ${baseUrl}/osx-64/${micromambaVersion} | tar -xvzO bin/micromamba > ${micromambaLoc}`) } await execute(`chmod u+x ${micromambaLoc}`) await execute(`${micromambaLoc} shell init -s bash -p ~/micromamba -y`) @@ -94,9 +94,9 @@ async function run () { } else if (process.platform === 'linux') { // linux try { - await executeNoCatch(`wget -qO- ${baseUrl}/linux-64/${micromambaVersion} | tar -xvjO bin/micromamba > ${micromambaLoc}`) + await executeNoCatch(`wget -qO- --retry-connrefused --waitretry=1 -t 5 ${baseUrl}/linux-64/${micromambaVersion} | tar -xvjO bin/micromamba > ${micromambaLoc}`) } catch (error) { - await execute(`wget -qO- ${baseUrl}/linux-64/${micromambaVersion} | tar -xvzO bin/micromamba > ${micromambaLoc}`) + await execute(`wget -qO- --retry-connrefused --waitretry=1 -t 5 ${baseUrl}/linux-64/${micromambaVersion} | tar -xvzO bin/micromamba > ${micromambaLoc}`) } await execute(`chmod u+x ${micromambaLoc}`) @@ -136,11 +136,25 @@ else Add-Content -path $profile -value "CONTENTPLACEHOLDER" Write-Host "Profile already exists and new content added" }` + const powershellDownloader = `$count = 0 +do{ + try + { + Invoke-Webrequest -URI ${baseUrl}/win-64/${micromambaVersion} -OutFile ~\\micromamba.tar.bz2 + $success = $true + } + catch + { + Start-sleep -Seconds 1 + } + $count++ +}until($count -eq 5 -or $success) +if(-not($success)){exit}` const autoactivate = powershellAutoActivateEnv.replace(/CONTENTPLACEHOLDER/g, `micromamba activate ${envName}`) core.startGroup(`Installing environment ${envName} from ${envFilePath} ...`) touch(profile) - await execPwsh(`Invoke-Webrequest -URI ${baseUrl}/win-64/${micromambaVersion} -OutFile ~\\micromamba.tar.bz2`) + await execPwsh(powershellDownloader) await execPwsh( '$env:Path = (get-item (get-command git).Path).Directory.parent.FullName + "\\usr\\bin;" + $env:Path;' + 'tar.exe -xvjf ~/micromamba.tar.bz2 --strip-components 2 -C ~ Library/bin/micromamba.exe'