test
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/cron/woodpecker Pipeline was successful

This commit is contained in:
dvirlabs 2026-04-24 15:33:50 +03:00
parent bbd675460f
commit 0b799bef84

View File

@ -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="["
# 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
FILES_JSON+=","
DEPLOYED_FILES_JSON+=","
fi
# Escape special characters in filenames for JSON
escaped_name="${CHANGED_FILES[$i]//\\/\\\\}"
escaped_name="${escaped_name//\"/\\\"}"
FILES_JSON+="{\"name\":\"$escaped_name\"}"
DEPLOYED_FILES_JSON+="{\"name\":\"$escaped_name\"}"
done
FILES_JSON+="]"
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 <<EOF
{
"repo": "$REPO_NAME",
"server": "$SERVER_NAME",
"sync_status": "$SYNC_STATUS",
"drift_count": $DRIFT_COUNT,
"files": $FILES_JSON,
"deployed_files": $DEPLOYED_FILES_JSON,
"drifted_files": $DRIFTED_FILES_JSON,
"last_check": "$TIMESTAMP"
}
EOF