Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate gcovr and Coveralls #30

Merged
merged 16 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ USER root
RUN apt-get update \
&& apt-get install autoconf autoconf-archive automake \
clang-format clang-tidy \
lcov doxygen graphviz -y --no-install-recommends \
build-essential gcovr lcov xdg-utils \
doxygen graphviz -y --no-install-recommends \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

# Install CMake and vcpkg
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/post-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ if ! git config --global --get safe.directory >/dev/null; then
fi

# set up pre-commit
pre-commit install
pre-commit install --install-hooks
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 15 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
name: Build SDK
runs-on: ubuntu-latest

permissions: write-all

steps:
- name: Checkout
uses: actions/checkout@v4.1.1
Expand All @@ -36,7 +38,8 @@ jobs:
sudo apt-get update && \
sudo apt-get install -y autoconf \
autoconf-archive \
build-essential
build-essential \
gcovr lcov xdg-utils
- name: Setup vcpkg
uses: lukka/run-vcpkg@v11
with:
Expand All @@ -49,7 +52,17 @@ jobs:
configurePreset: ci
buildPreset: ninja
- name: Run Tests
run: build/tests/iggy_cpp_test
run: build/tests/Debug/iggy_cpp_test
- name: Run Coverage
run: |
cd build
ninja coveralls
- name: Upload report to Coveralls
uses: coverallsapp/github-action@v2
with:
file: build/coveralls.json
measure: true
github-token: ${{ secrets.GITHUB_TOKEN }}

lint:
name: Lint
Expand Down
3 changes: 3 additions & 0 deletions .lcovrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
genhtml_branch_coverage = 1
lcov_branch_coverage = 1
lcov_excl_br_line = LCOV_EXCL_BR_LINE|CHECK|REQUIRE
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ repos:
always_run: true
- id: run-unit-tests
name: Run Unit Tests
entry: ./build/tests/iggy_cpp_test
entry: ./build/tests/Debug/iggy_cpp_test
language: system
pass_filenames: false
always_run: true
- id: e2e-tests
name: Run E2E Tests
entry: ./build/tests/iggy_e2e_test
entry: ./build/tests/Debug/iggy_e2e_test
language: system
pass_filenames: false
always_run: true
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ project(iggy-cpp-client)

option(BUILD_TESTS "Build and run unit tests" OFF)
option(BUILD_DOCS "Build documentation" OFF)
option(ENABLE_CODE_COVERAGE "Enable coverage reporting" OFF)

# avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
Expand Down Expand Up @@ -75,6 +76,13 @@ target_link_libraries(
unofficial-sodium::sodium
)

# even though this is related to unit tests, to get a full report we need to ensure that
# all library files are compiled with --coverage so gcno is generated properly
if(ENABLE_CODE_COVERAGE)
include(cmake/modules/CodeCoverage.cmake)
append_coverage_compiler_flags()
endif()

if(BUILD_TESTS)
add_subdirectory(tests)
endif()
Expand Down
5 changes: 3 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "default",
"binaryDir": "${sourceDir}/build",
"generator": "Ninja",
"generator": "Ninja Multi-Config",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
Expand All @@ -15,7 +15,8 @@
"description": "Preset for building unit tests",
"hidden": false,
"cacheVariables": {
"BUILD_TESTS": "ON"
"BUILD_TESTS": "ON",
"ENABLE_CODE_COVERAGE": "ON"
},
"inherits": [
"default"
Expand Down
22 changes: 16 additions & 6 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,31 @@

This is a collection of tips for developers of `iggy-cpp-client`. The initial code is being built with the latest Visual Studio Code and its C++ dev container, under `.devcontainer`. If you are using CLion, XCode or other toolchains it may not have been tested, so please report issues and we will fix them. We are also currently using [vcpkg](https://vcpkg.io) in [manifest mode](https://learn.microsoft.com/en-us/vcpkg/users/manifests) for dependency management. The appropriate packages are downloaded and compiled locally as part of the CMake build, but if you add a new dependency extra steps are required to update the manifest and CMake configuration.

## Philosophy: code quality

In VS Code the dev container automatically installs [pre-commit](https://pre-commit.com), sets up the `.git` hooks directory and installs all necessary tools for pre-commit checks. The relevant linters from [super-linter](https://github.com/super-linter/super-linter) -- which runs in CI automatically -- as well as the build, unit tests ad E2E tests are all run for you on any changed files before any local Git commit, _before_ it gets pushed. This is in line with the general project philosophy to do as many quality checks and fixes left-of-merge, meaning we aim to catch problems first in the IDE, then in pre-commit checks, and finally in mandatory checks run in CI before the developer ever merges a code change to the `main` branch. This is born of hard experience that quality problems, once merged in, are much harder to repair. Not only is the problem out of context ("which of the last 20 commits caused this E2E test regression?") but accountability is lost: the person who has broken a test, introduced a warning or violated coding standards _must_ be the one to fix the problem. "Quality control is everyone's problem" is not enough: applied literally, quality is nobody's problem, so this is better understood as a requirement that everyone own the impact of the changes they themselves make to the codebase to the maximum extent possible.

## Tested configurations

CI runs on ubuntu-20.04 and ubuntu-22.04, and the dev containers have been tested on both x64 and arm64 (macOS 14.x, using latest VS Code and Docker Desktop).
CI runs on `ubuntu-latest`, and the dev containers have been tested on both x64 and arm64 (macOS 14.x, using latest VS Code and Docker Desktop). CLion, XCode and other C++ IDE's will be supported on a best-efforts basis.

## HOWTO: Test GitHub Actions locally
## HOWTO: Run pre-commit checks manually

Our continuous integration uses GitHub Actions, and sometimes it's more convenient to first test it. The VS Code container includes the [act](https://github.com/nektos/act) extension, and you can use it to do a smoke test of the CI actions before you push to GitHub:
When adding new pre-commit checks or when testing out other development environment changes, you may wish to pro-actively run all pre-commit checks on all files. You can do it this way:

```shell
act -P ubuntu-20.04=catthehacker/ubuntu:full-20.04 -P ubuntu-22.04=catthehacker/ubuntu:full-22.04
pre-commit run --all-files
```

If you want to do a quicker test, add `--matrix=os:ubuntu-22.04` to run just a single matrix variant.
![Pre-commit run](docs/images/pre-commit_run.png)

## HOWTO: Test GitHub Actions locally

Our continuous integration uses GitHub Actions, and sometimes it's more convenient to first test it. The VS Code container includes the [act](https://github.com/nektos/act) extension, and you can use it to do a smoke test of the CI actions before you push to GitHub. Run `act` and, if running for the first time, choose "Medium" for the container:

![Initializing act](docs/images/init_act.png)

Once it's working well locally, you can push and the CI job will automatically run the full matrix for you.
Note `act` is an _emulator_ that runs in Docker. It may not perfectly reproduce the GitHub Actions environment, and is not a substitute for a full CI run on GitHub post-commit.

## Resources

Expand Down
Loading