diff --git a/.gitea/workflows/deploy-build-restart-service.yml b/.gitea/workflows/deploy-build-restart-service.yml index a320632..8fb8466 100644 --- a/.gitea/workflows/deploy-build-restart-service.yml +++ b/.gitea/workflows/deploy-build-restart-service.yml @@ -10,7 +10,7 @@ on: - 'prod' - 'v*' # paths: - # - 'services/000-master/**' + # - 'services/**' jobs: deploy: @@ -52,11 +52,27 @@ jobs: - name: Run Ansible Orchestrator run: | set -x + + # Disable pipefail temporarily or add an '|| true' fallback so grep doesn't kill the script + set +e + CHANGED_FILES=$(git diff --name-only bff62f79617dff38025c47fd54cccc6554d0e313 baedb68163454880544ac4eec71704c206f40f0c) + set -e + # 1. Parse changed directory names into space-separated string (e.g. "000-master 001-secondary") - CHANGED_SVC=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep "^services/" | awk -F/ '{print $2}' | sort -u | xargs) + CHANGED_SVC=$(echo "$CHANGED_FILES" | awk -F/ '$1=="services" {print $2}' | sort -u | xargs) + + echo "Detected changed services: '$CHANGED_SVC'" + + # Safely halt the execution if there is nothing to pass to Ansible + if [ -z "$CHANGED_SVC" ]; then + echo "No services changed in this commit range. Skipping deployment smoothly." + exit 0 + fi # 2. Figure out the destination target environment ENV_TARGET="${{ github.ref_type == 'tag' && 'prod' || 'dev' }}" # 3. Fire the playbook passing variables down - ansible-playbook deploy-service.yml -e "changed_services_raw='$CHANGED_SVC' agebd_env='$ENV_TARGET'" \ No newline at end of file + ansible-playbook deploy-service.yml -e "changed_services_raw='$CHANGED_SVC' agebd_env='$ENV_TARGET'" + + # Disable pipefail temporarily or add an '|| true' fallback so grep doesn't kill the script \ No newline at end of file