From 0b799bef848b2a68cbb434864eb37a7c51e7c8ec Mon Sep 17 00:00:00 2001 From: dvirlabs Date: Fri, 24 Apr 2026 15:33:50 +0300 Subject: [PATCH] test --- update-gitops-status.sh | 52 ++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/update-gitops-status.sh b/update-gitops-status.sh index 8a00434..b51b447 100644 --- a/update-gitops-status.sh +++ b/update-gitops-status.sh @@ -230,33 +230,53 @@ fi # ───────────────────────────────────────────────────────────────────────────────── echo "Step 3/4: Building JSON payload..." -# Convert files array to JSON -FILES_JSON="[]" -if [ ${#CHANGED_FILES[@]} -gt 0 ]; then - FILES_JSON="[" - for i in "${!CHANGED_FILES[@]}"; do - if [ "$i" -gt 0 ]; then - FILES_JSON+="," - fi - # Escape special characters in filenames for JSON - escaped_name="${CHANGED_FILES[$i]//\\/\\\\}" - escaped_name="${escaped_name//\"/\\\"}" - FILES_JSON+="{\"name\":\"$escaped_name\"}" - done - FILES_JSON+="]" +# Determine which field to populate based on mode +if [ "$MODE" = "post-deploy" ]; then + # Post-deploy: populate deployed_files, keep drifted_files empty + DEPLOYED_FILES_JSON="[" + DRIFTED_FILES_JSON="[]" + + if [ ${#CHANGED_FILES[@]} -gt 0 ]; then + for i in "${!CHANGED_FILES[@]}"; do + if [ "$i" -gt 0 ]; then + DEPLOYED_FILES_JSON+="," + fi + escaped_name="${CHANGED_FILES[$i]//\\/\\\\}" + escaped_name="${escaped_name//\"/\\\"}" + DEPLOYED_FILES_JSON+="{\"name\":\"$escaped_name\"}" + done + fi + DEPLOYED_FILES_JSON+="]" +else + # Drift-check mode: populate drifted_files, keep deployed_files empty + DEPLOYED_FILES_JSON="[]" + DRIFTED_FILES_JSON="[" + + if [ ${#CHANGED_FILES[@]} -gt 0 ]; then + for i in "${!CHANGED_FILES[@]}"; do + if [ "$i" -gt 0 ]; then + DRIFTED_FILES_JSON+="," + fi + escaped_name="${CHANGED_FILES[$i]//\\/\\\\}" + escaped_name="${escaped_name//\"/\\\"}" + DRIFTED_FILES_JSON+="{\"name\":\"$escaped_name\"}" + done + fi + DRIFTED_FILES_JSON+="]" fi # Generate ISO 8601 timestamp TIMESTAMP=$(date -u +'%Y-%m-%dT%H:%M:%SZ') -# Build complete JSON status +# Build complete JSON status with both fields STATUS_JSON=$(cat <