Skip to content

Commit 774c0c3

Browse files
committed
CI/scripts: only use jq to parse JSON output, not grep
1 parent a953b77 commit 774c0c3

File tree

3 files changed

+21
-26
lines changed

3 files changed

+21
-26
lines changed

.github/scripts/test-graphql-command-scripts.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,22 @@ for script_file in $script_files; do
5050

5151
# Execute the script and capture output
5252
if output=$(bash "$script_file" 2>&1); then
53-
echo "✅ Script executed successfully with output $output"
53+
echo "✅ Script executed successfully"
5454

5555
# Try to parse output as JSON using jq
56-
if json_response=$(echo "$output" | jq . 2>/dev/null); then
56+
if echo "$output" | jq . > /dev/null 2>&1; then
5757
# Valid JSON response - check for GraphQL errors
58-
if echo "$json_response" | jq -e '.errors' > /dev/null 2>&1; then
58+
if echo "$output" | jq -e '.errors' > /dev/null 2>&1; then
5959
echo "❌ Script returned GraphQL errors:"
60-
echo "$json_response" | jq '.errors'
60+
echo "$output" | jq '.errors'
6161
failed=$((failed + 1))
62-
elif echo "$json_response" | jq -e '.data' > /dev/null 2>&1; then
63-
echo "✅ Script response contains valid data: $(echo "$json_response" | head -c 100)..."
62+
elif echo "$output" | jq -e '.data' > /dev/null 2>&1; then
63+
echo "✅ Script response contains valid data: $(echo "$output" | head -c 100)..."
6464
else
65-
echo "⚠️ Unexpected JSON response format: $(echo "$json_response" | head -c 100)..."
65+
echo "⚠️ Unexpected JSON response format: $(echo "$output" | head -c 100)..."
6666
fi
6767
else
68-
echo "❌ Script did not return valid JSON"
68+
echo "❌ Script did not return valid JSON: $(echo "$output" | head -c 100)..."
6969
failed=$((failed + 1))
7070
fi
7171
else

.github/scripts/test-plain-node-capabilities.sh

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ for node_url in $plain_nodes; do
2222

2323
# Test network ID query using website script
2424
network_success=false
25-
if network_response=$(bash website/docs/developers/scripts/graphql-api/queries/curl/network-id.sh "$graphql_url" 2>/dev/null); then
26-
network_json=$(echo "$network_response" | grep "^{")
27-
if echo "$network_json" | jq -e '.data.networkID' > /dev/null 2>&1; then
28-
network_id=$(echo "$network_json" | jq -r '.data.networkID')
25+
if network_response=$(bash website/docs/developers/scripts/graphql-api/queries/curl/network-id.sh "$graphql_url" 2>&1); then
26+
if echo "$network_response" | jq -e '.data.networkID' > /dev/null 2>&1; then
27+
network_id=$(echo "$network_response" | jq -r '.data.networkID')
2928
echo "✅ Network ID query successful: $network_id"
3029
network_success=true
3130
else
@@ -37,10 +36,9 @@ for node_url in $plain_nodes; do
3736

3837
# Test best chain query using website script
3938
chain_success=false
40-
if chain_response=$(bash website/docs/developers/scripts/graphql-api/queries/curl/best-chain.sh "$graphql_url" 2>/dev/null); then
41-
chain_json=$(echo "$chain_response" | grep "^{")
42-
if echo "$chain_json" | jq -e '.data.bestChain[0].stateHash' > /dev/null 2>&1; then
43-
state_hash=$(echo "$chain_json" | jq -r '.data.bestChain[0].stateHash')
39+
if chain_response=$(bash website/docs/developers/scripts/graphql-api/queries/curl/best-chain.sh "$graphql_url" 2>&1); then
40+
if echo "$chain_response" | jq -e '.data.bestChain[0].stateHash' > /dev/null 2>&1; then
41+
state_hash=$(echo "$chain_response" | jq -r '.data.bestChain[0].stateHash')
4442
echo "✅ Best chain query successful: ${state_hash:0:16}..."
4543
chain_success=true
4644
else

.github/scripts/test-plain-node-connectivity.sh

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,18 @@ for node_url in $plain_nodes; do
3737
graphql_url="${node_url}graphql"
3838

3939
# Test daemon status query using the website script
40-
if response=$(bash website/docs/developers/scripts/graphql-api/queries/curl/daemon-status.sh "$graphql_url" 2>/dev/null); then
41-
# Extract JSON response (skip curl progress output)
42-
json_response=$(echo "$response" | grep "^{")
43-
40+
if response=$(bash website/docs/developers/scripts/graphql-api/queries/curl/daemon-status.sh "$graphql_url" 2>&1); then
4441
# Check if it's valid JSON
45-
if echo "$json_response" | jq . > /dev/null 2>&1; then
42+
if echo "$response" | jq . > /dev/null 2>&1; then
4643
# Check for GraphQL errors
47-
if echo "$json_response" | jq -e '.errors' > /dev/null 2>&1; then
44+
if echo "$response" | jq -e '.errors' > /dev/null 2>&1; then
4845
echo "⚠️ $graphql_url returned GraphQL error:"
49-
echo "$json_response" | jq '.errors'
46+
echo "$response" | jq '.errors'
5047
# Check for valid data
51-
elif echo "$json_response" | jq -e '.data.daemonStatus' > /dev/null 2>&1; then
48+
elif echo "$response" | jq -e '.data.daemonStatus' > /dev/null 2>&1; then
5249
echo "$graphql_url GraphQL query successful"
53-
sync_status=$(echo "$json_response" | jq -r '.data.daemonStatus.syncStatus // "unknown"')
54-
chain_id=$(echo "$json_response" | jq -r '.data.daemonStatus.chainId // "unknown"')
50+
sync_status=$(echo "$response" | jq -r '.data.daemonStatus.syncStatus // "unknown"')
51+
chain_id=$(echo "$response" | jq -r '.data.daemonStatus.chainId // "unknown"')
5552
echo " Sync Status: $sync_status, Chain ID: ${chain_id:0:16}..."
5653
else
5754
echo "⚠️ $graphql_url unexpected response format"

0 commit comments

Comments
 (0)