From 49a632ad48a860349f2de07d80a0f0099873c30b Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Tue, 24 Jul 2018 20:41:38 -0400 Subject: [PATCH] ci: Publish test reports --- .gitlab-ci.yml | 14 +++- scripts/update_test_results | 123 ++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+), 1 deletion(-) create mode 100755 scripts/update_test_results diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 59f550c1f..1048e98d4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,6 +5,9 @@ build: cache: paths: - .flatpak-builder + artifacts: + paths: + - xunit.xml script: - ls -a - export @@ -12,4 +15,13 @@ build: - flatpak-builder --force-clean app build/flatpak/org.pitivi.Pitivi.json --ccache - flatpak-builder --run app build/flatpak/org.pitivi.Pitivi.json meson mesonbuild/ - flatpak-builder --run app build/flatpak/org.pitivi.Pitivi.json ninja -C mesonbuild/ - - xvfb-run -n 32 -s "-screen 0 640x480x24" flatpak-builder --env=PITIVI_DEVELOPMENT=1 --run app build/flatpak/org.pitivi.Pitivi.json gst-validate-launcher $PWD/tests/ptv_testsuite.py --dump-on-failure --timeout-factor 4 + - xvfb-run -n 32 -s "-screen 0 640x480x24" flatpak-builder --env=PITIVI_DEVELOPMENT=1 --run app build/flatpak/org.pitivi.Pitivi.json gst-validate-launcher $PWD/tests/ptv_testsuite.py --dump-on-failure --timeout-factor 4 --xunit-file xunit.xml + +test-results: + artifacts: + paths: + - test-results + dependencies: + - build + stage: deploy-test-results + - scripts/update_test_results \ No newline at end of file diff --git a/scripts/update_test_results b/scripts/update_test_results new file mode 100755 index 000000000..2a85cc723 --- /dev/null +++ b/scripts/update_test_results @@ -0,0 +1,123 @@ +#!/usr/bin/env python3 + +# -*- coding: utf-8 -*- +# Pitivi video editor test results. +# Copyright (c) 2018, Thibault Saunier +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this program; if not, write to the +# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, +# Boston, MA 02110-1301, USA. +""" +Script to update test results in gitlab-ci. +""" +import argparse +import os +import stat +import subprocess +import tempfile +import zipfile + +from urllib.request import urlretrieve +from urllib.error import HTTPError + +DIR = os.path.realpath(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) +def get_zip(url, out_dir): + """Bannanna.""" + last_message_length = 0 + + def sizeof_fmt(num, suffix='B'): + for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']: + if abs(num) < 1024.0: + return "%3.1f%s%s" % (num, unit, suffix) + num /= 1024.0 + return "%.1f%s%s" % (num, 'Yi', suffix) + + def message(string): + nonlocal last_message_length + print('\r' + string + ' ' * max(0, last_message_length - len(string)), end='') + last_message_length = len(string) + + def reporthook(blocknum, blocksize, totalsize): + readsofar = blocknum * blocksize + if totalsize > 0: + percent = readsofar * 1e2 / totalsize + msg = "\r%s —%5.1f%% %s / %s" % ( + url, percent, sizeof_fmt(readsofar), sizeof_fmt(totalsize)) \ + + ' ' * 50 + message(msg) + else: # total size is unknown + message("read %d" % (readsofar,)) + + with tempfile.NamedTemporaryFile() as ziped_file: + print("-> Downloading Allure.") + try: + urlretrieve(url, ziped_file.name, reporthook) + except: + print("\nCould not retrieve %s" % url) + raise + print("\n-> Extracting.") + zip_ref = zipfile.ZipFile(ziped_file.name, 'r') + zip_ref.extractall(out_dir) + zip_ref.close() + +def get_allure(): + """Download allure.""" + allure_version = "allure-2.7.0" + + allure_path = os.path.join(DIR, allure_version, 'bin', 'allure') + if os.path.exists(allure_path): + return allure_path + + # pylint: disable=line-too-long + get_zip("https://bintray.com/qameta/generic/download_file?file_path=io%2Fqameta%2Fallure%2Fallure%2F2.7.0%2Fallure-2.7.0.zip", DIR) + + st = os.stat(allure_path) + os.chmod(allure_path, st.st_mode | stat.S_IEXEC) + + return allure_path + + +def get_history(ref): + """Get latest test results.""" + try: + get_zip("https://gitlab.gnome.org/GNOME/pitivi/-/jobs/artifacts/%s/download?job=deploy-test-results" % ref, DIR) + except HTTPError: + return None + os.rename(os.path.join(DIR, "test-results"), os.path.join(DIR, "history")) + + return os.path.join(DIR, "history") + + +def main(): + """Run the script.""" + parser = argparse.ArgumentParser() + parser.add_argument('results_dir', nargs=1, default=None, + help='The directory in which to find results') + parser.add_argument('--build-url', default="No build URL provided", + help='The url where to find full build informations.') + + options = parser.parse_args() + + allure = get_allure() + history = get_history(os.environ.get('CI_COMMIT_REF_NAME', 'master')) + results_dir = os.path.join(DIR, "test-results") + + command = [allure, "generate", "--clean", "--output", results_dir] + if history: + command.append(history) + + subprocess.check_call(command + options.results_dir) + +if __name__ == "__main__": + main() -- GitLab