Skip to content

Commit ce0ca0e

Browse files
committed
feat: faster pipeline, build docker image on dockerhub, unit test coverage, codecov badge, sonarqube badge
1 parent 9bb73ce commit ce0ca0e

9 files changed

Lines changed: 245 additions & 35 deletions

File tree

.github/workflows/build.yml

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ on:
1010
jobs:
1111
format:
1212
runs-on: ubuntu-latest
13+
container:
14+
image: milss/tradercppbuild:v1.5
1315
steps:
1416
- name: Checkout repository
1517
uses: actions/checkout@v4
1618

17-
- name: Set up clang-format
18-
run: sudo apt update && sudo apt install -y clang-format
19+
# - name: Set up clang-format
20+
# run: sudo apt update && sudo apt install -y clang-format
1921

2022
- name: Check code formatting
2123
run: |
@@ -33,6 +35,8 @@ jobs:
3335
build_and_test:
3436
needs: format
3537
runs-on: ubuntu-latest
38+
container:
39+
image: milss/tradercppbuild:v1.5
3640
steps:
3741
- name: Checkout repository
3842
uses: actions/checkout@v4
@@ -45,13 +49,49 @@ jobs:
4549
restore-keys: |
4650
${{ runner.os }}-conan-
4751
48-
- name: Install dependencies and build
52+
# - name: Install system dependencies
53+
# run: |
54+
# set -e
55+
# sudo apt update && sudo apt install -y g++ lcov
56+
# pip install conan
57+
58+
- name: Install conan dependencies
4959
run: |
5060
set -e
51-
sudo apt update && sudo apt install -y g++
52-
pip install conan
61+
rm -rf build
5362
conan profile detect --force
5463
conan install . --build=missing -s build_type=Debug
55-
cmake --preset=conan-debug
56-
cmake --build --preset=conan-debug
57-
ctest --test-dir build/Debug --output-on-failure
64+
65+
- name: Build and Test
66+
run: |
67+
set -e
68+
cmake --preset=debug
69+
cmake --build --preset=debug
70+
ctest --preset=debug
71+
lcov --gcov-tool gcov \
72+
--capture \
73+
--directory . \
74+
--output-file lcov.info \
75+
--rc geninfo_unexecuted_blocks=1 \
76+
--ignore-errors mismatch
77+
# lcov --remove lcov.info '/home/*' '/usr/*' 'tests/*' --output-file lcov_filtered.info
78+
# TODO: need to solve mismatch before proceeding, custom docker image
79+
80+
# TODO: should coverage be published in the case that SonarQube fails?
81+
# - name: Upload coverage to Coveralls
82+
# uses: coverallsapp/github-action@v2
83+
# with:
84+
# path-to-lcov: lcov.info
85+
# continue-on-error: true
86+
87+
- name: Upload coverage to Codecov
88+
uses: codecov/codecov-action@v5
89+
with:
90+
token: ${{ secrets.CODECOV_TOKEN }}
91+
files: lcov.info
92+
93+
- name: SonarQube Scan
94+
uses: SonarSource/sonarqube-scan-action@v6.0.0
95+
env:
96+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
97+
continue-on-error: true

.vscode/settings.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
22
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
33
"C_Cpp.default.compileCommands": "${workspaceFolder}/build/Debug/compile_commands.json",
4-
"editor.formatOnSave": true
4+
"editor.formatOnSave": true,
5+
"sonarlint.connectedMode.project": {
6+
"connectionId": "milsanore",
7+
"projectKey": "milsanore_trader.cpp"
8+
},
9+
"sonarlint.pathToCompileCommands": "${workspaceFolder}/build/Debug/compile_commands.json"
510
}

.vscode/tasks.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"command": "bash",
88
"args": [
99
"-c",
10-
"mkdir -p build && source .venv/bin/activate && conan install . --build=missing -s build_type=Debug && cmake --preset=conan-debug && cmake --build --preset=conan-debug"
10+
"mkdir -p build && source .venv/bin/activate && conan install . --build=missing -s build_type=Debug && cmake --preset=debug && cmake --build --preset=debug"
1111
],
1212
"group": {
1313
"kind": "build",
@@ -17,4 +17,4 @@
1717
"detail": "Builds the project using Conan and CMake Debug preset"
1818
}
1919
]
20-
}
20+
}

CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ set(SOURCES ${ALL_SOURCES})
3232
# Create core logic library
3333
add_library(traderlib STATIC ${SOURCES})
3434

35-
# TODO: MAKE CONDITIONAL
3635
# Add coverage flags to the traderlib target
37-
target_compile_options(traderlib PRIVATE -O0 -g --coverage)
38-
target_link_libraries(traderlib PRIVATE --coverage)
36+
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
37+
message(STATUS "Enabling coverage flags")
38+
target_compile_options(traderlib PRIVATE -O0 -g --coverage)
39+
target_link_libraries(traderlib PRIVATE --coverage)
40+
endif()
3941

4042
# Link dependencies to the library (so both exe and tests get them)
4143
target_link_libraries(traderlib PUBLIC

CMakePresets.json

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,36 @@
22
"version": 3,
33
"cmakeMinimumRequired": {
44
"major": 3,
5-
"minor": 23,
5+
"minor": 25,
66
"patch": 0
77
},
8-
"configurePresets": []
9-
}
8+
"configurePresets": [
9+
{
10+
"name": "debug",
11+
"displayName": "Conan Debug Build",
12+
"generator": "Ninja",
13+
"binaryDir": "${sourceDir}/build/Debug",
14+
"cacheVariables": {
15+
"CMAKE_BUILD_TYPE": "Debug",
16+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
17+
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/build/Debug/generators/conan_toolchain.cmake"
18+
}
19+
}
20+
],
21+
"buildPresets": [
22+
{
23+
"name": "debug",
24+
"configurePreset": "debug",
25+
"jobs": 0
26+
}
27+
],
28+
"testPresets": [
29+
{
30+
"name": "debug",
31+
"configurePreset": "debug",
32+
"output": {
33+
"outputOnFailure": true
34+
}
35+
}
36+
]
37+
}

Dockerfile_build

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#############################################
2+
# milss/tradercppbuild:v1.5
3+
# Build container for tradercpp
4+
# Published to dockerhub in order to accelerate github actions
5+
# Uses:
6+
# - Ubuntu 24.04
7+
# - CMake 4
8+
# - Conan 2 (incl. Python3)
9+
# - GCC 13
10+
# - LLVM 18 (clang-format and clang-tidy)
11+
# - make
12+
# - ninja-build
13+
# - perl (compilation dependency for conan packages)
14+
#############################################
15+
16+
17+
FROM ubuntu:24.04 AS build_container
18+
19+
# Set noninteractive mode to avoid prompts during install
20+
ENV DEBIAN_FRONTEND=noninteractive
21+
22+
RUN apt-get update && \
23+
apt-get install -y software-properties-common && \
24+
add-apt-repository universe && \
25+
apt-get update
26+
27+
28+
# Install CMake
29+
30+
RUN apt install -y --no-install-recommends \
31+
gnupg \
32+
lsb-release \
33+
software-properties-common \
34+
wget
35+
36+
RUN wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | \
37+
gpg --dearmor - | tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null && \
38+
echo "deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ $(lsb_release -cs) main" | \
39+
tee /etc/apt/sources.list.d/kitware.list >/dev/null
40+
41+
RUN apt install -y --no-install-recommends cmake
42+
43+
44+
# Install Conan
45+
46+
RUN apt install -y --no-install-recommends python3 python3-pip python3-venv
47+
48+
RUN python3 -m venv /opt/conan-venv && \
49+
/opt/conan-venv/bin/pip install --upgrade pip && \
50+
/opt/conan-venv/bin/pip install "conan>=2.0"
51+
52+
ENV PATH="/opt/conan-venv/bin:$PATH"
53+
54+
RUN mkdir -p /root/.conan2/profiles && printf \
55+
"[settings]\n\
56+
arch=x86_64\n\
57+
build_type=Release\n\
58+
compiler=gcc\n\
59+
compiler.cppstd=gnu17\n\
60+
compiler.libcxx=libstdc++11\n\
61+
compiler.version=13\n\
62+
os=Linux\n" \
63+
> /root/.conan2/profiles/default
64+
65+
66+
# Install GCC 13
67+
68+
RUN add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
69+
apt-get update && \
70+
apt-get install -y --no-install-recommends \
71+
cmake \
72+
g++-13 \
73+
gcc-13
74+
75+
76+
# Install LLVM (clang-format and clang-tidy)
77+
78+
RUN apt-get install -y \
79+
gnupg \
80+
lsb-release \
81+
software-properties-common \
82+
wget
83+
84+
RUN wget -qO - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
85+
86+
RUN echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" > /etc/apt/sources.list.d/llvm18.list
87+
88+
RUN apt-get update && \
89+
apt-get install -y clang-format-18 clang-tidy-18
90+
91+
RUN update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-18 100 && \
92+
update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-18 100
93+
94+
95+
# Install build tools
96+
97+
RUN apt-get install -y --no-install-recommends \
98+
build-essential \
99+
curl \
100+
git \
101+
lcov \
102+
make \
103+
ninja-build \
104+
perl \
105+
unzip \
106+
&& rm -rf /var/lib/apt/lists/*
107+
108+
# END: CLEAR CACHE
109+
RUN rm -rf /var/lib/apt/lists/*

Makefile

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,32 @@ init:
2828
source .venv/bin/activate && \
2929
pip install conan && \
3030
conan install . --build=missing -s build_type=Debug
31-
cmake --preset=conan-debug
31+
cmake --preset=debug
32+
33+
## init-build-container: 🚢 create the docker container for building the app (hosted on dockerhub)
34+
.PHONY: init-build-container
35+
init-build-container:
36+
docker build -f Dockerfile_build -t milss/tradercppbuild:latest .
3237

3338
## build-debug: 🔨 compile (debug)
3439
.PHONY: build-debug
3540
build-debug:
36-
cmake --build --preset=conan-debug
41+
cmake --build --preset=debug
3742

3843
## test: 🧪 run google-test
3944
.PHONY: test
4045
test:
41-
cmake --build --preset=conan-debug
42-
ctest --test-dir build/Debug --output-on-failure
46+
cmake --build --preset=debug
47+
ctest --preset=debug
4348
lcov --gcov-tool gcov --capture --directory . --output-file lcov.info
4449

4550
## build-release: 🔨🔨 compile (prod)
4651
.PHONY: build-release
4752
build-release:
4853
source .venv/bin/activate && \
4954
conan install . --build=missing -s build_type=Release
50-
cmake --preset=conan-release
51-
cmake --build --preset=conan-release
55+
cmake --preset=release
56+
cmake --build --preset=release
5257

5358
## run-debug: 🏃‍♂️ run the app (debug) (don't forget `withenv`)
5459
.PHONY: run-debug

README.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
# trader.cpp
2-
a proof-of-concept, showcasing some c++ coding combined with some fintech concepts
1+
2+
[![codecov](https://codecov.io/gh/your-username/your-repo/branch/main/graph/badge.svg?token=YOUR_TOKEN)](https://codecov.io/gh/your-username/your-repo)
3+
[![Build](https://github.com/milsanore/trader.cpp/actions/workflows/build.yml/badge.svg)](https://github.com/milsanore/trader.cpp/actions/workflows/build.yml)
4+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=milsanore_trader.cpp&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=milsanore_trader.cpp)
35

46
<img src="https://static.wikia.nocookie.net/surrealmemes/images/8/80/2f0.png"
57
alt="stonks"
68
width="250" />
79

8-
## REQUIREMENTS
10+
# trader.cpp
11+
a proof-of-concept, showcasing some c++ coding combined with some fintech concepts
12+
13+
## RUN REQUIREMENTS
914
- a Binance account, with an Ed25519 token that has FIX read permissions enabled
15+
- `stunnel` or a local proxy, for TLS encryption
16+
17+
## BUILD REQUIREMENTS
1018
- C++20
1119
- `Conan` (and a conan profile)
1220
- `CMake`
13-
- `stunnel` or a local proxy, for TLS encryption
1421

1522
## DEV REQUIREMENTS
1623
- `clang-tidy`
@@ -58,23 +65,27 @@ a proof-of-concept, showcasing some c++ coding combined with some fintech concep
5865
- basic schema (severity, correlationId)
5966
- ✅ dependency injection
6067
- ✅ single-threaded to start with, then re-architect (and mermaid diagram)
61-
- nix virtual environment
68+
- ✅ code formatting / clang-format
69+
- ✅ git hooks
70+
- ✅ integrated into build pipeline
71+
- ✅ coverage badge
72+
- ✅ custom docker build image with all dependencies (for faster pipelines)
73+
- ✅ static code analysis
74+
- ✅ sonarcloud integrated into build pipeline
75+
- clang-tidy
6276
- decimal type
6377
- sparse arrays
6478
- release binaries on github
6579
- ccache.dev
6680
- zeromq + protobufs?
6781
- valgrind/cachegrind
68-
- code formatting / auto-formatter
69-
- ✅ clang-format
70-
- ✅ git hooks
71-
- ✅integrated into build pipeline
72-
- clang-tidy
7382
- github releases
74-
- custom docker build image with all dependencies
83+
- local github action runner
84+
- sonarqube integration
85+
- nix virtual environment
7586

7687
# STANDARDS
77-
- high unit-test coverage + badge
88+
- high unit-test coverage
7889
- static code analysis
7990
- configure debugging
8091
- git use

sonar-project.properties

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
sonar.host.url=https://sonarcloud.io
2+
sonar.organization=milsanore
3+
sonar.projectKey=milsanore_trader.cpp
4+
5+
# Sources
6+
sonar.sources=src
7+
sonar.cfamily.compile-commands=build/Debug/compile_commands.json
8+
9+
# Optional: coverage (see below)
10+
sonar.cpp.coverage.reportPath=lcov.info

0 commit comments

Comments
 (0)