Skip to content

Commit e73dfc5

Browse files
committed
fix: adjusted script to not exit when encountering other files
1 parent 9e8a5ca commit e73dfc5

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

scripts/inject-version.sh

100644100755
Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,40 @@ set -euo pipefail
77
IFS=$'\n\t'
88

99
# ---- args & checks ----
10-
[ $# -ge 1 ] || { echo "Usage: $0 <version> [dir]" >&2; exit 1; }
10+
if [ $# -lt 1 ]; then
11+
echo "Usage: $0 <version> [dir]" >&2
12+
exit 1
13+
fi
14+
1115
V="$1"
1216
DIR="${2:-definitions}"
1317

14-
command -v jq >/dev/null 2>&1 || { echo "jq is required" >&2; exit 1; }
15-
[[ "$V" =~ ^[0-9]+(\.[0-9]+)*$ ]] || { echo "Invalid version: $V" >&2; exit 1; }
16-
[ -d "$DIR" ] || { echo "Folder not found: $DIR" >&2; exit 1; }
18+
if ! command -v jq >/dev/null 2>&1; then
19+
echo "jq is required" >&2
20+
exit 1
21+
fi
22+
23+
if [[ ! "$V" =~ ^[0-9]+(\.[0-9]+)*$ ]]; then
24+
echo "Invalid version: $V" >&2
25+
exit 1
26+
fi
27+
28+
if [ ! -d "$DIR" ]; then
29+
echo "Folder not found: $DIR" >&2
30+
exit 1
31+
fi
1732

1833
# ---- process ----
1934
updated=0
2035
skipped=0
36+
37+
# Disable exit-on-error inside loop so non-critical skips don’t abort the script
38+
set +e
2139
while IFS= read -r -d '' f; do
2240
# Validate JSON first
2341
if ! jq -e . "$f" >/dev/null 2>&1; then
2442
echo "INVALID JSON (skipped): $f" >&2
25-
((skipped++))
43+
((skipped+=1)) || true
2644
continue
2745
fi
2846

@@ -33,16 +51,18 @@ while IFS= read -r -d '' f; do
3351
if jq --arg v "$V" '.version=$v' "$f" >"$tmp"; then
3452
mv -f "$tmp" "$f"
3553
echo "updated: $f"
36-
((updated++))
54+
((updated+=1)) || true
3755
else
3856
echo "ERROR processing: $f" >&2
3957
rm -f "$tmp"
40-
((skipped++))
58+
((skipped+=1)) || true
4159
fi
4260
else
4361
echo "skipped (non-object): $f"
44-
((skipped++))
62+
((skipped+=1)) || true
4563
fi
4664
done < <(find "$DIR" -type f -name '*.json' -print0)
65+
set -e
4766

4867
echo "Done. Updated: $updated Skipped: $skipped"
68+
exit 0

0 commit comments

Comments
 (0)