]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add a check for existence and sanity of the junit.xml file
authorŠtěpán Balážik <stepan@isc.org>
Wed, 4 Jun 2025 12:41:35 +0000 (14:41 +0200)
committerŠtěpán Balážik <stepan@isc.org>
Thu, 26 Jun 2025 13:14:06 +0000 (15:14 +0200)
And use if after system tests are run using pytest.

(cherry picked from commit dfd6097f7bb573dfa9e713149d33e6d9b92e3e99)

.gitlab-ci.yml

index e553988d2cad4e1da243a1bc644b4e5c327800fe..6bc8630a192bac691c36f9622d5707551d62344e 100644 (file)
@@ -334,6 +334,21 @@ stages:
 .fips-feature-test: &fips_feature_test
     - if bin/tests/system/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 `<testsuites><testsuite /></testsuites>`)
+    - 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
@@ -421,14 +436,23 @@ stages:
   before_script:
     - test -n "${OUT_OF_TREE_WORKSPACE}" && cp -r bin/tests/system/* "${OUT_OF_TREE_WORKSPACE}/bin/tests/system/" && cd "${OUT_OF_TREE_WORKSPACE}"
     - *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 ../../.. && make clean >/dev/null 2>&1 )
   after_script: