Skip to content

Commit 7123732

Browse files
authored
Merge pull request #85 from traderjoe-xyz/add-workflows
add workflows
2 parents f6ce214 + 39a5da5 commit 7123732

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

.github/workflows/test.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Tokenlist Validation CI
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
pull_request:
8+
branches:
9+
- "main"
10+
11+
jobs:
12+
validate:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: Run validations
17+
run: ./.github/workflows/validate.sh

.github/workflows/validate.sh

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# -----------------------------
5+
# Validate JSON structure
6+
# -----------------------------
7+
echo "Validating JSON structure for tokenlists"
8+
jq empty ./popular_tokenlist.json
9+
jq empty ./verified_tokenlist.json
10+
11+
12+
# -----------------------------
13+
# Check required keys in JSON array
14+
# -----------------------------
15+
REQUIRED_KEYS=("chainId" "address" "decimals" "name" "symbol" "tags")
16+
echo "Checking required keys for each token..."
17+
18+
for key in "${REQUIRED_KEYS[@]}"; do
19+
if [ "$(jq ".[] | [has(\"$key\")] | contains([false])" popular_tokenlist.json)" == "true" ]; then
20+
echo "JSON validation failed: Missing key $key"
21+
exit 1
22+
fi
23+
done
24+
echo "All required keys are present in each token."
25+
26+
# -----------------------------
27+
# Check allowed 'chainId' values
28+
# -----------------------------
29+
ALLOWED_CHAIN_IDS=(1 42161 421613 56 97 8453 10143 42161 43113 43114 80084 80094 1399811149)
30+
# Convert bash array to jq array format
31+
JQ_ALLOWED_CHAIN_IDS=$(printf "[%s]" "$(IFS=, ; echo "${ALLOWED_CHAIN_IDS[*]}")")
32+
33+
echo "Validating 'chainId' values..."
34+
INVALID_CHAIN_IDS=$(jq "[.[].chainId] | map(select(. as \$id | ($JQ_ALLOWED_CHAIN_IDS | index(\$id)) == null))" popular_tokenlist.json)
35+
36+
if [ "$INVALID_CHAIN_IDS" != "[]" ]; then
37+
echo "Invalid 'chainId' value(s) found: $INVALID_CHAIN_IDS. Must be one of ${ALLOWED_CHAIN_IDS[*]}"
38+
exit 1
39+
else
40+
echo "All 'chainId' values are valid in popular_tokenlist.json."
41+
fi
42+
43+
INVALID_CHAIN_IDS=$(jq "[.[].chainId] | map(select(. as \$id | ($JQ_ALLOWED_CHAIN_IDS | index(\$id)) == null))" verified_tokenlist.json)
44+
45+
if [ "$INVALID_CHAIN_IDS" != "[]" ]; then
46+
echo "Invalid 'chainId' value(s) found: $INVALID_CHAIN_IDS. Must be one of ${ALLOWED_CHAIN_IDS[*]}"
47+
exit 1
48+
else
49+
echo "All 'chainId' values are valid in verified_tokenlist.json."
50+
fi
51+
52+
53+
54+
# -----------------------------
55+
# Check logos folder and file names
56+
# -----------------------------
57+
58+
ETH_ADDRESS_PATTERN="^0x[a-f0-9]{40}\.png$"
59+
60+
LOGOS_DIR="logos"
61+
62+
# Check if the logos directory exists
63+
if [ ! -d "$LOGOS_DIR" ]; then
64+
echo "Error: Logos directory '$LOGOS_DIR' does not exist."
65+
exit 1
66+
fi
67+
68+
# Iterate through each subdirectory in the logos folder
69+
for dir in "$LOGOS_DIR"/*; do
70+
if [ -d "$dir" ]; then
71+
# ignore solana folder
72+
if [[ "$dir" == "logos/1399811149" ]]; then
73+
continue
74+
fi
75+
# Iterate through files in the subdirectory
76+
for file in "$dir"/*; do
77+
if [ -f "$file" ]; then
78+
filename=$(basename "$file")
79+
if [[ ! "$filename" =~ $ETH_ADDRESS_PATTERN ]]; then
80+
echo "Invalid file found: $file"
81+
exit 1
82+
fi
83+
else
84+
echo "Invalid entry found (not a file): $file"
85+
exit 1
86+
fi
87+
done
88+
fi
89+
done
90+
91+
echo "Every logo is named correctly."
92+
93+
echo "All validations passed successfully."

0 commit comments

Comments
 (0)