diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 89d533e50ec3edaf1b3916b80bebdb35ddf9eae8..68385d721400a095fa64173b8eb5903844be6f58 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,45 +1,206 @@ -# This file is a template, and might need editing before it works on your project. -# To contribute improvements to CI/CD templates, please follow the Development guide at: -# https://docs.gitlab.com/ee/development/cicd/templates.html -# This specific template is located at: -# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Getting-Started.gitlab-ci.yml - -# This is a sample GitLab CI/CD configuration file that should run without any modifications. -# It demonstrates a basic 3 stage CI/CD pipeline. Instead of real tests or scripts, -# it uses echo commands to simulate the pipeline execution. -# -# A pipeline is composed of independent jobs that run scripts, grouped into stages. -# Stages run in sequential order, but jobs within stages run in parallel. -# -# For more information, see: https://docs.gitlab.com/ee/ci/yaml/index.html#stages - -stages: # List of stages for jobs, and their order of execution - - build - - test - - deploy - -build-job: # This job runs in the build stage, which runs first. - stage: build - script: - - echo "Compiling the code..." - - echo "Compile complete." +stages: + - demo -unit-test-job: # This job runs in the test stage. - stage: test # It only starts when the job in the build stage completes successfully. - script: - - echo "Running unit tests... This will take about 60 seconds." - - sleep 60 - - echo "Code coverage is 90%" +############ YAML ANCHORS ############ +.preliminaries_template: &preliminaries_definition + ## Install ssh-agent if not already installed, it is required by Docker. + ## (change apt-get to yum if you use an RPM-based image) + - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )' + + ## Run ssh-agent (inside the build environment) + - eval $(ssh-agent -s) + + ## Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store + ## We're using tr to fix line endings which makes ed25519 keys work + ## without extra base64 encoding. + ## https://gitlab.com/gitlab-examples/ssh-private-key/issues/1#note_48526556 + - mkdir -p ~/.ssh + - chmod 700 ~/.ssh + - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null + # - echo "$SSH_KNOWN_HOSTS" > $HOME/.ssh/known_hosts + - ssh-keyscan -H -p 2202 gitlab.iri.upc.edu >> $HOME/.ssh/known_hosts + + # update apt + - apt-get update + + # create ci_deps folder (if not exists) + - mkdir -pv ci_deps + + # manually source ros setup.bash + - source /root/catkin_ws/devel/setup.bash + - roscd # check that it works + +.install_wolf_template: &install_wolf_definition + - cd ${CI_PROJECT_DIR}/ci_deps + - if [ -d wolf ]; then + - echo "directory wolf exists" + - cd wolf + - git checkout devel + - git pull + - git checkout $WOLF_CORE_BRANCH + - git pull + - else + - git clone -b $WOLF_CORE_BRANCH ssh://git@gitlab.iri.upc.edu:2202/mobile_robotics/wolf_projects/wolf_lib/wolf.git + - cd wolf + - fi + - mkdir -pv build + - cd build + - cmake -DCMAKE_BUILD_TYPE=release -DBUILD_DEMOS=OFF -DBUILD_TESTS=OFF .. + - make -j$(nproc) + - make install + - ldconfig + +.install_laserscanutils_template: &install_laserscanutils_definition + - cd ${CI_PROJECT_DIR}/ci_deps + - if [ -d laser_scan_utils ]; then + - echo "directory laser_scan_utils exists" + - cd laser_scan_utils + - git pull + - else + - git clone https://gitlab.iri.upc.edu/labrobotica/algorithms/laser_scan_utils.git + - cd laser_scan_utils + - fi + - mkdir -pv build + - cd build + - rm -rf * + - cmake -DCMAKE_BUILD_TYPE=release .. + - make -j$(nproc) + - make install + - ldconfig + +.install_csm_template: &install_csm_definition + - cd ${CI_PROJECT_DIR}/ci_deps + - apt-get install -y libgsl-dev + - if [ -d csm ]; then + - echo "directory csm exists" + - cd csm + - git pull + - else + - git clone https://gitlab.iri.upc.edu/labrobotica/algorithms/csm.git + - cd csm + - fi + - cmake . + - make -j$(nproc) + - make install + - ldconfig + +.install_wolflaser_template: &install_wolflaser_definition + - cd ${CI_PROJECT_DIR}/ci_deps + - if [ -d laser ]; then + - echo "directory laser exists" + - cd laser + - git checkout devel + - git pull + - git checkout $WOLF_LASER_BRANCH + - git pull + - else + - git clone -b $WOLF_LASER_BRANCH ssh://git@gitlab.iri.upc.edu:2202/mobile_robotics/wolf_projects/wolf_lib/plugins/laser.git + - cd laser + - fi + - mkdir -pv build + - cd build + - cmake -DCMAKE_BUILD_TYPE=release -DBUILD_TESTS=OFF .. + - make -j$(nproc) + - make install + - ldconfig + +.install_wolfimu_template: &install_wolfimu_definition + - cd ${CI_PROJECT_DIR}/ci_deps + - if [ -d imu ]; then + - echo "directory imu exists" + - cd imu + - git checkout devel + - git pull + - git checkout $WOLF_IMU_BRANCH + - git pull + - else + - git clone -b $WOLF_IMU_BRANCH ssh://git@gitlab.iri.upc.edu:2202/mobile_robotics/wolf_projects/wolf_lib/plugins/imu.git + - cd imu + - fi + - mkdir -pv build + - cd build + - cmake -DCMAKE_BUILD_TYPE=release -DBUILD_TESTS=OFF .. + - make -j$(nproc) + - make install + - ldconfig + +.clone_wolfrosnode_template: &clone_wolfrosnode_definition + - roscd + - cd ../src + - git clone ssh://git@gitlab.iri.upc.edu:2202/mobile_robotics/wolf_projects/wolf_ros/wolf_ros_node.git + - cd wolf_ros_node + - git checkout $WOLF_ROS_CORE_BRANCH + +.clone_wolfroslaser_template: &clone_wolfroslaser_definition + - roscd + - cd ../src + - git clone ssh://git@gitlab.iri.upc.edu:2202/mobile_robotics/wolf_projects/wolf_ros/wolf_ros_laser.git + - cd wolf_ros_laser + - git checkout $WOLF_ROS_LASER_BRANCH + +.clone_wolfroslaser_template: &clone_wolfrosimu_definition + - roscd + - cd ../src + - git clone ssh://git@gitlab.iri.upc.edu:2202/mobile_robotics/wolf_projects/wolf_ros/wolf_ros_imu.git + - cd wolf_ros_imu + - git checkout $WOLF_ROS_IMU_BRANCH + +.demo_template: &demo_definition + - roscd + - cd ../src + - git clone ssh://git@gitlab.iri.upc.edu:2202/${CI_PROJECT_PATH}.git + - cd wolf_demo_imu2d + - git checkout $CI_COMMIT_BRANCH + - cd ../.. + - catkin_make + - roscd wolf_demo_imu2d/bag + - wget https://gitlab.iri.upc.edu/mobile_robotics/wolf_projects/wolf_ros/demos/demo_rosbags/-/raw/main/laser2d_imu/ana_lab_2.bag + - roslaunch wolf_demo_imu2d imu2d_analysys.launch bag:=ana_lab_2 test:=E robot:=ana record:=false rviz:=false 2> roslaunch_error_messages.log + - cat roslaunch_error_messages.log + - if [[ "$(cat roslaunch_error_messages.log)" == *"process has finished cleanly"* ]]; then + - echo "============= ROSLAUNCH FINISHED WITHOUT ANY PROBLEM! ================="; + - else + - exit 1 + - fi -lint-test-job: # This job also runs in the test stage. - stage: test # It can run at the same time as unit-test-job (in parallel). +############ UBUNTU 18.04 TEST ############ +demo:bionic: + stage: demo + image: labrobotica/wolf_deps_ros:18.04 + cache: + - key: wolf_and_deps-bionic + paths: + - ci_deps + before_script: + - *preliminaries_definition + - *install_wolf_definition + - *install_csm_definition + - *install_laserscanutils_definition + - *install_wolflaser_definition + - *install_wolfimu_definition + - *clone_wolfrosnode_definition + - *clone_wolfroslaser_definition + - *clone_wolfrosimu_definition script: - - echo "Linting code... This will take about 10 seconds." - - sleep 10 - - echo "No lint issues found." + - *demo_definition -deploy-job: # This job runs in the deploy stage. - stage: deploy # It only runs when *both* jobs in the test stage complete successfully. +############ UBUNTU 20.04 TEST ############ +demo:focal: + stage: demo + image: labrobotica/wolf_deps_ros:20.04 + cache: + - key: wolf_and_deps-focal + paths: + - ci_deps + before_script: + - *preliminaries_definition + - *install_wolf_definition + - *install_csm_definition + - *install_laserscanutils_definition + - *install_wolflaser_definition + - *install_wolfimu_definition + - *clone_wolfrosnode_definition + - *clone_wolfroslaser_definition + - *clone_wolfrosimu_definition script: - - echo "Deploying application..." - - echo "Application successfully deployed." + - *demo_definition