Skip to content

Commit 12e1cb3

Browse files
authored
Merge pull request #1430 from o1-labs/dw/section-with-o1labs-infra
Website: add o1Labs infrastructure + improve GraphQL doc
2 parents 146fb99 + 386098b commit 12e1cb3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2049
-327
lines changed
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
name: Test Documentation Scripts - GraphQL API
2+
3+
# Test GraphQL API scripts and examples
4+
on:
5+
schedule:
6+
# Run daily at 7 AM UTC to catch API issues early
7+
- cron: '0 7 * * *'
8+
workflow_dispatch:
9+
# Allow manual triggering for testing
10+
pull_request:
11+
# Always run on pull requests
12+
push:
13+
branches: [ main, develop ]
14+
15+
jobs:
16+
test-graphql-scripts:
17+
name: Test GraphQL API Scripts
18+
strategy:
19+
matrix:
20+
os: [ubuntu-latest, macos-latest]
21+
runs-on: ${{ matrix.os }}
22+
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v5
26+
27+
- name: Install jq for JSON processing
28+
run: |
29+
if [[ "${{ runner.os }}" == "Linux" ]]; then
30+
sudo apt-get update && sudo apt-get install -y jq
31+
elif [[ "${{ runner.os }}" == "macOS" ]]; then
32+
brew install jq
33+
fi
34+
35+
- name: Test script and query file consistency
36+
run: |
37+
echo "🔍 Testing consistency between bash scripts and GraphQL query files..."
38+
39+
script_dir="website/docs/developers/scripts/graphql-api/queries/curl"
40+
query_dir="website/docs/developers/scripts/graphql-api/queries/query"
41+
42+
inconsistent=0
43+
44+
# Check that each script that references a query file has a corresponding .graphql file
45+
for script_file in "$script_dir"/*.sh; do
46+
if [ ! -f "$script_file" ]; then
47+
continue
48+
fi
49+
50+
script_name=$(basename "$script_file" .sh)
51+
52+
# Look for query file references in the script
53+
if grep -q "query/" "$script_file"; then
54+
expected_query_file="$query_dir/$script_name.graphql"
55+
56+
if [ -f "$expected_query_file" ]; then
57+
echo "✅ $script_name has corresponding query file"
58+
else
59+
echo "❌ $script_name missing query file: $expected_query_file"
60+
inconsistent=$((inconsistent + 1))
61+
fi
62+
fi
63+
done
64+
65+
# Check that each query file has a corresponding script
66+
for query_file in "$query_dir"/*.graphql; do
67+
if [ ! -f "$query_file" ]; then
68+
continue
69+
fi
70+
71+
query_name=$(basename "$query_file" .graphql)
72+
expected_script_file="$script_dir/$query_name.sh"
73+
74+
if [ -f "$expected_script_file" ]; then
75+
echo "✅ $query_name has corresponding script file"
76+
else
77+
echo "❌ $query_name query file has no corresponding script: $expected_script_file"
78+
inconsistent=$((inconsistent + 1))
79+
fi
80+
done
81+
82+
if [ $inconsistent -gt 0 ]; then
83+
echo "💥 $inconsistent script/query file inconsistencies found"
84+
exit 1
85+
else
86+
echo "🎉 All scripts and query files are consistent"
87+
fi
88+
89+
- name: Test GraphQL command scripts
90+
run: |
91+
echo "🔍 Testing GraphQL API command scripts..."
92+
93+
# Dynamically discover all bash scripts in the queries/curl directory (only test queries, not mutations)
94+
script_dir="website/docs/developers/scripts/graphql-api/queries/curl"
95+
96+
if [ ! -d "$script_dir" ]; then
97+
echo "❌ Script directory not found: $script_dir"
98+
exit 1
99+
fi
100+
101+
# Get all .sh files in the curl directory
102+
script_files=$(ls "$script_dir"/*.sh 2>/dev/null)
103+
104+
if [ -z "$script_files" ]; then
105+
echo "❌ No bash scripts found in $script_dir"
106+
exit 1
107+
fi
108+
109+
failed=0
110+
111+
for script_file in $script_files; do
112+
if [ ! -f "$script_file" ]; then
113+
echo "❌ Script file not found: $script_file"
114+
failed=$((failed + 1))
115+
continue
116+
fi
117+
118+
echo "Testing script: $script_file"
119+
120+
# Execute the script and capture output
121+
if output=$(timeout 30 bash "$script_file" 2>&1); then
122+
echo "✅ Script executed successfully"
123+
124+
# Check if this is a GraphQL script (contains JSON response)
125+
if echo "$output" | grep -q "^{"; then
126+
# Extract JSON response (skip curl progress output)
127+
json_response=$(echo "$output" | grep "^{")
128+
129+
# Check if it's valid JSON
130+
if echo "$json_response" | jq . > /dev/null 2>&1; then
131+
# Check for GraphQL errors
132+
if echo "$json_response" | jq -e '.errors' > /dev/null 2>&1; then
133+
echo "❌ Script returned GraphQL errors:"
134+
echo "$json_response" | jq '.errors'
135+
failed=$((failed + 1))
136+
else
137+
echo "✅ Script response contains valid JSON: $(echo "$json_response" | head -c 100)..."
138+
fi
139+
else
140+
echo "❌ Script returned invalid JSON: $(echo "$json_response" | head -c 100)..."
141+
failed=$((failed + 1))
142+
fi
143+
else
144+
# Non-JSON script validation (basic error checking)
145+
if echo "$output" | grep -q "error\|Error\|ERROR"; then
146+
echo "⚠️ Script returned error response: $(echo "$output" | head -c 100)..."
147+
else
148+
echo "✅ Script response looks valid: $(echo "$output" | head -c 100)..."
149+
fi
150+
fi
151+
else
152+
echo "❌ Script execution failed: $script_file"
153+
failed=$((failed + 1))
154+
fi
155+
156+
echo "---"
157+
done
158+
159+
if [ $failed -gt 0 ]; then
160+
echo "💥 $failed GraphQL script tests failed"
161+
echo "Some GraphQL API scripts may need updates."
162+
exit 1
163+
else
164+
echo "🎉 All GraphQL API command scripts are working"
165+
fi

0 commit comments

Comments
 (0)