From d0068e4285bd736a497eb906abc27d3292d75152 Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Fri, 3 Jan 2025 18:06:01 +0100
Subject: [PATCH] Try to collect pytest artifacts

---
 .gitlab-ci.yml         |  5 +++++
 playbooks/ai3-test.yml | 27 ++++++++++++++++++++++++---
 test/Dockerfile        |  2 +-
 3 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 7a0e2501..6797e8f5 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -21,6 +21,7 @@ docker_build_and_release_tests:
     - if: '$CI_COMMIT_BRANCH != "master"'
       when: never
     - changes:
+        - test/Dockerfile
         - test/**/*
 
 .deploy_template:
@@ -91,6 +92,10 @@ docker_build_and_release_tests:
     - with-ssh-key env TESTDATA_DIR=$BUILD_DIR/testdata $BUILD_DIR/float/test-driver test $BUILD_DIR $PWD/playbooks/ai3-test.yml
   tags: [ai3]
   retry: 2
+  artifacts:
+    when: always
+    reports:
+      junit: ai3test.xml
   environment:
     name: review/$VMINE_TAG/$CI_COMMIT_REF_SLUG
     action: verify
diff --git a/playbooks/ai3-test.yml b/playbooks/ai3-test.yml
index 7ff65408..bedef537 100644
--- a/playbooks/ai3-test.yml
+++ b/playbooks/ai3-test.yml
@@ -9,10 +9,31 @@
         dest: /tmp/test-config.yml
         content: "{{ vars|to_nice_yaml }}"
 
-    - name: Setup test Docker image
-      command: "float-pull-image registry.git.autistici.org/ai3/config:integration-test"
+    - name: Create test artifact directory
+      file:
+        path: "/artifacts"
+        state: directory
+        mode: "01777"
+
+    - name: Pull the test suite container image
+      command: "float-pull-image {{ test_image }}"
       register: test_container_image
       failed_when: "test_container_image.rc not in [0, 42]"
 
     - name: Run tests
-      command: "docker run --rm --net host --mount type=bind,source=/tmp/test-config.yml,destination=/test-config.yml registry.git.autistici.org/ai3/config:integration-test"
+      command: "podman run --rm --net host --mount type=bind,source=/tmp/test-config.yml,destination=/test-config.yml --mount type=bind,source=/artifacts,destination=/artifacts {{ test_image }}"
+
+    - name: Retrieve test result
+      slurp:
+        src: "/artifacts/ai3test.xml"
+      register: ai3test_xml
+
+    - name: Store test results locally
+      local_action:
+        module: copy
+        dest: "ai3test.xml"
+        content: "{{ ai3test_xml['content'] | b64decode }}"
+
+  vars:
+    test_image: "registry.git.autistici.org/ai3/config:integration-test"
+
diff --git a/test/Dockerfile b/test/Dockerfile
index e615d056..89c135f5 100644
--- a/test/Dockerfile
+++ b/test/Dockerfile
@@ -6,4 +6,4 @@ RUN python3 setup.py install
 
 ENV TEST_CONFIG=/test-config.yml
 ENV PYTHONPATH=/src
-CMD ["nosetests3", "-v", "ai3test"]
+CMD ["pytest", "-v", "--junitxml=/artifacts/ai3test.xml", "ai3test"]
-- 
GitLab