fix: sync-envs-to-secrets depth 3, fix ((copied++)) set -e bug

This commit is contained in:
Fizzlepoof
2026-05-12 08:22:40 -05:00
parent c31656bca2
commit 4d5fa8f4a0

View File

@@ -26,26 +26,27 @@ copied=0
skipped=0
while IFS= read -r -d '' envfile; do
# Derive stack name from parent directory
stack=$(basename "$(dirname "$envfile")")
# Derive stack name: use "parent-child" for nested dirs (e.g. media/kima-hub → media-kima-hub)
relpath="${envfile#${COMPOSE_ROOT}/}" # e.g. media/kima-hub/.env
stackpath="${relpath%/.env}" # e.g. media/kima-hub
stack="${stackpath//\//-}" # e.g. media-kima-hub
dest="${ENV_DIR}/${stack}.env"
if [[ -f "$dest" ]]; then
# Only overwrite if source is newer or different
if ! diff -q "$envfile" "$dest" &>/dev/null; then
cp "$envfile" "$dest"
info "Updated: ${stack}.env"
((copied++))
copied=$((copied + 1))
else
warn "Unchanged: ${stack}.env — skipping"
((skipped++))
skipped=$((skipped + 1))
fi
else
cp "$envfile" "$dest"
info "Added: ${stack}.env"
((copied++))
copied=$((copied + 1))
fi
done < <(find "$COMPOSE_ROOT" -maxdepth 2 -name ".env" -not -path "*/.git/*" -print0 | sort -z)
done < <(find "$COMPOSE_ROOT" -maxdepth 3 -name ".env" -not -path "*/.git/*" -print0 | sort -z)
if [[ $copied -eq 0 ]]; then
warn "Nothing new to commit ($skipped unchanged)."