Skip to content

Commit 9ed5d16

Browse files
bash review
1 parent bdd6612 commit 9ed5d16

1 file changed

Lines changed: 23 additions & 15 deletions

File tree

configuration/steps/commands/scripts/mtr_reporter.sh

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,38 @@ PLATFORM="$4"
1010
BBNUM="$5"
1111
DIR="$6" # Directory containing .xml files
1212

13+
err() {
14+
set +x
15+
echo >&2 "ERROR: $*"
16+
exit 1
17+
}
18+
19+
bb_log_info() {
20+
set +x
21+
echo >&1 "INFO: $*"
22+
set -x
23+
}
24+
1325
UPLOAD_URL="${BASE_URL}/upload-test-results/"
1426
HEALTH_URL="${BASE_URL}/health"
1527

1628
# Step 1: Health check before uploads
17-
echo "Checking service health at $HEALTH_URL..."
29+
command -v curl >/dev/null || err "curl not found"
30+
bb_log_info "Checking service health at $HEALTH_URL..."
1831
if ! curl "$HEALTH_URL" \
1932
--max-time 5 \
2033
--retry 3 \
2134
--retry-max-time 0 \
2235
--retry-delay 5 \
2336
--retry-connrefused \
2437
--fail-with-body; then
25-
echo "Service health check failed. Aborting uploads."
26-
exit 1
38+
err "Service health check failed. Aborting uploads."
2739
fi
28-
echo "Service is healthy. Proceeding with uploads."
40+
bb_log_info "Service is healthy. Proceeding with uploads."
2941

3042
# Step 2: Validate directory
3143
if [[ ! -d "$DIR" ]]; then
32-
echo "Error: directory '$DIR' does not exist"
33-
exit 1
44+
err "Error: directory '$DIR' does not exist"
3445
fi
3546

3647
# Step 3: Find XML files
@@ -39,8 +50,7 @@ XML_FILES=("$DIR"/*.xml)
3950
shopt -u nullglob
4051

4152
if [[ ${#XML_FILES[@]} -eq 0 ]]; then
42-
echo "Error: no .xml files found in directory '$DIR'"
43-
exit 1
53+
err "Error: no .xml files found in directory '$DIR'"
4454
fi
4555

4656
# Step 4: Upload files and track failures
@@ -49,7 +59,7 @@ ANY_FAILED=0
4959
for FILE in "${XML_FILES[@]}"; do
5060
# Extract filename without extension for 'typ'
5161
BASENAME="$(basename "$FILE" .xml)"
52-
echo "Uploading $FILE (typ=$BASENAME)..."
62+
bb_log_info "Uploading $FILE (typ=$BASENAME)..."
5363

5464
if ! curl --max-time 120 --connect-timeout 10 --fail-with-body \
5565
-X POST "$UPLOAD_URL" \
@@ -59,18 +69,16 @@ for FILE in "${XML_FILES[@]}"; do
5969
-F "bbnum=${BBNUM}" \
6070
-F "typ=${BASENAME}" \
6171
-F "file=@${FILE};type=application/xml"; then
62-
echo "Upload failed for $FILE"
72+
bb_log_info "Upload failed for $FILE"
6373
ANY_FAILED=1
6474
else
65-
echo "Upload succeeded for $FILE"
75+
bb_log_info "Upload succeeded for $FILE"
6676
fi
6777
done
6878

6979
# Step 5: Final result
7080
if [[ $ANY_FAILED -ne 0 ]]; then
71-
echo "One or more uploads failed."
72-
exit 1
81+
err "One or more uploads failed."
7382
else
74-
echo "All uploads succeeded."
75-
exit 0
83+
bb_log_info "All uploads succeeded."
7684
fi

0 commit comments

Comments
 (0)