|
| 1 | +name: Run Solana Unit Tests |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - solana |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +jobs: |
| 10 | + networks-solana: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + steps: |
| 14 | + - name: Checkout Repository 📝 |
| 15 | + uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Setup Node.js |
| 18 | + uses: actions/setup-node@v4 |
| 19 | + with: |
| 20 | + node-version: "20.x" |
| 21 | + cache: "yarn" |
| 22 | + |
| 23 | + - name: Install Dependencies |
| 24 | + run: yarn install --frozen-lockfile |
| 25 | + |
| 26 | + - name: Build Project |
| 27 | + run: yarn build |
| 28 | + |
| 29 | + - name: Set Up Starship Infrastructure |
| 30 | + id: starship-infra |
| 31 | + uses: hyperweb-io/[email protected] |
| 32 | + with: |
| 33 | + config: networks/solana/starship/configs/config.yaml |
| 34 | + |
| 35 | + - name: Port-forward and run Solana unit tests |
| 36 | + run: | |
| 37 | + set -euxo pipefail |
| 38 | + # Discover namespace |
| 39 | + NS="${{ steps.starship-infra.outputs.namespace }}" |
| 40 | + if [ -z "${NS}" ]; then |
| 41 | + NS=$(kubectl get pods -A -o jsonpath='{range .items[*]}{.metadata.namespace}{" "}{.metadata.name}{"\n"}{end}' | awk '/solana-genesis/{print $1; exit}' || true) |
| 42 | + fi |
| 43 | + echo "Using namespace: ${NS:-<unknown>}" |
| 44 | +
|
| 45 | + echo "Checking pods status..." |
| 46 | + kubectl get pods -A -o wide || true |
| 47 | + if [ -n "${NS}" ]; then |
| 48 | + kubectl get pods -n "$NS" -o wide || true |
| 49 | + (kubectl wait --for=condition=Ready pod -l app=solana-genesis -n "$NS" --timeout=300s || \ |
| 50 | + kubectl wait --for=condition=Ready pod -l app.kubernetes.io/name=solana-genesis -n "$NS" --timeout=300s) || true |
| 51 | + fi |
| 52 | +
|
| 53 | + # Start port-forward and keep this step alive while tests run |
| 54 | + if [ -n "${NS}" ]; then |
| 55 | + echo "Starting port-forward process..." |
| 56 | + PORTS_ENV_FILE="networks/solana/starship/.pf-env" NS="$NS" bash networks/solana/starship/port-forward.sh & |
| 57 | + PF_SUPERVISOR_PID=$! |
| 58 | + # Clean up on exit |
| 59 | + trap 'echo "Stopping port-forward"; kill -9 ${PF_SUPERVISOR_PID} >/dev/null 2>&1 || true; pkill -f "kubectl -n ${NS} port-forward" || true' EXIT |
| 60 | +
|
| 61 | + # Give port-forward script time to start |
| 62 | + echo "Allowing port-forward script time to initialize..." |
| 63 | + sleep 5 |
| 64 | + else |
| 65 | + echo "Could not determine namespace for port-forward" >&2 |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | +
|
| 69 | + # Load dynamic ports from port-forward script if provided |
| 70 | + PF_ENV="networks/solana/starship/.pf-env" |
| 71 | + echo "Waiting for port-forward setup to complete..." |
| 72 | + for i in $(seq 1 100); do |
| 73 | + if [ -f "$PF_ENV" ]; then |
| 74 | + # shellcheck disable=SC1090 |
| 75 | + . "$PF_ENV" || true |
| 76 | + echo "Port-forward environment loaded from $PF_ENV" |
| 77 | + cat "$PF_ENV" || true |
| 78 | + break |
| 79 | + fi |
| 80 | + if [ $((i % 25)) -eq 0 ]; then |
| 81 | + echo "Still waiting for port-forward setup... (${i}/100)" |
| 82 | + fi |
| 83 | + sleep 0.2 |
| 84 | + done |
| 85 | +
|
| 86 | + RPC_PORT="${SOLANA_RPC_PORT:-8899}" |
| 87 | + WS_PORT="${SOLANA_WS_PORT:-8900}" |
| 88 | + export SOLANA_RPC_PORT="$RPC_PORT" |
| 89 | + export SOLANA_WS_PORT="$WS_PORT" |
| 90 | + export SOLANA_RPC_ENDPOINT="http://127.0.0.1:${RPC_PORT}" |
| 91 | + export SOLANA_WS_ENDPOINT="ws://127.0.0.1:${WS_PORT}" |
| 92 | +
|
| 93 | + echo "Waiting for RPC health on 127.0.0.1:${RPC_PORT} ..." |
| 94 | + ok=0 |
| 95 | + for i in $(seq 1 60); do |
| 96 | + if curl -fsS "http://127.0.0.1:${RPC_PORT}/health" | grep -qi ok; then |
| 97 | + ok=1; break |
| 98 | + fi |
| 99 | + sleep 5 |
| 100 | + done |
| 101 | +
|
| 102 | + if [ "$ok" -ne 1 ]; then |
| 103 | + echo "RPC not healthy; dumping diagnostics" >&2 |
| 104 | + kubectl get pods -A -o wide || true |
| 105 | + if [ -n "${NS}" ]; then kubectl describe pods -n "$NS" || true; fi |
| 106 | + exit 1 |
| 107 | + fi |
| 108 | +
|
| 109 | + echo "Waiting for WS port on 127.0.0.1:${WS_PORT} ..." |
| 110 | + ws_ok=0 |
| 111 | + for i in $(seq 1 60); do |
| 112 | + if command -v nc >/dev/null 2>&1; then |
| 113 | + if nc -z 127.0.0.1 "${WS_PORT}" >/dev/null 2>&1; then ws_ok=1; break; fi |
| 114 | + else |
| 115 | + if (exec 3<>/dev/tcp/127.0.0.1/"${WS_PORT}") 2>/dev/null; then exec 3>&- 3<&-; ws_ok=1; break; fi |
| 116 | + fi |
| 117 | + sleep 2 |
| 118 | + done |
| 119 | + if [ "$ws_ok" -ne 1 ]; then |
| 120 | + echo "WebSocket port ${WS_PORT} not reachable; dumping diagnostics" >&2 |
| 121 | + echo "=== Current listening ports ===" |
| 122 | + if command -v ss >/dev/null 2>&1; then ss -ltnp || true; fi |
| 123 | + if command -v lsof >/dev/null 2>&1; then lsof -iTCP -sTCP:LISTEN || true; fi |
| 124 | + echo "=== Port-forward environment file ===" |
| 125 | + if [ -f "$PF_ENV" ]; then cat "$PF_ENV" || true; else echo "No $PF_ENV file found"; fi |
| 126 | + echo "=== Port-forward log files ===" |
| 127 | + ls -la networks/solana/starship/pf_*.log 2>/dev/null || echo "No port-forward log files found" |
| 128 | + for log in networks/solana/starship/pf_*.log; do |
| 129 | + if [ -f "$log" ]; then |
| 130 | + echo "=== Contents of $log ===" |
| 131 | + cat "$log" || true |
| 132 | + fi |
| 133 | + done |
| 134 | + echo "=== Kubernetes services ===" |
| 135 | + kubectl get svc -A -o wide || true |
| 136 | + if [ -n "${NS}" ]; then |
| 137 | + echo "=== Pods in namespace $NS ===" |
| 138 | + kubectl get pods -n "$NS" -o wide || true |
| 139 | + echo "=== Pod descriptions ===" |
| 140 | + (kubectl describe pods -l app=solana-genesis -n "$NS" || \ |
| 141 | + kubectl describe pods -l app.kubernetes.io/name=solana-genesis -n "$NS") || true |
| 142 | + fi |
| 143 | + exit 1 |
| 144 | + fi |
| 145 | +
|
| 146 | + cd ./networks/solana |
| 147 | + yarn test --runInBand |
0 commit comments