Giter Site home page Giter Site logo

ginomempin / sample-ci-cpp Goto Github PK

View Code? Open in Web Editor NEW
24.0 4.0 11.0 64 KB

Sample project for setting-up Gitlab CI/CD with CMake, googletest, lcov for C++-based applications

CMake 39.31% Dockerfile 11.99% C++ 48.70%
cpp cpp14 cmake googletest lcov gitlab-ci gitlab-ci-runner gitlab-pipeline

sample-ci-cpp's Introduction

Gitlab CI/CD Example for C++-based Apps

pipeline status coverage report

CONTENTS

DEPENDENCIES

  • The main requirements are:
    • Ubuntu 16.04
    • cmake 3.5.1
      • g++ 5.4.0 (needed by CMake to compile CXX files)
    • googletest 1.8.1
      • git 2.7.4 (for downloading googletest within CMake)
      • libpthread-stubs0-dev 0.3-4 (for linking pthread)
    • lcov 1.12 (for generating code coverage)
    • Access to a Gitlab instance
    • Access to a build/test/server PC for gitlab-runner

SETUP

  • Setup the Local Test Environment
    • Using your own Ubuntu system
      • Install gcc, cmake, git, and pthread
        $ sudo apt-get update
        $ sudo apt-get install g++=4:5.3.1-1ubuntu1
        $ sudo apt-get install lcov=1.12-2
        $ sudo apt-get install cmake=3.5.1-1ubuntu3
        $ sudo apt-get install git=1:2.7.4-0ubuntu1.6
        $ sudo apt-get install libpthread-stubs0-dev=0.3-4
        
        
      • Build the application and the tests
        $ cd build
        $ cmake ..
        $ make -j8
        
        
    • Using Docker
      • Create a Docker image from the Dockerfile
        docker build --tag sample-ci-cpp .
        docker run -it sample-ci-cpp:latest /bin/bash
        
        
  • Setup Gitlab CI

USAGE

  • Run the Tests on Local
    • Run the tests
      $ cd build
      $ ./bin/calculator_tests
      [==========] Running 3 tests from 2 test cases.
      [----------] Global test environment set-up.
      [----------] 1 test from AddTest
      [ RUN      ] AddTest.ValidNumbers
      [       OK ] AddTest.ValidNumbers (0 ms)
      [----------] 1 test from AddTest (0 ms total)
      
      [----------] 2 tests from DivTest
      [ RUN      ] DivTest.ValidNumbers
      [       OK ] DivTest.ValidNumbers (0 ms)
      [ RUN      ] DivTest.InvalidNumbers
      [       OK ] DivTest.InvalidNumbers (0 ms)
      [----------] 2 tests from DivTest (0 ms total)
      
      [----------] Global test environment tear-down
      [==========] 3 tests from 2 test cases ran. (1 ms total)
      [  PASSED  ] 3 tests.
      
      
    • Check code coverage
      $ cd build
      $ cd CMakeFiles/calculator_tests.dir/
      $ lcov --directory . --capture -o coverage.info
      $ lcov -r coverage.info */build/* */tests/* */c++/* -o coverageFiltered.info
      $ lcov --list coverageFiltered.info
      
      
  • Run the Tests on Gitlab
    • Make changes in src/ and in tests/
    • Make changes to the .gitlab-ci.yml configuration (if necessary)
    • Commit the changes then push to Gitlab
    • Go to the Gitlab project > CI/CD > Pipelines
    • Select the currently running job to view progress/result
    • It is possible to download the job log by clicking on the Raw button

ISSUES

  • The tests and the code coverage does not seem to be using latest src and tests
    • Delete the build directory then re-create it
      $ rm -Rf build
      $ mkdir build
      $ touch .gitkeep
      
      
  • "This job is stuck, because you don’t have any active runners that can run this job."
    • Make sure that the .gitlab-ci.yml has the correct tags
    • Make sure the gitlab-runner service is running
    • Make sure the machine running gitlab-runner is accessible by the Gitlab instance
  • "yaml invalid"
    • Go to the Gitlab project > CI/CD
    • On the top-right portion, click the CI Lint button
    • Paste the contents of gitlab-ci.yml file and validate
  • The gitlab-runner is leaving a lot of -cache- containers/volumes
    • See a discussion of this behavior here
    • Possible solutions:
      • Manually regularly run docker system prune
      • Setup a cron job docker system prune -f
        # Cleanup docker containers/volumes every 3am every monday
        0 3 * * 1 /usr/bin/docker system prune -f
        
        

DOCUMENTATION

sample-ci-cpp's People

Contributors

ginomempin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.