From dfd6097f7bb573dfa9e713149d33e6d9b92e3e99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20Bal=C3=A1=C5=BEik?= Date: Wed, 4 Jun 2025 14:41:35 +0200 Subject: [PATCH] Add a check for existence and sanity of the junit.xml file And use if after system tests are run using pytest. --- .gitlab-ci.yml | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index dff20918b5..e006364fa9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -311,6 +311,21 @@ stages: .fips-feature-test: &fips_feature_test - if build/feature-test --have-fips-mode; then fips-mode-setup --check; fips-mode-setup --is-enabled; fi +.check_for_junit_xml: &check_for_junit_xml + # test if junit.xml file exists and is longer 40 bytes + # (i.e., contains more than ``) + - if [ -f "$CI_PROJECT_DIR"/junit.xml ]; then + if [ $(wc -c < "$CI_PROJECT_DIR"/junit.xml) -gt 40 ]; then + echo "junit.xml file exists and is longer than 40 bytes."; + else + echo "junit.xml file exists but is too short."; + exit 1; + fi + else + echo "junit.xml file does not exist."; + exit 1; + fi + .build: &build_job <<: *default_triggering_rules stage: build @@ -394,14 +409,23 @@ stages: stage: system before_script: - *setup_interfaces + # This script needs to: 1) fail if the system tests fail, 2) fail if + # the junit.xml file is broken, 3) produce the junit.xml file even if + # the system tests fail. Therefore, $RET is used to "cache" the + # result of running pytest as interrupting the script immediately when + # system tests fail would make checking the contents of the junit.xml + # file impossible (GitLab Runner uses "set -o pipefail"). script: - *fips_feature_test - *find_pytest - *find_python - ( if [ "${CI_DISPOSABLE_ENVIRONMENT}" = "true" ]; then sleep 3000; "$PYTHON" "${CI_PROJECT_DIR}/util/get-running-system-tests.py"; fi ) & - cd bin/tests/system + - RET=0 - > - "$PYTEST" --junit-xml="$CI_PROJECT_DIR"/junit.xml -n "$TEST_PARALLEL_JOBS" | tee pytest.out.txt + ("$PYTEST" --junit-xml="$CI_PROJECT_DIR"/junit.xml -n "$TEST_PARALLEL_JOBS" | tee pytest.out.txt) || RET=1 + - *check_for_junit_xml + - (exit $RET) - '( ! grep -F "grep: warning:" pytest.out.txt )' - test "$CLEAN_BUILD_ARTIFACTS_ON_SUCCESS" -eq 0 || ( cd ../../.. && ninja -C build clean >/dev/null 2>&1 ) after_script: