diff --git a/update-gitops-status.sh b/update-gitops-status.sh index 5daf927..a7a8ffb 100644 --- a/update-gitops-status.sh +++ b/update-gitops-status.sh @@ -72,8 +72,23 @@ if [ "$MODE" = "post-deploy" ]; then # Check what files changed in the last commit in files/ directory if command -v git >/dev/null 2>&1 && [ -d .git ]; then - # Get list of changed files in files/ directory from last commit - CHANGED_FILE_PATHS=$(git diff-tree --no-commit-id --name-only -r HEAD -- files/ 2>/dev/null || echo "") + # Try multiple methods to detect changed files (Woodpecker might do shallow clone) + + # Method 1: Use git show to see files in HEAD commit + CHANGED_FILE_PATHS=$(git show --name-only --pretty="" HEAD -- files/ 2>/dev/null || echo "") + + # Method 2: If method 1 fails, try diff with parent (if it exists) + if [ -z "$CHANGED_FILE_PATHS" ]; then + CHANGED_FILE_PATHS=$(git diff --name-only HEAD~1 HEAD -- files/ 2>/dev/null || echo "") + fi + + # Method 3: If still nothing, check Woodpecker CI environment variables + if [ -z "$CHANGED_FILE_PATHS" ] && [ -n "${CI_COMMIT_CHANGED_FILES:-}" ]; then + # Filter CI_COMMIT_CHANGED_FILES to only files/ directory + CHANGED_FILE_PATHS=$(echo "$CI_COMMIT_CHANGED_FILES" | tr ' ' '\n' | grep '^files/' || echo "") + fi + + echo " DEBUG: Git detection method results: '$CHANGED_FILE_PATHS'" if [ -n "$CHANGED_FILE_PATHS" ]; then echo " Files changed in last commit:"