From 57d23d6d7ef72645b8aff2fd399056bae669aa50 Mon Sep 17 00:00:00 2001 From: Viktor Vorobev <vorobev@in.tum.de> Date: Fri, 23 Sep 2022 10:46:28 +0000 Subject: [PATCH] Merged in NRRPLT-8635-scm-versioning (pull request #35) NRRPLT-8635 scm versioning Approved-by: Ugo Albanese Approved-by: Vahid Zolfaghari --- Jenkinsfile | 20 +++++++++++++++---- .../tests/test_version.py | 20 +++++++++++++++++++ .../hbp_nrp_distributed_nest/version.py | 20 +++++++++++++++++-- 3 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 hbp_nrp_distributed_nest/hbp_nrp_distributed_nest/tests/test_version.py diff --git a/Jenkinsfile b/Jenkinsfile index 33f2019..dc68312 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -42,8 +42,11 @@ pipeline { agent { docker { label 'ci_label' + alwaysPull true // NEXUS_REGISTRY_IP and NEXUS_REGISTRY_PORT are Jenkins global variables - image "${env.NEXUS_REGISTRY_IP}:${env.NEXUS_REGISTRY_PORT}/nrp:${IMG_TAG}" + registryUrl "https://${env.NEXUS_REGISTRY_IP}:${env.NEXUS_REGISTRY_PORT}" + registryCredentialsId 'nexusadmin' + image "nrp:${IMG_TAG}" args '--entrypoint="" -u root --privileged' } } @@ -68,7 +71,15 @@ pipeline { // Checkout main project to GIT_CHECKOUT_DIR dir(env.GIT_CHECKOUT_DIR) { - checkout scm + checkout([ + $class: "GitSCM", + branches: scm.branches, + extensions: [ + [$class: 'CloneOption', noTags: false], + [$class: 'LocalBranch', localBranch: "**"] + ], + userRemoteConfigs: scm.userRemoteConfigs + ]) sh 'chown -R "${USER}" ./' } @@ -84,8 +95,9 @@ pipeline { cloneRepoTopic(env.GAZEBO_ROS_DIR, 'git@bitbucket.org:hbpneurorobotics/gazeborospackages.git', env.TOPIC_BRANCH, env.DEFAULT_BRANCH, '${USER}') cloneRepoTopic(env.EXP_CONTROL_DIR, 'git@bitbucket.org:hbpneurorobotics/experimentcontrol.git', env.TOPIC_BRANCH, env.DEFAULT_BRANCH, '${USER}') cloneRepoTopic(env.CLE_DIR, 'git@bitbucket.org:hbpneurorobotics/cle.git', env.TOPIC_BRANCH, env.DEFAULT_BRANCH, '${USER}') - cloneRepoTopic(env.EXDBACKEND_DIR, 'git@bitbucket.org:hbpneurorobotics/exdbackend.git', env.TOPIC_BRANCH, env.DEFAULT_BRANCH, '${USER}') - + cloneRepoTopic(env.EXDBACKEND_DIR, 'git@bitbucket.org:hbpneurorobotics/exdbackend.git', env.TOPIC_BRANCH, env.DEFAULT_BRANCH, '${USER}') + + sh "git config --global --add safe.directory '*'" } } diff --git a/hbp_nrp_distributed_nest/hbp_nrp_distributed_nest/tests/test_version.py b/hbp_nrp_distributed_nest/hbp_nrp_distributed_nest/tests/test_version.py new file mode 100644 index 0000000..c460981 --- /dev/null +++ b/hbp_nrp_distributed_nest/hbp_nrp_distributed_nest/tests/test_version.py @@ -0,0 +1,20 @@ +""" +Unit tests for testing the version value +""" + +import unittest +import hbp_nrp_distributed_nest.version +from unittest.mock import patch + +__author__ = "Viktor Vorobev" + + +class TestVersion(unittest.TestCase): + + def test_version(self): + self.assertRegex(hbp_nrp_distributed_nest.version._get_version(), "^\d+.\d+.\d+") + self.assertRegex(hbp_nrp_distributed_nest.version.VERSION, "^\d+.\d+.\d+") + + @patch('os.getenv', return_value="/non-existing-path") + def test_version_exception(self, mock_getenv): + self.assertRaises(RuntimeError, hbp_nrp_distributed_nest.version._get_version) diff --git a/hbp_nrp_distributed_nest/hbp_nrp_distributed_nest/version.py b/hbp_nrp_distributed_nest/hbp_nrp_distributed_nest/version.py index d5d3104..006613b 100644 --- a/hbp_nrp_distributed_nest/hbp_nrp_distributed_nest/version.py +++ b/hbp_nrp_distributed_nest/hbp_nrp_distributed_nest/version.py @@ -1,2 +1,18 @@ -'''version string - generated by setVersion.sh''' -VERSION = '3.2.1' +'''version string - automatically calculated from the SCM (git)''' +import subprocess +import os +from subprocess import CalledProcessError + +def _get_version(): + try: + version = subprocess.run(['bash', + f'{os.getenv("HBP")}/user-scripts/nrp_get_scm_version.sh', + 'get_scm_version'], + stdout=subprocess.PIPE, check=True).stdout.decode('utf-8') + except CalledProcessError as e: + raise RuntimeError("The SCM version calculation script failed.\ + Expected path: $HBP/user-scripts/nrp_get_scm_version.sh,\ + check its existance.") from e + return version + +VERSION = _get_version() -- GitLab