Skip to content

fix port-forward

fix port-forward #11

name: Run Solana Unit Tests
on:
push:
branches:
- solana
workflow_dispatch:
jobs:
networks-solana:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository 📝
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20.x"
cache: "yarn"
- name: Install Dependencies
run: yarn install --frozen-lockfile
- name: Build Project
run: yarn build
- name: Set Up Starship Infrastructure
id: starship-infra
uses: hyperweb-io/[email protected]
with:
config: networks/solana/starship/configs/config.yaml
- name: Port-forward and run Solana unit tests
run: |
set -euxo pipefail
# Discover namespace
NS="${{ steps.starship-infra.outputs.namespace }}"
if [ -z "${NS}" ]; then
NS=$(kubectl get pods -A -o jsonpath='{range .items[*]}{.metadata.namespace}{" "}{.metadata.name}{"\n"}{end}' | awk '/solana-genesis/{print $1; exit}' || true)
fi
echo "Using namespace: ${NS:-<unknown>}"
echo "Checking pods status..."
kubectl get pods -A -o wide || true
if [ -n "${NS}" ]; then
kubectl get pods -n "$NS" -o wide || true
(kubectl wait --for=condition=Ready pod -l app=solana-genesis -n "$NS" --timeout=300s || \
kubectl wait --for=condition=Ready pod -l app.kubernetes.io/name=solana-genesis -n "$NS" --timeout=300s) || true
fi
# Start port-forward and keep this step alive while tests run
if [ -n "${NS}" ]; then
echo "Starting port-forward process..."
PORTS_ENV_FILE="networks/solana/starship/.pf-env" NS="$NS" bash networks/solana/starship/port-forward.sh &
PF_SUPERVISOR_PID=$!
# Clean up on exit
trap 'echo "Stopping port-forward"; kill -9 ${PF_SUPERVISOR_PID} >/dev/null 2>&1 || true; pkill -f "kubectl -n ${NS} port-forward" || true' EXIT
# Give port-forward script time to start
echo "Allowing port-forward script time to initialize..."
sleep 5
else
echo "Could not determine namespace for port-forward" >&2
exit 1
fi
# Load dynamic ports from port-forward script if provided
PF_ENV="networks/solana/starship/.pf-env"
echo "Waiting for port-forward setup to complete..."
for i in $(seq 1 100); do
if [ -f "$PF_ENV" ]; then
# shellcheck disable=SC1090
. "$PF_ENV" || true
echo "Port-forward environment loaded from $PF_ENV"
cat "$PF_ENV" || true
break
fi
if [ $((i % 25)) -eq 0 ]; then
echo "Still waiting for port-forward setup... (${i}/100)"
fi
sleep 0.2
done
RPC_PORT="${SOLANA_RPC_PORT:-8899}"
WS_PORT="${SOLANA_WS_PORT:-8900}"
export SOLANA_RPC_PORT="$RPC_PORT"
export SOLANA_WS_PORT="$WS_PORT"
export SOLANA_RPC_ENDPOINT="http://127.0.0.1:${RPC_PORT}"
export SOLANA_WS_ENDPOINT="ws://127.0.0.1:${WS_PORT}"
echo "Waiting for RPC health on 127.0.0.1:${RPC_PORT} ..."
ok=0
for i in $(seq 1 60); do
if curl -fsS "http://127.0.0.1:${RPC_PORT}/health" | grep -qi ok; then
ok=1; break
fi
sleep 5
done
if [ "$ok" -ne 1 ]; then
echo "RPC not healthy; dumping diagnostics" >&2
kubectl get pods -A -o wide || true
if [ -n "${NS}" ]; then kubectl describe pods -n "$NS" || true; fi
exit 1
fi
echo "Waiting for WS port on 127.0.0.1:${WS_PORT} ..."
ws_ok=0
for i in $(seq 1 60); do
if command -v nc >/dev/null 2>&1; then
if nc -z 127.0.0.1 "${WS_PORT}" >/dev/null 2>&1; then ws_ok=1; break; fi
else
if (exec 3<>/dev/tcp/127.0.0.1/"${WS_PORT}") 2>/dev/null; then exec 3>&- 3<&-; ws_ok=1; break; fi
fi
sleep 2
done
if [ "$ws_ok" -ne 1 ]; then
echo "WebSocket port ${WS_PORT} not reachable; dumping diagnostics" >&2
echo "=== Current listening ports ==="
if command -v ss >/dev/null 2>&1; then ss -ltnp || true; fi
if command -v lsof >/dev/null 2>&1; then lsof -iTCP -sTCP:LISTEN || true; fi
echo "=== Port-forward environment file ==="
if [ -f "$PF_ENV" ]; then cat "$PF_ENV" || true; else echo "No $PF_ENV file found"; fi
echo "=== Port-forward log files ==="
ls -la networks/solana/starship/pf_*.log 2>/dev/null || echo "No port-forward log files found"
for log in networks/solana/starship/pf_*.log; do
if [ -f "$log" ]; then
echo "=== Contents of $log ==="
cat "$log" || true
fi
done
echo "=== Kubernetes services ==="
kubectl get svc -A -o wide || true
if [ -n "${NS}" ]; then
echo "=== Pods in namespace $NS ==="
kubectl get pods -n "$NS" -o wide || true
echo "=== Pod descriptions ==="
(kubectl describe pods -l app=solana-genesis -n "$NS" || \
kubectl describe pods -l app.kubernetes.io/name=solana-genesis -n "$NS") || true
fi
exit 1
fi
cd ./networks/solana
yarn test --runInBand