From bada623d69b920ab1fafdfb5d6f5d3ec33c8c11e Mon Sep 17 00:00:00 2001 From: Viktor Vorobev <vorobev@in.tum.de> Date: Thu, 21 Jan 2021 10:54:03 +0000 Subject: [PATCH] Merged in NRRPLT-8128-test-coverage-update-py3.8 (pull request #26) [NRRPLT-8128] Test coverage update Python 3.8 * [NRRPLT-8127] make reports with function * [NRRPLT-8127] setup manual coverage line * [NRRPLT-0000] docstrings and pylint fix for ci directory download python script Approved-by: Vahid Zolfaghari Approved-by: Krzysztof Lebioda --- .ci/ci_download_directory.py | 56 +++++++++++++++++++++++------------- Jenkinsfile | 19 ++---------- 2 files changed, 39 insertions(+), 36 deletions(-) diff --git a/.ci/ci_download_directory.py b/.ci/ci_download_directory.py index 4c3b0a8..4568c8c 100644 --- a/.ci/ci_download_directory.py +++ b/.ci/ci_download_directory.py @@ -1,4 +1,9 @@ #!/usr/bin/env python +""" +CI script for checkout of a single directory from a specified repo ref HEAD +This script uses BitBucket API, so the repo is supposed to be in BitBucket cloud +""" + import os import sys from urllib.parse import urlparse @@ -6,18 +11,26 @@ import urllib.request try: import json -except: +except ImportError: import simplejson as json -def open_directory(API_PATH, username, repo, slug, path): - directory_url = "%s/%s/%s/src/%s/%s" % (API_PATH, username, repo, slug, path) +def open_directory(api_path_, user_name_, repository_, slug_, path_): + """ + open_directory opens directory and recursevely downloads its content throug BitBucket API + :param api_path_: path to BitBucket API core (https://api.bitbucket.org/2.0/repositories) + :param user_name_: BitBucket username (hbpneurorobotics) + :param repository_: the desired repo to download (i.e. CLE) + :param slug_: the desired ref (branch/tag/hash) + :param path_: the path to the directory inside repository + """ + directory_url = "%s/%s/%s/src/%s/%s" % (api_path_, user_name_, repository_, slug_, path_) print(directory_url) json_data_url_handle = urllib.request.urlopen(directory_url) if json_data_url_handle.code != 200: print("url %s not found" % directory_url) - exit() + sys.exit() json_directory = json.loads(json_data_url_handle.read()) page_exists = True @@ -26,35 +39,38 @@ def open_directory(API_PATH, username, repo, slug, path): for item in json_directory["values"]: print(json.dumps(item, indent=4)) if item["type"] == "commit_directory": - open_directory(API_PATH, username, repo, slug, item["path"]) + open_directory(api_path_, user_name_, repository_, slug_, item["path"]) - for file in json_directory["values"]: - if file["type"] == "commit_file" and file["mimetype"] == "text/xml": + for file_ in json_directory["values"]: + if file_["type"] == "commit_file" and file_["mimetype"] == "text/xml": try: - os.makedirs(os.path.dirname(file["path"])) + os.makedirs(os.path.dirname(file_["path"])) except OSError: - None - print("downloading %s" % file["path"]) - print(file['links']['self']['href']) - urllib.request.urlretrieve(file['links']['self']['href'], file['path']) + pass + print("downloading %s" % file_["path"]) + print(file_['links']['self']['href']) + urllib.request.urlretrieve(file_['links']['self']['href'], file_['path']) if "next" in json_directory: json_data_url_handle = urllib.request.urlopen(json_directory['next']) if json_data_url_handle.code != 200: print("url %s not found" % directory_url) - exit() + sys.exit() json_directory = json.loads(json_data_url_handle.read()) else: page_exists = False + if ( - len(sys.argv) != 2 or - sys.argv[1].find("https://bitbucket.org/") != 0 or - sys.argv[1].find("/src/") == -1 + len(sys.argv) != 2 or + sys.argv[1].find("https://bitbucket.org/") != 0 or + sys.argv[1].find("/src/") == -1 ): print("usage: python download_directory.py.py https://bitbucket.org/ws/repo/src/branch/demo/") - exit() + sys.exit() API_PATH = "https://api.bitbucket.org/2.0/repositories" -null, username, repo, null, slug, path = urlparse(sys.argv[1]).path.split("/", 5) -print(username, repo, slug, path) -open_directory(API_PATH, username, repo, slug, path) +_, username, repo, _, slug, path_section = urlparse(sys.argv[1]).path.split("/", 5) + +print(username, repo, slug, path_section) + +open_directory(API_PATH, username, repo, slug, path_section) diff --git a/Jenkinsfile b/Jenkinsfile index 6269960..37bb808 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -29,8 +29,7 @@ pipeline { TOPIC_BRANCH = selectTopicBranch(env.BRANCH_NAME, env.CHANGE_BRANCH) DEFAULT_BRANCH = 'development' - NRP_COVERAGE_BRANCH=0 - NRP_COVERAGE_LINE=23 + CODE_COVERAGE_LINE = 29 } agent { docker { @@ -106,18 +105,7 @@ pipeline { sh 'sudo -H -u bbpnrsoa bash .ci/build.bash' // deliver artifacts - step([$class: 'CoberturaPublisher', - autoUpdateHealth: true, - autoUpdateStability: false, - coberturaReportFile: 'coverage.xml', - failUnhealthy: true, - failUnstable: false, - maxNumberOfBuilds: 0, - onlyStable: false, - sourceEncoding: 'ASCII', - zoomCoverageChart: false, - lineCoverageTargets: "0.0, 0, 0"]) - archiveArtifacts 'coverage.xml' + makeReports(false, env.CODE_COVERAGE_LINE) } } } @@ -128,8 +116,7 @@ pipeline { dir(env.GIT_CHECKOUT_DIR){ archiveArtifacts 'p*.*' archiveArtifacts 'test-reports/*.*' - junit 'test-reports/*.xml' - recordIssues enabledForFailure: true, tools: [pyLint(pattern: 'pylint.txt'), pep8(pattern: 'pycodestyle.txt')], qualityGates: [[threshold: 1, type: 'TOTAL', unstable: true]] + archiveArtifacts 'coverage.xml' } } aborted { -- GitLab