Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retry when fetching the shell script #10

Merged
merged 10 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 12 additions & 18 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,28 @@ jobs:
shell: pwsh
run: |
Get-Command wasmer
Get-Command wapm
Get-Command wax

# Verify Wasmer runs
- name: Verify Wasmer runs
run: |
wapm config set registry.url "https://registry.wapm.io"
mkdir test-dir
cd test-dir
wapm install robert/[email protected]
wasmer run -- './wapm_packages/robert/[email protected]/echo.wasm' "${{ env.ECHO_STRING }}" > output.txt
wasmer run https://wasmer.io/robert/[email protected] -- "${{ env.ECHO_STRING }}" > output.txt
grep "${{ env.ECHO_STRING }}" output.txt

test-versions:
name: Test version on ${{ matrix.os }}
name: Test v${{ matrix.version }} on ${{ matrix.os }}
strategy:
matrix:
os:
- macos-latest
- ubuntu-latest
- windows-latest
version:
- 3.2.0
- 3.3.0
- 4.0.0
- 4.1.0
- 4.2.0
- 4.2.5
runs-on: ${{ matrix.os }}
steps:
# Checkout source code
Expand All @@ -65,29 +66,22 @@ jobs:
- name: Setup Wasmer
uses: ./
with:
version: "v3.0.0-rc.2"
version: v${{ matrix.version }}

# Verify Wasmer is installed
- name: Verify Wasmer is installed
shell: pwsh
run: |
Get-Command wasmer
Get-Command wapm
Get-Command wax

# Verify Wasmer version is correct
- name: Verify Wasmer version is correct
uses: MeilCli/[email protected]
with:
command: wasmer --version
expect_contain: "wasmer 3.0.0-rc.2"
expect_contain: ${{ matrix.version }}

# Verify Wasmer runs
- name: Verify Wasmer runs
run: |
wapm config set registry.url "https://registry.wapm.io"
mkdir test-dir
cd test-dir
wapm install robert/[email protected]
wasmer run -- './wapm_packages/robert/[email protected]/echo.wasm' "${{ env.ECHO_STRING }}" > output.txt
wasmer run robert/[email protected] -- "${{ env.ECHO_STRING }}" > output.txt
grep "${{ env.ECHO_STRING }}" output.txt
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Setup Wasmer Action
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/wasmerio/setup-wasmer/Tests?label=Tests&style=flat-square)](https://github.com/wasmerio/setup-wasmer/actions/workflows/tests.yml)

[GitHub action](https://github.com/features/actions) for setting up [Wasmer](https://wasmer.io). Works well with [wasmerio/wapm-publish](https://github.com/wasmerio/wapm-publish).
[GitHub action](https://github.com/features/actions) for setting up [Wasmer](https://wasmer.io).

## Features
* Always uses the latest stable Wasmer build
Expand Down
4 changes: 3 additions & 1 deletion dist/index.js

Large diffs are not rendered by default.

38 changes: 30 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,36 @@ const main = async () =>
const percent = Math.round(data.percent * 100);

//Log
info(`Downloaded ${transferred}K out of ${total}K (${percent}%)`);
if (!Number.isNaN(transferred) && !Number.isNaN(total) && !Number.isNaN(percent)) {
info(`Downloaded ${transferred}K out of ${total}K (${percent}%)`);
}
};
await pipeline(
got.stream(isWindows ? 'https://win.wasmer.io' : 'https://get.wasmer.io').on('downloadProgress', progressHandler),
createWriteStream(tmp, {
mode: 0o655
})
);
const url = isWindows ? 'https://win.wasmer.io' : 'https://get.wasmer.io';
let retryAttempts = 0;
const maxRetryAttempts = 10;

while (retryAttempts < maxRetryAttempts) {
try {
await pipeline(
got.stream(url).on('downloadProgress', progressHandler),
createWriteStream(tmp, {
mode: 0o655
})
);
console.log('Downloaded installer.');
break;
}
catch (error) {
retryAttempts++;
// exponential backoff with jitter
const backoff = Math.pow(2, retryAttempts) + Math.random();
console.log(`Failed to download installer. Retrying in ${backoff} seconds.`);
await new Promise(resolve => setTimeout(resolve, backoff * 1000));
if (retryAttempts >= maxRetryAttempts) {
throw new Error(`Failed to download installer after ${retryAttempts} attempts.\nLast error: ${error}`);
}
}
}
endGroup();

info('Downloaded installer.');
Expand Down Expand Up @@ -92,4 +114,4 @@ const main = async () =>
main().catch(error =>
{
throw error;
});
});
Loading