From aa395fbbf7587c7cb5d52cff025f50cb3b18d7a9 Mon Sep 17 00:00:00 2001 From: aitbc Date: Mon, 27 Apr 2026 09:40:21 +0200 Subject: [PATCH] ci: dynamically discover and manage systemd services in workflow tests --- .gitea/workflows/api-endpoint-tests.yml | 45 ++++++++++++++++--------- .gitea/workflows/integration-tests.yml | 38 ++++++++++++++++++--- 2 files changed, 62 insertions(+), 21 deletions(-) diff --git a/.gitea/workflows/api-endpoint-tests.yml b/.gitea/workflows/api-endpoint-tests.yml index f35eff01..faab3a5f 100644 --- a/.gitea/workflows/api-endpoint-tests.yml +++ b/.gitea/workflows/api-endpoint-tests.yml @@ -54,19 +54,26 @@ jobs: - name: Start required services run: | + cd /var/lib/aitbc-workspaces/api-tests/repo echo "Starting AITBC services for endpoint testing..." - - # Start coordinator-api - systemctl start aitbc-coordinator-api.service || echo "⚠️ coordinator-api already running or failed to start" - - # Start exchange-api - systemctl start aitbc-exchange-api.service || echo "⚠️ exchange-api already running or failed to start" - - # Start wallet daemon - systemctl start aitbc-wallet.service || echo "⚠️ wallet already running or failed to start" - - # Start blockchain RPC - systemctl start aitbc-blockchain-rpc.service || echo "⚠️ blockchain-rpc already running or failed to start" + + mapfile -t services < <( + find systemd -maxdepth 1 -type f -name "aitbc-*.service" -printf "%f\n" | + sed 's/\.service$//' | + sort + ) + + if [[ ${#services[@]} -eq 0 ]]; then + echo "⚠️ No aitbc service files found to start" + fi + + for svc in "${services[@]}"; do + if systemctl list-unit-files | grep -q "^$svc.service"; then + systemctl start "$svc" 2>/dev/null && echo "✅ $svc started" || echo "⚠️ $svc already running or failed to start" + else + echo "⚠️ $svc service file not found" + fi + done # Give services time to initialize sleep 5 @@ -155,11 +162,17 @@ jobs: - name: Cleanup if: always() run: | + cd /var/lib/aitbc-workspaces/api-tests/repo # Stop the services we started - systemctl stop aitbc-coordinator-api.service || true - systemctl stop aitbc-exchange-api.service || true - systemctl stop aitbc-wallet.service || true - systemctl stop aitbc-blockchain-rpc.service || true + mapfile -t services < <( + find systemd -maxdepth 1 -type f -name "aitbc-*.service" -printf "%f\n" | + sed 's/\.service$//' | + sort + ) + + for svc in "${services[@]}"; do + systemctl stop "$svc" || true + done # Clean up workspace rm -rf /var/lib/aitbc-workspaces/api-tests diff --git a/.gitea/workflows/integration-tests.yml b/.gitea/workflows/integration-tests.yml index a60ed168..af0471f1 100644 --- a/.gitea/workflows/integration-tests.yml +++ b/.gitea/workflows/integration-tests.yml @@ -56,12 +56,27 @@ jobs: - name: Start services if: github.event_name != 'pull_request' run: | + cd /var/lib/aitbc-workspaces/integration-tests/repo echo "Starting AITBC services..." - for svc in aitbc-coordinator-api aitbc-exchange-api aitbc-wallet aitbc-blockchain-rpc aitbc-blockchain-node aitbc-agent-coordinator; do - if systemctl is-active --quiet "$svc" 2>/dev/null; then - echo "✅ $svc already running" + mapfile -t services < <( + find systemd -maxdepth 1 -type f -name "aitbc-*.service" -printf "%f\n" | + sed 's/\.service$//' | + sort + ) + + if [[ ${#services[@]} -eq 0 ]]; then + echo "⚠️ No aitbc service files found to start" + fi + + for svc in "${services[@]}"; do + if systemctl list-unit-files | grep -q "^$svc.service"; then + if systemctl is-active --quiet "$svc" 2>/dev/null; then + echo "✅ $svc already running" + else + systemctl start "$svc" 2>/dev/null && echo "✅ $svc started" || echo "⚠️ $svc failed to start" + fi else - systemctl start "$svc" 2>/dev/null && echo "✅ $svc started" || echo "⚠️ $svc not available" + echo "⚠️ $svc service file not found" fi sleep 1 done @@ -147,8 +162,21 @@ jobs: - name: Service status report if: always() run: | + cd /var/lib/aitbc-workspaces/integration-tests/repo echo "=== Service Status ===" - for svc in aitbc-coordinator-api aitbc-exchange-api aitbc-wallet aitbc-blockchain-rpc aitbc-blockchain-node aitbc-agent-coordinator; do + + mapfile -t services < <( + find systemd -maxdepth 1 -type f -name "aitbc-*.service" -printf "%f\n" | + sed 's/\.service$//' | + sort + ) + + if [[ ${#services[@]} -eq 0 ]]; then + echo "⚠️ No aitbc service files found" + exit 0 + fi + + for svc in "${services[@]}"; do status=$(systemctl is-active "$svc" 2>/dev/null) || status="inactive" echo " $svc: $status" done