Skip to content

Commit 03dae6a

Browse files
committed
Stabilize compare-baseline exit handling in CI
1 parent 6c49be6 commit 03dae6a

1 file changed

Lines changed: 69 additions & 6 deletions

File tree

.github/workflows/build-ultraplot.yml

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,31 +221,94 @@ jobs:
221221
echo "No valid nodeids found on PR branch; skipping image comparison."
222222
exit 0
223223
else
224+
status=0
224225
echo "=== Memory before image comparison ===" && free -h
226+
set +e
225227
pytest -n ${PYTEST_WORKERS} --dist loadfile --tb=short --disable-warnings -W ignore \
226-
--mpl \
227-
--mpl-baseline-path=./ultraplot/tests/baseline \
228-
--mpl-results-path=./results/ \
229-
--mpl-generate-summary=html \
230-
--mpl-default-style="./ultraplot.yml" \
231-
"${FILTERED_NODEIDS[@]}" || status=$?
228+
--mpl \
229+
--mpl-baseline-path=./ultraplot/tests/baseline \
230+
--mpl-results-path=./results/ \
231+
--mpl-generate-summary=html \
232+
--mpl-default-style="./ultraplot.yml" \
233+
--junitxml=./results/junit.xml \
234+
"${FILTERED_NODEIDS[@]}"
235+
status=$?
236+
set -e
232237
echo "=== Memory after image comparison ===" && free -h
238+
if [ "$status" -ne 0 ] && [ -f ./results/junit.xml ]; then
239+
if python - <<'PY'
240+
import sys
241+
import xml.etree.ElementTree as ET
242+
try:
243+
root = ET.parse("./results/junit.xml").getroot()
244+
except Exception:
245+
sys.exit(1)
246+
if root.tag == "testsuites":
247+
suites = list(root.findall("testsuite"))
248+
else:
249+
suites = [root]
250+
failures = 0
251+
errors = 0
252+
for suite in suites:
253+
failures += int(suite.attrib.get("failures", 0) or 0)
254+
errors += int(suite.attrib.get("errors", 0) or 0)
255+
sys.exit(0 if (failures == 0 and errors == 0) else 1)
256+
PY
257+
then
258+
echo "pytest exited with $status but junit reports no failures/errors; overriding exit status to 0."
259+
status=0
260+
fi
261+
fi
233262
if [ "$status" -eq 4 ] || [ "$status" -eq 5 ]; then
234263
echo "No tests collected from selected nodeids; skipping image comparison."
235264
status=0
236265
fi
237266
fi
238267
exit "$status"
239268
else
269+
status=0
240270
echo "=== Memory before image comparison ===" && free -h
271+
set +e
241272
pytest -n ${PYTEST_WORKERS} --dist loadfile --tb=short --disable-warnings -W ignore \
242273
--mpl \
243274
--mpl-baseline-path=./ultraplot/tests/baseline \
244275
--mpl-results-path=./results/ \
245276
--mpl-generate-summary=html \
246277
--mpl-default-style="./ultraplot.yml" \
278+
--junitxml=./results/junit.xml \
247279
ultraplot/tests
280+
status=$?
281+
set -e
248282
echo "=== Memory after image comparison ===" && free -h
283+
if [ "$status" -ne 0 ] && [ -f ./results/junit.xml ]; then
284+
if python - <<'PY'
285+
import sys
286+
import xml.etree.ElementTree as ET
287+
try:
288+
root = ET.parse("./results/junit.xml").getroot()
289+
except Exception:
290+
sys.exit(1)
291+
if root.tag == "testsuites":
292+
suites = list(root.findall("testsuite"))
293+
else:
294+
suites = [root]
295+
failures = 0
296+
errors = 0
297+
for suite in suites:
298+
failures += int(suite.attrib.get("failures", 0) or 0)
299+
errors += int(suite.attrib.get("errors", 0) or 0)
300+
sys.exit(0 if (failures == 0 and errors == 0) else 1)
301+
PY
302+
then
303+
echo "pytest exited with $status but junit reports no failures/errors; overriding exit status to 0."
304+
status=0
305+
fi
306+
fi
307+
if [ "$status" -eq 4 ] || [ "$status" -eq 5 ]; then
308+
echo "No tests collected; skipping image comparison."
309+
status=0
310+
fi
311+
exit "$status"
249312
fi
250313

251314
# Return the html output of the comparison even if failed

0 commit comments

Comments
 (0)