Skip to content

Commit

Permalink
Merge pull request #27 from adriendelsalle/robustify-dl
Browse files Browse the repository at this point in the history
Add retries when downloading `micromamba`
  • Loading branch information
wolfv authored Oct 20, 2021
2 parents 66899ad + 3aa0bb0 commit 0868e71
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
24 changes: 19 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,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`)
Expand All @@ -106,9 +106,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}`)

Expand Down Expand Up @@ -148,11 +148,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'
Expand Down
24 changes: 19 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,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`)
Expand All @@ -99,9 +99,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}`)

Expand Down Expand Up @@ -141,11 +141,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'
Expand Down

0 comments on commit 0868e71

Please sign in to comment.