fix: sync-envs-to-secrets depth 3, fix ((copied++)) set -e bug
This commit is contained in:
@@ -26,26 +26,27 @@ copied=0
|
|||||||
skipped=0
|
skipped=0
|
||||||
|
|
||||||
while IFS= read -r -d '' envfile; do
|
while IFS= read -r -d '' envfile; do
|
||||||
# Derive stack name from parent directory
|
# Derive stack name: use "parent-child" for nested dirs (e.g. media/kima-hub → media-kima-hub)
|
||||||
stack=$(basename "$(dirname "$envfile")")
|
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"
|
dest="${ENV_DIR}/${stack}.env"
|
||||||
|
|
||||||
if [[ -f "$dest" ]]; then
|
if [[ -f "$dest" ]]; then
|
||||||
# Only overwrite if source is newer or different
|
|
||||||
if ! diff -q "$envfile" "$dest" &>/dev/null; then
|
if ! diff -q "$envfile" "$dest" &>/dev/null; then
|
||||||
cp "$envfile" "$dest"
|
cp "$envfile" "$dest"
|
||||||
info "Updated: ${stack}.env"
|
info "Updated: ${stack}.env"
|
||||||
((copied++))
|
copied=$((copied + 1))
|
||||||
else
|
else
|
||||||
warn "Unchanged: ${stack}.env — skipping"
|
warn "Unchanged: ${stack}.env — skipping"
|
||||||
((skipped++))
|
skipped=$((skipped + 1))
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
cp "$envfile" "$dest"
|
cp "$envfile" "$dest"
|
||||||
info "Added: ${stack}.env"
|
info "Added: ${stack}.env"
|
||||||
((copied++))
|
copied=$((copied + 1))
|
||||||
fi
|
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
|
if [[ $copied -eq 0 ]]; then
|
||||||
warn "Nothing new to commit ($skipped unchanged)."
|
warn "Nothing new to commit ($skipped unchanged)."
|
||||||
|
|||||||
Reference in New Issue
Block a user