From fb28f15ad85699c45a2a4d28554458aa5687d580 Mon Sep 17 00:00:00 2001 From: Benjamin Labrecque Date: Thu, 30 Jul 2026 14:59:28 +0200 Subject: [PATCH] feat: add services tests before deploying --- .gitea/workflows/deploy.yml | 41 ++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 42b933e..b0231a6 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -89,24 +89,45 @@ jobs: # ----------------------------------------------------------------- # Services Deployment # ----------------------------------------------------------------- - - name: Deploy Changed Services + - name: Detect Changed Services if: steps.filter.outputs.services == 'true' + id: detect-services run: | - # 1. Determine git comparison point BEFORE="${{ github.event.before }}" if [ -z "$BEFORE" ] || [ "$BEFORE" = "0000000000000000000000000000000000000000" ]; then BEFORE="HEAD~1" fi - # 2. Extract list of modified service folder names - CHANGED_SERVICES=$(git diff --name-only "$BEFORE" "${{ github.sha }}" | awk -F/ '$1=="services" && $2!="" {print $2}' | sort -u) + # Get space-separated list of changed service directory names + CHANGED_SERVICES=$(git diff --name-only "$BEFORE" "${{ github.sha }}" | awk -F/ '$1=="services" && $2!="" {print $2}' | sort -u | tr '\n' ' ') + + echo "services=$CHANGED_SERVICES" >> $GITHUB_OUTPUT + echo "Detected changed services: $CHANGED_SERVICES" - if [ -z "$CHANGED_SERVICES" ]; then - echo "No service directory changes detected in diff." - exit 0 - fi + - name: Test Changed Services + if: steps.filter.outputs.services == 'true' && steps.detect-services.outputs.services != '' + run: | + SERVICES="${{ steps.detect-services.outputs.services }}" + + for SERVICE in $SERVICES; do + SERVICE_DIR="services/$SERVICE" + if [ -d "$SERVICE_DIR/tests" ]; then + echo "==========================================" + echo "Running tests for: $SERVICE" + echo "==========================================" + + # Run pytest inside the service directory using uv + uv run --directory "$SERVICE_DIR" pytest + else + echo "No tests directory found for $SERVICE, skipping..." + fi + done - # 3. Loop through changed services and invoke deployment script - echo "$CHANGED_SERVICES" | while read -r SERVICE; do + - name: Deploy Changed Services + if: steps.filter.outputs.services == 'true' && steps.detect-services.outputs.services != '' + run: | + SERVICES="${{ steps.detect-services.outputs.services }}" + + for SERVICE in $SERVICES; do ./.gitea/scripts/deploy-and-restart-service.sh "${SERVICE}" "${AGEBD_ENV}" done