-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathmain.sh
59 lines (51 loc) · 1.49 KB
/
main.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
set -euo pipefail
# Load API keys from the repo root.
repoRoot=$(git rev-parse --show-toplevel)
if [ -f "$repoRoot/.env" ]; then
# shellcheck disable=SC1091
source "$repoRoot/.env"
fi
if [ -n "${INFURA_API_KEY:-}" ]; then
echo "INFURA_API_KEY exists"
else
echo "INFURA_API_KEY does not exist"
fi
# Log "alchemy exists"
if [ -n "${ALCHEMY_API_KEY:-}" ]; then
echo "ALCHEMY_API_KEY exists"
else
echo "ALCHEMY_API_KEY does not exist"
fi
# Function to handle final preparation steps.
final_preparation() {
local exitStatus=$?
echo ""
bun script/postprocess.ts # Slice data by feature.
bun check # Runs prepare-chain-data, lints, and formats.
echo ""
if [ $exitStatus -eq 0 ]; then
echo "✅ Chain data fetched and processed successfully!"
else
echo "❌ An error occurred during chain data fetching or processing. See above for details."
fi
}
# Set up a trap to run final preparation steps on script exit.
trap final_preparation EXIT
if [ $# -eq 0 ]; then
# No input provided, read from `input.json`.
chainIds=$(jq -r '.[].chainId' script/input.json)
numChains=$(echo "$chainIds" | wc -l | xargs)
echo "Found $numChains chains"
index=1
for chainId in $chainIds; do
echo ""
echo "Running for chain ID $chainId (chain $index of $numChains)"
bun script/index.ts "$chainId"
index=$((index + 1))
done
else
# Input provided, run the script with the provided input.
echo "Running for chain ID $1"
bun script/index.ts "$1"
fi