2022-12-29 12:53:11 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e; # Fail fast
|
2021-11-22 09:02:28 +00:00
|
|
|
# shellcheck shell=bash
|
2022-06-01 15:22:39 +00:00
|
|
|
|
|
|
|
# examples that we can't run because they require some additional infra, docker or ledger for example
|
|
|
|
ignored=(
|
2022-12-29 12:53:11 +00:00
|
|
|
"examples-contracts:deploy_moonbeam"
|
|
|
|
"examples-providers:ipc"
|
|
|
|
"examples-wallets:ledger"
|
|
|
|
"examples-wallets:trezor"
|
|
|
|
"examples-wallets:yubi"
|
|
|
|
"examples-transactions:remove_liquidity"
|
2022-06-01 15:22:39 +00:00
|
|
|
)
|
|
|
|
|
2022-12-29 12:53:11 +00:00
|
|
|
example_crates=$(cargo metadata --format-version 1 |
|
|
|
|
jq -c '.workspace_members' |
|
|
|
|
jq -r 'map(select(startswith("examples")) |
|
|
|
|
sub("\\s.*$";"")) | .[]')
|
|
|
|
|
|
|
|
for crate in $example_crates; do
|
|
|
|
# Remove "examples-" prefix from crate name (e.g. examples-contracts => contracts)
|
|
|
|
cratedir="${crate#examples-}"
|
|
|
|
srcdir="examples/$cratedir/examples"
|
|
|
|
# Retrieve all example files in crate:
|
|
|
|
# Transform the absolute path into the filename (e.g. some-path/deploy_anvil.rs => deploy_anvil)
|
|
|
|
example_files=$(find $srcdir -type f -name '*.rs' -exec basename {} \; | sed 's/\.[^.]*$//')
|
|
|
|
|
|
|
|
for file in $example_files; do
|
|
|
|
# Build the example
|
|
|
|
echo "Building example: $crate:$file"
|
|
|
|
cargo build -p $crate --example $file
|
|
|
|
|
|
|
|
# Run the example
|
|
|
|
if [[ "${ignored[*]}" =~ $(basename "$crate:$file") ]]; then
|
|
|
|
echo "skipping: $crate:$file"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
echo "running $crate:$file"
|
|
|
|
cargo run -p $crate --example $file
|
|
|
|
done
|
2021-08-30 11:00:30 +00:00
|
|
|
done
|