Skip to content

Commit 194f750

Browse files
committed
wip: ci
1 parent 02f3041 commit 194f750

2 files changed

Lines changed: 77 additions & 9 deletions

File tree

.github/workflows/solana-unit-tests.yaml

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,36 @@ jobs:
5252
5353
# Start port-forward and keep this step alive while tests run
5454
if [ -n "${NS}" ]; then
55-
NS="$NS" bash networks/solana/starship/port-forward.sh &
55+
PORTS_ENV_FILE="networks/solana/starship/.pf-env" NS="$NS" bash networks/solana/starship/port-forward.sh &
5656
PF_SUPERVISOR_PID=$!
5757
# Clean up on exit
5858
trap 'echo "Stopping port-forward"; kill -9 ${PF_SUPERVISOR_PID} >/dev/null 2>&1 || true; pkill -f "kubectl -n ${NS} port-forward" || true' EXIT
5959
else
6060
echo "Could not determine namespace for port-forward" >&2
6161
fi
6262
63-
echo "Waiting for RPC health on 127.0.0.1:8899 ..."
63+
# Load dynamic ports from port-forward script if provided
64+
PF_ENV="networks/solana/starship/.pf-env"
65+
for i in $(seq 1 50); do
66+
if [ -f "$PF_ENV" ]; then
67+
# shellcheck disable=SC1090
68+
. "$PF_ENV" || true
69+
break
70+
fi
71+
sleep 0.2
72+
done
73+
74+
RPC_PORT="${SOLANA_RPC_PORT:-8899}"
75+
WS_PORT="${SOLANA_WS_PORT:-8900}"
76+
export SOLANA_RPC_PORT="$RPC_PORT"
77+
export SOLANA_WS_PORT="$WS_PORT"
78+
export SOLANA_RPC_ENDPOINT="http://127.0.0.1:${RPC_PORT}"
79+
export SOLANA_WS_ENDPOINT="ws://127.0.0.1:${WS_PORT}"
80+
81+
echo "Waiting for RPC health on 127.0.0.1:${RPC_PORT} ..."
6482
ok=0
6583
for i in $(seq 1 60); do
66-
if curl -fsS http://127.0.0.1:8899/health | grep -qi ok; then
84+
if curl -fsS "http://127.0.0.1:${RPC_PORT}/health" | grep -qi ok; then
6785
ok=1; break
6886
fi
6987
sleep 5
@@ -76,18 +94,18 @@ jobs:
7694
exit 1
7795
fi
7896
79-
echo "Waiting for WS port on 127.0.0.1:8900 ..."
97+
echo "Waiting for WS port on 127.0.0.1:${WS_PORT} ..."
8098
ws_ok=0
8199
for i in $(seq 1 60); do
82100
if command -v nc >/dev/null 2>&1; then
83-
if nc -z 127.0.0.1 8900 >/dev/null 2>&1; then ws_ok=1; break; fi
101+
if nc -z 127.0.0.1 "${WS_PORT}" >/dev/null 2>&1; then ws_ok=1; break; fi
84102
else
85-
if (exec 3<>/dev/tcp/127.0.0.1/8900) 2>/dev/null; then exec 3>&- 3<&-; ws_ok=1; break; fi
103+
if (exec 3<>/dev/tcp/127.0.0.1/"${WS_PORT}") 2>/dev/null; then exec 3>&- 3<&-; ws_ok=1; break; fi
86104
fi
87105
sleep 2
88106
done
89107
if [ "$ws_ok" -ne 1 ]; then
90-
echo "WebSocket port 8900 not reachable; dumping diagnostics" >&2
108+
echo "WebSocket port ${WS_PORT} not reachable; dumping diagnostics" >&2
91109
if command -v ss >/dev/null 2>&1; then ss -ltnp || true; fi
92110
if command -v lsof >/dev/null 2>&1; then lsof -iTCP -sTCP:LISTEN || true; fi
93111
kubectl get svc -A -o wide || true

networks/solana/starship/port-forward.sh

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ NS="${NS:-default}" # Override with --ns
66
POD_NAME="" # Override with --pod
77
SLEEP_BETWEEN=0.2
88
CHECK_RETRIES=25 # 25 * 0.2s = 5s
9+
PORTS_ENV_FILE="${PORTS_ENV_FILE:-$(dirname "$0")/.pf-env}"
910

1011
usage() {
1112
echo "Usage: $0 [--ns <namespace>] [--pod <pod-name>]"
@@ -39,11 +40,15 @@ start_pf() {
3940
local target="$1" # pods/<pod> or service/<svc>
4041
local mapping="$2" # <local>:<remote>
4142
local local_port="${mapping%%:*}"
43+
local remote_port="${mapping##*:}"
4244

4345
free_port "$local_port"
4446

4547
# Start in background
46-
kubectl -n "$NS" port-forward "$target" "$mapping" >/dev/null 2>&1 &
48+
# Capture logs for troubleshooting in CI
49+
mkdir -p "$(dirname "$PORTS_ENV_FILE")"
50+
local log_file="$(dirname "$PORTS_ENV_FILE")/pf_${local_port}.log"
51+
kubectl -n "$NS" port-forward "$target" "$mapping" >"$log_file" 2>&1 &
4752
local pf_pid=$!
4853

4954
# Health check: wait for local port to open
@@ -69,14 +74,45 @@ start_pf() {
6974

7075
if [[ $ok -eq 1 ]]; then
7176
log "Forwarded $target (local $mapping)"
77+
# Record ports to env file for consumers (e.g., CI step/tests)
78+
case "$remote_port" in
79+
8899)
80+
echo "export SOLANA_RPC_PORT=$local_port" >>"$PORTS_ENV_FILE" ;;
81+
8900)
82+
echo "export SOLANA_WS_PORT=$local_port" >>"$PORTS_ENV_FILE" ;;
83+
8080)
84+
echo "export REGISTRY_REST_PORT=$local_port" >>"$PORTS_ENV_FILE" ;;
85+
9090)
86+
echo "export REGISTRY_GRPC_PORT=$local_port" >>"$PORTS_ENV_FILE" ;;
87+
esac
7288
return 0
7389
else
7490
err "Failed to forward $target (local $mapping); killing pid $pf_pid"
7591
kill -9 "$pf_pid" >/dev/null 2>&1 || true
92+
# Surface port-forward logs to help debugging
93+
if [[ -f "$log_file" ]]; then
94+
err "---- port-forward log ($log_file) ----"
95+
tail -n +1 "$log_file" >&2 || true
96+
err "---- end log ----"
97+
fi
7698
return 1
7799
fi
78100
}
79101

102+
# Try a list of local ports for a given remote port and record the first success
103+
start_pf_any() {
104+
local target="$1"
105+
local remote_port="$2"
106+
shift 2
107+
local candidate
108+
for candidate in "$@"; do
109+
if start_pf "$target" "${candidate}:${remote_port}"; then
110+
return 0
111+
fi
112+
done
113+
return 1
114+
}
115+
80116
# Resolve POD_NAME if not provided
81117
resolve_pod() {
82118
if [[ -n "$POD_NAME" ]]; then
@@ -108,12 +144,26 @@ fi
108144
log "Using namespace: $NS"
109145
log "Using pod: $POD_NAME"
110146

147+
# Reset env file for fresh run
148+
mkdir -p "$(dirname "$PORTS_ENV_FILE")"
149+
: > "$PORTS_ENV_FILE"
150+
111151
success=0
112152

113153
# ---- Pod/Service Ports (with fallback) ----
114154
# Try pod first; if it fails, fall back to service/solana-genesis
115155
( start_pf "pods/$POD_NAME" "8899:8899" || start_pf "service/solana-genesis" "8899:8899" ) && ((success++)) # Solana RPC
116-
( start_pf "pods/$POD_NAME" "8900:8900" || start_pf "service/solana-genesis" "8900:8900" ) && ((success++)) # Solana WS
156+
157+
# WebSocket: try default 8900 locally; if bind fails, try alternates and record selected port
158+
if start_pf "pods/$POD_NAME" "8900:8900" || start_pf "service/solana-genesis" "8900:8900"; then
159+
((success++))
160+
else
161+
# Try alternate local ports mapping to remote 8900
162+
if start_pf_any "pods/$POD_NAME" 8900 8910 18900 19000 29000 || \
163+
start_pf_any "service/solana-genesis" 8900 8910 18900 19000 29000; then
164+
((success++))
165+
fi
166+
fi
117167
start_pf "pods/$POD_NAME" "8001:8001" && ((success++)) # Exposer
118168
start_pf "pods/$POD_NAME" "9900:9900" && ((success++)) # Faucet
119169

0 commit comments

Comments
 (0)