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 tobuild
and then runscmake
with--graphviz=dependency.dot
flag. This flag generates adependency.dot
file which is a graphviz file. Then, it runsdot
command with-Tpng
flag to generate adependency.png
file in build directory. This png file is a dependency graph of palpatine.codecov
rule builds unit_tests target just liketest
rule. Then, it runs gcovr command with--html
flag to generate aindex.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
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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.