feat: add services tests before deploying
This commit is contained in:
+31
-10
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user