Makefiles can be helpful in your CI Workflow

While developing palpatine, I used Makefile to automate the process of building and running the project.

Currently, it looks something like this:

setup:
@if [ “$(shell uname)” = “Darwin” ]; then \
brew install gcovr; \
brew ins…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Batuhan İpçi

While developing palpatine, I used Makefile to automate the process of building and running the project.

Currently, it looks something like this:

setup: 
    @if [ "$(shell uname)" = "Darwin" ]; then \
        brew install gcovr; \
        brew install lcov; \
    fi
    @if [ "$(shell uname)" = "Linux" ]; then \
        pip install gcovr; \
    fi

dependency:
    cd build && cmake .. --graphviz=dependency.dot && dot -Tpng dependency.dot -o dependency.png

prepare:
    @echo ">>> Building palpatine ...";
    @if [ -d ./build ]; then rm -rf ./build; fi
    @mkdir build; 
    @cd build; \
    cmake -S .. -B .; \
    make; \

    @echo ">>> Done";
    @echo ">>> Run ./palpatine [options] to start the application";


test:
    @echo ">>> Running tests ...";
    @cd build; \
    cmake --build . --target unit_tests ;
    @cd build/tests; \
    ./unit_tests;

codecov:
    @echo ">>> Running tests ...";
    @cd build; \
    cmake --build . --target unit_tests ;
    gcovr --html -o build/index.html ;

Most of the set of rules of this Makefile are self-explanatory, also the echo logs I've set makes it easier to understand. I’m going to explain the ones that are not that obvious.

  • dependency rule is a interesting one. It initially changes the directory to build and then runs cmake with --graphviz=dependency.dot flag. This flag generates a dependency.dot file which is a graphviz file. Then, it runs dot command with -Tpng flag to generate a dependency.png file in build directory. This png file is a dependency graph of palpatine.

  • codecov rule builds unit_tests target just like test rule. Then, it runs gcovr command with --html flag to generate a index.html file in build directory. It helps to visualize the code coverage of the project.

Few weeks ago, I have added CI workflow to palpatine.

jobs:
  build:
    runs-on: macos-latest
    steps:
    - uses: actions/checkout@v2
    - name: setup
      run: |
        make setup
    - name: configure
      run: |
        cmake -H. -Bbuild -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="Debug"
    - name: building
      run: |
        cmake --build build --config Debug --target unit_tests -j4
    - name: testing
      run: |
        cd build/tests && ./unit_tests
        bash <(curl -s https://codecov.io/bash)

This workflow runs on macOS and it does the following:

  • It checks out the code from the repository.
  • It runs make setup to install gcovr and lcov.
  • It runs cmake to configure the project.
  • It builds the project.
  • It runs the tests.
  • It uploads the code coverage report to codecov.

In the next releases, I am planning to automate the CI workflow with Makefile commands. I will update this post when I do that.


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Batuhan İpçi


Print Share Comment Cite Upload Translate Updates
APA

Batuhan İpçi | Sciencx (2022-11-30T22:47:44+00:00) Makefiles can be helpful in your CI Workflow. Retrieved from https://www.scien.cx/2022/11/30/makefiles-can-be-helpful-in-your-ci-workflow/

MLA
" » Makefiles can be helpful in your CI Workflow." Batuhan Ä°pçi | Sciencx - Wednesday November 30, 2022, https://www.scien.cx/2022/11/30/makefiles-can-be-helpful-in-your-ci-workflow/
HARVARD
Batuhan Ä°pçi | Sciencx Wednesday November 30, 2022 » Makefiles can be helpful in your CI Workflow., viewed ,<https://www.scien.cx/2022/11/30/makefiles-can-be-helpful-in-your-ci-workflow/>
VANCOUVER
Batuhan Ä°pçi | Sciencx - » Makefiles can be helpful in your CI Workflow. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/11/30/makefiles-can-be-helpful-in-your-ci-workflow/
CHICAGO
" » Makefiles can be helpful in your CI Workflow." Batuhan Ä°pçi | Sciencx - Accessed . https://www.scien.cx/2022/11/30/makefiles-can-be-helpful-in-your-ci-workflow/
IEEE
" » Makefiles can be helpful in your CI Workflow." Batuhan Ä°pçi | Sciencx [Online]. Available: https://www.scien.cx/2022/11/30/makefiles-can-be-helpful-in-your-ci-workflow/. [Accessed: ]
rf:citation
» Makefiles can be helpful in your CI Workflow | Batuhan Ä°pçi | Sciencx | https://www.scien.cx/2022/11/30/makefiles-can-be-helpful-in-your-ci-workflow/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.