Skip to content

Commit a6aaffe

Browse files
Fixes on update-thv-models
The script is failing currently. I will invesitgate by runnin in this branch/PR
1 parent c387c70 commit a6aaffe

File tree

2 files changed

+83
-35
lines changed

2 files changed

+83
-35
lines changed

.github/workflows/update-thv-models.yml

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,70 @@ jobs:
3737
with:
3838
version: 3.44.1
3939

40-
- name: Install Dependencies
41-
run: task install
40+
- name: Start ToolHive Server
41+
run: |
42+
echo "Starting thv serve --openapi on port 8080..."
43+
thv serve --openapi --port 8080 &
44+
THV_PID=$!
45+
echo "THV_PID=$THV_PID" >> $GITHUB_ENV
46+
echo "thv serve started with PID: $THV_PID"
47+
48+
echo "Waiting for thv serve to be ready..."
49+
MAX_ATTEMPTS=30
50+
for i in $(seq 1 $MAX_ATTEMPTS); do
51+
# Check if the process is still running
52+
if ! kill -0 "$THV_PID" 2>/dev/null; then
53+
wait "$THV_PID" || true
54+
exit_code=$?
55+
echo "ERROR: thv serve process (PID: $THV_PID) exited unexpectedly with code $exit_code"
56+
exit $exit_code
57+
fi
58+
59+
# Check if endpoint returns valid JSON with expected content
60+
if response=$(curl -s --max-time 5 http://127.0.0.1:8080/api/openapi.json 2>&1); then
61+
# Validate JSON
62+
if echo "$response" | python3 -m json.tool > /dev/null 2>&1; then
63+
# Check for openapi field
64+
if echo "$response" | grep -q "openapi"; then
65+
echo "thv serve is ready!"
66+
break
67+
else
68+
echo "Attempt $i/$MAX_ATTEMPTS: Response doesn't contain 'openapi' field"
69+
fi
70+
else
71+
echo "Attempt $i/$MAX_ATTEMPTS: Invalid JSON response"
72+
fi
73+
else
74+
echo "Attempt $i/$MAX_ATTEMPTS: curl failed"
75+
fi
76+
77+
if [ $i -eq $MAX_ATTEMPTS ]; then
78+
echo "ERROR: thv serve did not become ready after $MAX_ATTEMPTS attempts"
79+
echo "Last response: $response"
80+
# Kill the process if it's still running
81+
kill "$THV_PID" 2>/dev/null || true
82+
exit 1
83+
fi
84+
sleep 1
85+
done
4286
4387
- name: Generate ToolHive Models
88+
env:
89+
MANAGE_THV: "false"
4490
run: task generate-thv-models
4591

92+
- name: Stop ToolHive Server
93+
if: always()
94+
run: |
95+
if [ -n "$THV_PID" ] && kill -0 "$THV_PID" 2>/dev/null; then
96+
echo "Stopping thv serve (PID: $THV_PID)..."
97+
kill "$THV_PID" 2>/dev/null || true
98+
wait "$THV_PID" 2>/dev/null || true
99+
echo "thv serve stopped"
100+
else
101+
echo "thv serve process not running or already stopped"
102+
fi
103+
46104
- name: Check for Changes
47105
id: check-changes
48106
run: |
@@ -65,6 +123,7 @@ jobs:
65123
66124
Automated update of ToolHive API models from OpenAPI specification.
67125
branch: update-thv-models-${{ github.run_id }}
126+
base: main
68127
delete-branch: true
69128
title: 'chore: Update ToolHive API models'
70129
body: |

scripts/generate_toolhive_models.sh

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,39 @@ set -euo pipefail
44

55
OUTPUT_DIR="src/mcp_optimizer/toolhive/api_models"
66
TEMP_DIR="$(mktemp -d)"
7-
THV_PID=""
8-
MANAGE_THV="${MANAGE_THV:-true}"
97

108
# Cleanup function
119
cleanup() {
1210
local exit_code=$?
13-
if [ -n "$THV_PID" ] && [ "$MANAGE_THV" = "true" ]; then
14-
# Check if process exists before attempting to kill
15-
if kill -0 "$THV_PID" 2>/dev/null; then
16-
echo "Stopping thv serve (PID: $THV_PID)..."
17-
kill "$THV_PID" 2>/dev/null || true
18-
wait "$THV_PID" 2>/dev/null || true
19-
fi
20-
fi
2111
rm -rf "$TEMP_DIR"
2212
exit $exit_code
2313
}
2414

2515
trap cleanup EXIT INT TERM
2616

27-
# Start thv serve if we're managing it
28-
if [ "$MANAGE_THV" = "true" ]; then
29-
echo "Starting thv serve --openapi on port 8080..."
30-
thv serve --openapi --port 8080 &
31-
THV_PID=$!
32-
33-
echo "Waiting for thv serve to be ready..."
34-
MAX_ATTEMPTS=30
35-
for i in $(seq 1 $MAX_ATTEMPTS); do
36-
# Check if endpoint returns valid JSON with expected content
37-
response=$(curl -s --max-time 5 http://127.0.0.1:8080/api/openapi.json 2>&1)
38-
if [ $? -eq 0 ] && echo "$response" | python3 -m json.tool > /dev/null 2>&1 && echo "$response" | grep -q "openapi"; then
39-
echo "thv serve is ready!"
40-
break
41-
fi
42-
if [ $i -eq $MAX_ATTEMPTS ]; then
43-
echo "ERROR: thv serve did not become ready"
44-
echo "Last response: $response"
45-
exit 1
17+
# Verify thv serve is running and accessible
18+
echo "Checking if thv serve is accessible..."
19+
MAX_ATTEMPTS=5
20+
for i in $(seq 1 $MAX_ATTEMPTS); do
21+
if response=$(curl -s --max-time 5 http://127.0.0.1:8080/api/openapi.json 2>&1); then
22+
# Validate JSON
23+
if echo "$response" | uv run python -m json.tool > /dev/null 2>&1; then
24+
# Check for openapi field
25+
if echo "$response" | grep -q "openapi"; then
26+
echo "thv serve is accessible!"
27+
break
28+
fi
4629
fi
47-
echo "Attempt $i/$MAX_ATTEMPTS: Waiting for OpenAPI endpoint..."
48-
sleep 1
49-
done
50-
fi
30+
fi
31+
32+
if [ $i -eq $MAX_ATTEMPTS ]; then
33+
echo "ERROR: thv serve is not accessible at http://127.0.0.1:8080/api/openapi.json"
34+
echo "Please ensure thv serve is running with --openapi flag on port 8080"
35+
exit 1
36+
fi
37+
echo "Attempt $i/$MAX_ATTEMPTS: Waiting for thv serve..."
38+
sleep 1
39+
done
5140

5241
# Save current models to temp directory for comparison
5342
if [ -d "$OUTPUT_DIR" ]; then

0 commit comments

Comments
 (0)