Skip to content

Commit 1a5d9f8

Browse files
committed
fix: use safe arithmetic assignment to avoid exit-on-zero
With set -euo pipefail, ((COUNTER++)) returns 0 when COUNTER is 0, causing the script to exit with error. Using COUNTER=$((COUNTER + 1)) is safe and always returns the new value. This bug would cause the script to fail on the first skip, even though skipping is valid behavior (e.g., backend plugins, missing metadata). Reported-by: kadel Ref: #2383 (comment)
1 parent 3232ef6 commit 1a5d9f8

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

scripts/instrument-plugin.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,22 @@ while IFS= read -r PROD_IMAGE; do
5656

5757
if [[ ! -f "$METADATA_FILE" ]]; then
5858
echo " ⚠️ No metadata file found at $METADATA_FILE - skipping"
59-
((SKIPPED_COUNT++))
59+
SKIPPED_COUNT=$((SKIPPED_COUNT + 1))
6060
continue
6161
fi
6262

6363
# Check if this is a frontend plugin (only frontend plugins need instrumentation)
6464
PLUGIN_ROLE=$(yq -r '.spec.backstage.role // ""' "$METADATA_FILE")
6565
if [[ "$PLUGIN_ROLE" != "frontend-plugin" ]]; then
6666
echo " Skipping $PLUGIN_ROLE (only frontend plugins need browser coverage)"
67-
((SKIPPED_COUNT++))
67+
SKIPPED_COUNT=$((SKIPPED_COUNT + 1))
6868
continue
6969
fi
7070

7171
# Pull production image first (needed to inspect labels)
7272
if ! podman pull "$PROD_IMAGE" 2>&1 | grep -v "WARNING: image platform"; then
7373
echo " ❌ Failed to pull image - skipping"
74-
((SKIPPED_COUNT++))
74+
SKIPPED_COUNT=$((SKIPPED_COUNT + 1))
7575
continue
7676
fi
7777

@@ -109,7 +109,7 @@ while IFS= read -r PROD_IMAGE; do
109109

110110
if [[ -z "$PLUGIN_PATH" ]]; then
111111
echo " ⚠️ Could not determine plugin path - skipping"
112-
((SKIPPED_COUNT++))
112+
SKIPPED_COUNT=$((SKIPPED_COUNT + 1))
113113
continue
114114
fi
115115

@@ -121,7 +121,7 @@ while IFS= read -r PROD_IMAGE; do
121121
echo " ❌ Failed to extract plugin bundle from container - skipping"
122122
podman rm "$CID" || true
123123
rm -rf "$WORK_DIR"
124-
((SKIPPED_COUNT++))
124+
SKIPPED_COUNT=$((SKIPPED_COUNT + 1))
125125
continue
126126
fi
127127

@@ -133,7 +133,7 @@ while IFS= read -r PROD_IMAGE; do
133133
if ! (cd "$WORK_DIR" && npx --yes nyc@18.0.0 instrument dist-original dist-instrumented --source-map); then
134134
echo " ❌ Instrumentation failed - skipping"
135135
rm -rf "$WORK_DIR"
136-
((SKIPPED_COUNT++))
136+
SKIPPED_COUNT=$((SKIPPED_COUNT + 1))
137137
continue
138138
fi
139139

@@ -142,7 +142,7 @@ while IFS= read -r PROD_IMAGE; do
142142
if [[ "$JS_COUNT" -eq 0 ]]; then
143143
echo " ❌ No __coverage__ found in instrumented files - skipping"
144144
rm -rf "$WORK_DIR"
145-
((SKIPPED_COUNT++))
145+
SKIPPED_COUNT=$((SKIPPED_COUNT + 1))
146146
continue
147147
fi
148148
echo " ✓ Instrumented $JS_COUNT JS files"
@@ -162,15 +162,15 @@ EOF
162162
if ! podman build -t "$COVERAGE_IMAGE" -f "$WORK_DIR/Containerfile" "$WORK_DIR"; then
163163
echo " ❌ Failed to build coverage image - skipping"
164164
rm -rf "$WORK_DIR"
165-
((SKIPPED_COUNT++))
165+
SKIPPED_COUNT=$((SKIPPED_COUNT + 1))
166166
continue
167167
fi
168168

169169
# Push coverage image
170170
if ! podman push "$COVERAGE_IMAGE"; then
171171
echo " ❌ Failed to push coverage image"
172172
rm -rf "$WORK_DIR"
173-
((SKIPPED_COUNT++))
173+
SKIPPED_COUNT=$((SKIPPED_COUNT + 1))
174174
continue
175175
fi
176176

@@ -180,7 +180,7 @@ EOF
180180
rm -rf "$WORK_DIR"
181181
echo ""
182182

183-
((INSTRUMENTED_COUNT++))
183+
INSTRUMENTED_COUNT=$((INSTRUMENTED_COUNT + 1))
184184

185185
done
186186

0 commit comments

Comments
 (0)