From 82d4bfac75611c63c3c93b21bdec97e5537ce739 Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Fri, 5 May 2023 20:58:50 -0400 Subject: [PATCH] Make attach paths relative and upload the output contents Attach should be relative to CI_PROJECT_DIR --- .gitlab/templates.yml | 6 +++--- qa/tests/cli/conftest.py | 26 ++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/.gitlab/templates.yml b/.gitlab/templates.yml index 33e10ef0ab..db0a07df2f 100644 --- a/.gitlab/templates.yml +++ b/.gitlab/templates.yml @@ -27,13 +27,13 @@ - ctest -R qa_${TEST} # GitLab supports displaying the results in the GUI through JUNIT artifacts # (https://docs.gitlab.com/ee/ci/junit_test_reports.html) - # so we upload the JUNIT results. Note that there is a bug with how paths - # are processed in the junit report (https://gitlab.com/gitlab-org/gitlab/issues/23835) - # so we can't use a glob and have to list out each hierarchy separately. + # so we upload the JUNIT results. artifacts: when: always paths: - build/linux/qa/**/*.log + - build/linux/qa/**/output/* + - build/linux/qa/**/*.xml reports: junit: - build/linux/qa/**/*.xml \ No newline at end of file diff --git a/qa/tests/cli/conftest.py b/qa/tests/cli/conftest.py index 9a4212b64d..5db5792784 100644 --- a/qa/tests/cli/conftest.py +++ b/qa/tests/cli/conftest.py @@ -25,14 +25,25 @@ import os from pathlib import Path class KiTestFixture: + junit: bool = False + _output_path: Path = None + _junit_folder: Path = None + _ci_project_dir: Path = None + def __init__( self, config ) -> None: self._junit = False + + env_project_dir = os.getenv( 'CI_PROJECT_DIR' ) + if env_project_dir is not None: + self._ci_project_dir = Path( env_project_dir ) + junitxml = config.getoption("xmlpath") if junitxml is not None: p = Path( junitxml ) p = Path( p.parent ) # get the directory as junitxml points to a file p = p.resolve() # get absolute path + self._junit_folder = p self._junit = True else: p = Path.cwd() @@ -59,8 +70,19 @@ class KiTestFixture: def add_attachment( self, path: str ) -> None: """Prints the attachment message line for junit reports""" - if self._junit: - print( "[[ATTACHMENT|{}]]".format( path ) ) + if not self._junit: + return + + # Make the attachment path relative, gitlab in particular wants it + # relative tot he CI_PROJECT_DIR variable + attach_src_path = Path( path ) + attach_path: Path = None + if self._ci_project_dir is not None: + attach_path = attach_src_path.relative_to( self._ci_project_dir ) + else: + attach_path = attach_src_path.relative_to( self._junit_folder ) + + print( "[[ATTACHMENT|{}]]".format( str( attach_path ) ) ) @pytest.fixture