Skip to content
Snippets Groups Projects
Commit 711269e1 authored by Viktor Vorobev's avatar Viktor Vorobev
Browse files

Merged in NRRPLT-8635-scm-versioning (pull request #41)

NRRPLT-8635 scm versioning

Approved-by: Ugo Albanese
parent 90d63dd2
No related branches found
No related tags found
No related merge requests found
......@@ -6,31 +6,21 @@ set -x
whoami
env | sort
if [ -f .ci/env ]; then
# add quotes to all vars (but do it once)
sudo sed -i -E 's/="*(.*[^"])"*$/="\1"/' .ci/env
source '.ci/env'
fi
if [ -z ${PYTHON_VERSION_MAJOR_MINOR} ]; then
export PYTHON_VERSION_MAJOR=$(python -c "import sys; print(sys.version_info.major)")
export PYTHON_VERSION_MAJOR_MINOR=$(python -c "import sys; print('{}.{}'.format(sys.version_info.major, sys.version_info.minor))")
fi
# Force the build to happen in the build workspace, not in the container
# This should be done at the beginning, but there are some circular dependencies
# between Gazebo build artifacts (existing in the container) and nrp aliases/variables
# Force the build to happen in the build workspace
export HBP=$WORKSPACE
cd $WORKSPACE
export PYTHONPATH=
source ${USER_SCRIPTS_DIR}/nrp_variables
cd ${WORKSPACE}/${VIRTUAL_COACH_DIR}
# Configure build
export VIRTUAL_ENV_PATH=$VIRTUAL_ENV
export VIRTUAL_ENV_PATH="${VIRTUAL_ENV}"
export NRP_INSTALL_MODE=dev
export PYTHONPATH=hbp_nrp_virtual_coach:${VIRTUAL_ENV_PATH}/lib/python${PYTHON_VERSION_MAJOR_MINOR}/site-packages:$PYTHONPATH
......
......@@ -2,11 +2,8 @@
set -e
# Build package
git fetch --tags
PYNRP_VERSION=$(git describe --tags --always)
echo "${PYNRP_VERSION}"
echo "VERSION = \"${PYNRP_VERSION}\"" > hbp_nrp_virtual_coach/pynrp/version.py
export NRP_INSTALL_MODE=user
make set-nrp-version
pushd hbp_nrp_virtual_coach
python3 setup.py sdist bdist_wheel
......
......@@ -24,7 +24,6 @@ pipeline {
environment {
USER_SCRIPTS_DIR = "user-scripts"
ADMIN_SCRIPTS_DIR = "admin-scripts"
GAZEBO_ROS_DIR = "GazeboRosPackages"
VIRTUAL_COACH_DIR = "VirtualCoach"
// GIT_CHECKOUT_DIR is a dir of the main project (that was pushed)
GIT_CHECKOUT_DIR = "${env.VIRTUAL_COACH_DIR}"
......@@ -41,9 +40,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,28 +69,23 @@ 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}" ./'
}
// Clone all dependencies
cloneRepoTopic(env.USER_SCRIPTS_DIR, 'git@bitbucket.org:hbpneurorobotics/user-scripts.git', env.TOPIC_BRANCH, env.DEFAULT_BRANCH, '${USER}')
cloneRepoTopic(env.GAZEBO_ROS_DIR, 'git@bitbucket.org:hbpneurorobotics/gazeborospackages.git', env.TOPIC_BRANCH, env.DEFAULT_BRANCH, '${USER}')
cloneRepoTopic(env.ADMIN_SCRIPTS_DIR, 'git@bitbucket.org:hbpneurorobotics/admin-scripts.git', env.TOPIC_BRANCH, 'master', '${USER}')
}
}
stage('Build GazeboRosPackages') {
steps {
bitbucketStatusNotify(buildState: 'INPROGRESS', buildName: 'Building GazeboRosPackages')
// Use GazeboRosPackages build script
dir(env.GAZEBO_ROS_DIR){
// Determine explicitly the shell as bash (needed for proper user-scripts operation)
sh 'bash .ci/build.bash ${WORKSPACE}/${USER_SCRIPTS_DIR}/'
}
sh "git config --global --add safe.directory '*'"
}
}
......@@ -99,10 +95,7 @@ pipeline {
// Determine explicitly the shell as bash (needed for proper user-scripts operation)
dir(env.GIT_CHECKOUT_DIR){
// this is a workaround to pass all env vars into script run by the other user (now we are root)
sh 'env > .ci/env'
sh 'sudo -H -u bbpnrsoa bash .ci/build.bash'
sh 'bash .ci/build.bash'
// deliver artifacts
// Make true to false when the coverage reaches 85%-90%. This with turn off auto threshold for coverage
makeReports(true, env.CODE_COVERAGE_LINE)
......@@ -115,8 +108,8 @@ pipeline {
bitbucketStatusNotify(buildState: 'INPROGRESS', buildName: 'Building pynrp')
dir(env.GIT_CHECKOUT_DIR){
// tbuild package
sh 'bash ./.ci/whl-package.bash'
// build package
sh "export HBP=${WORKSPACE} && bash ./.ci/whl-package.bash"
// upload package
withCredentials([usernamePassword(credentialsId: 'nexusadmin', usernameVariable: 'USER', passwordVariable: 'PASSWORD')])
{
......
......@@ -18,7 +18,7 @@ PYTHON_PIP_VERSION?=pip>=19
python_version_full := $(shell python -c "import sys; maj, min = sys.version_info[:2]; print('{}.{}'.format(maj, min))" 2>&1)
ifeq ($(NRP_INSTALL_MODE),user)
include user_makefile
include $(HBP)/user-scripts/config_files/user_makefile
else
CI_REPO?=git@bitbucket.org:hbpneurorobotics/admin-scripts.git
CI_DIR?=$(HBP)/admin-scripts/ContinuousIntegration
......
......@@ -29,6 +29,7 @@ from future import standard_library
standard_library.install_aliases()
from builtins import object
from pynrp.virtual_coach import VirtualCoach
import pynrp.version
from unittest.mock import Mock, patch, MagicMock
import unittest
......@@ -149,6 +150,7 @@ class TestVirtualCoach(unittest.TestCase):
"sdf":"example_model_2.sdf",
"configPath":"example_model_2/model.config"}}
def test_init_asserts_no_password(self):
# invalid environment
self.assertRaises(AssertionError, VirtualCoach, environment=True)
......@@ -166,6 +168,14 @@ class TestVirtualCoach(unittest.TestCase):
def test_no_login_credentials(self):
self.assertRaises(Exception, VirtualCoach)
def test_version(self):
self.assertRegex(pynrp.version._get_version(), "^\d+.\d+.\d+")
self.assertRegex(pynrp.version.VERSION, "^\d+.\d+.\d+")
@patch('os.getenv', return_value="/non-existing-path")
def test_version_exception(self, mock_getenv):
self.assertRaises(RuntimeError, pynrp.version._get_version)
@patch('pynrp.virtual_coach.VirtualCoach._VirtualCoach__get_storage_token')
@patch('getpass.getpass', return_value='password')
......
'''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()
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment