Skip to content

Commit 3d44246

Browse files
committed
Harden compare-baseline status normalization logic
1 parent 16e20d0 commit 3d44246

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

.github/workflows/build-ultraplot.yml

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,18 @@ jobs:
235235
status=$?
236236
set -e
237237
echo "=== Memory after image comparison ===" && free -h
238-
if [ "$status" -ne 0 ] && [ -f ./results/junit.xml ]; then
239-
if python -c "import sys, xml.etree.ElementTree as ET; root = ET.parse('./results/junit.xml').getroot(); suites = list(root.findall('testsuite')) if root.tag == 'testsuites' else [root]; failures = sum(int(s.attrib.get('failures', 0) or 0) for s in suites); errors = sum(int(s.attrib.get('errors', 0) or 0) for s in suites); sys.exit(0 if (failures == 0 and errors == 0) else 1)"
240-
then
241-
echo "pytest exited with $status but junit reports no failures/errors; overriding exit status to 0."
242-
status=0
243-
fi
238+
junit_failures=-1
239+
junit_errors=-1
240+
if [ -f ./results/junit.xml ]; then
241+
junit_failures=$(sed -n 's/.*failures="\([0-9][0-9]*\)".*/\1/p' ./results/junit.xml | head -n 1)
242+
junit_errors=$(sed -n 's/.*errors="\([0-9][0-9]*\)".*/\1/p' ./results/junit.xml | head -n 1)
243+
junit_failures=${junit_failures:-0}
244+
junit_errors=${junit_errors:-0}
245+
fi
246+
echo "pytest_status=$status junit_failures=$junit_failures junit_errors=$junit_errors"
247+
if [ "$status" -ne 0 ] && [ "$junit_failures" -eq 0 ] && [ "$junit_errors" -eq 0 ]; then
248+
echo "pytest exited with $status but junit reports no failures/errors; overriding exit status to 0."
249+
status=0
244250
fi
245251
if [ "$status" -eq 4 ] || [ "$status" -eq 5 ]; then
246252
echo "No tests collected from selected nodeids; skipping image comparison."
@@ -263,12 +269,18 @@ jobs:
263269
status=$?
264270
set -e
265271
echo "=== Memory after image comparison ===" && free -h
266-
if [ "$status" -ne 0 ] && [ -f ./results/junit.xml ]; then
267-
if python -c "import sys, xml.etree.ElementTree as ET; root = ET.parse('./results/junit.xml').getroot(); suites = list(root.findall('testsuite')) if root.tag == 'testsuites' else [root]; failures = sum(int(s.attrib.get('failures', 0) or 0) for s in suites); errors = sum(int(s.attrib.get('errors', 0) or 0) for s in suites); sys.exit(0 if (failures == 0 and errors == 0) else 1)"
268-
then
269-
echo "pytest exited with $status but junit reports no failures/errors; overriding exit status to 0."
270-
status=0
271-
fi
272+
junit_failures=-1
273+
junit_errors=-1
274+
if [ -f ./results/junit.xml ]; then
275+
junit_failures=$(sed -n 's/.*failures="\([0-9][0-9]*\)".*/\1/p' ./results/junit.xml | head -n 1)
276+
junit_errors=$(sed -n 's/.*errors="\([0-9][0-9]*\)".*/\1/p' ./results/junit.xml | head -n 1)
277+
junit_failures=${junit_failures:-0}
278+
junit_errors=${junit_errors:-0}
279+
fi
280+
echo "pytest_status=$status junit_failures=$junit_failures junit_errors=$junit_errors"
281+
if [ "$status" -ne 0 ] && [ "$junit_failures" -eq 0 ] && [ "$junit_errors" -eq 0 ]; then
282+
echo "pytest exited with $status but junit reports no failures/errors; overriding exit status to 0."
283+
status=0
272284
fi
273285
if [ "$status" -eq 4 ] || [ "$status" -eq 5 ]; then
274286
echo "No tests collected; skipping image comparison."

0 commit comments

Comments
 (0)