Skip to content
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
12 changes: 7 additions & 5 deletions .github/workflows/cpp-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ jobs:

- name: Check Tools
run: |
echo "-----------"
gcc --version
echo "-----------"
g++ --version
echo "-----------"
Expand All @@ -41,18 +43,18 @@ jobs:
echo "-----------"
vcpkg --version
echo "-----------"
gcov --version
echo "-----------"
gcovr --version

- name: Install dependencies
run: |
make dependencies
run: make dependencies

- name: Build
run: |
make build
run: make build

- name: Test / Coverage
run: make coverage
run: make coverage/test

# yamllint disable rule:line-length
- name: Upload coverage reports to Codecov with GitHub Action
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ jobs:

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4

- name: "PRODUCTION: Build and push"
uses: docker/build-push-action@v7
with:
Expand Down Expand Up @@ -209,7 +210,7 @@ jobs:
run: >
docker
run --rm ${{ env.IMAGE_NAME }}-${{ matrix.base_image }}:test
make test-no-deps
make coverage/test

# yamllint disable rule:line-length
# security:
Expand Down Expand Up @@ -272,6 +273,7 @@ jobs:
actions: read
contents: read
security-events: write

steps:
- name: Download artifact
uses: actions/download-artifact@v8
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM alpine:3.24 AS init

ENV WORKDIR=/app
ENV WORKDIR=/workspace
WORKDIR ${WORKDIR}

ARG DEBIAN_FRONTEND=noninteractive
Expand Down Expand Up @@ -118,7 +118,7 @@ RUN apk --update add --no-cache \
# libasan required (AdressSanitizer)
"gcc=15.2.0-r5" \
# coverage
"lcov=2.3.1-r1" \
"gcovr=8.6-r1" \
# runtime required libraries
"libgcc=15.2.0-r5" \
"libstdc++=15.2.0-r5"
Expand All @@ -132,13 +132,13 @@ FROM alpine:3.24 AS production

ENV LOG_LEVEL=INFO
ENV BRUTEFORCE=false
ENV WORKDIR=/app
ENV WORKDIR=/workspace
WORKDIR ${WORKDIR}

COPY --from=builder ${WORKDIR}/build/src/lib/exercises/*.a ${WORKDIR}/

RUN addgroup -S -g 1001 app \
&& adduser -S -u 1001 -G app -h /home/app app
&& adduser -S -u 1001 -G app -h /home/workspace app
USER 1001

RUN ls -alhR
Expand Down
12 changes: 7 additions & 5 deletions Dockerfile.debian
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM debian:stable-20261005-slim AS init

ENV WORKDIR=/app
ENV WORKDIR=/workspace
WORKDIR ${WORKDIR}

ARG DEBIAN_FRONTEND=noninteractive
Expand All @@ -11,6 +11,7 @@ RUN apt-get update \
&& apt-get -y install --no-install-recommends --no-install-suggests \
## common permanent packages
"make=4.4.1-2" \
"gcc=4:14.2.0-1" \
&& rm -rf /var/lib/apt/lists/*

COPY ./Makefile ${WORKDIR}/
Expand Down Expand Up @@ -43,7 +44,6 @@ RUN apt-get update \
&& apt-get -y install --no-install-recommends --no-install-suggests \
"build-essential=12.12" \
"g++=4:14.2.0-1" \
"gcc=4:14.2.0-1" \
"pkg-config=1.8.1-4" \
## clean up
&& apt-get clean \
Expand Down Expand Up @@ -130,8 +130,10 @@ FROM init AS testing

RUN apt-get -y update && \
apt-get -y install --no-install-recommends --no-install-suggests \
"lcov=2.3.1-1" && \
rm -rf /var/lib/apt/lists/*
"python3-minimal=3.13.5-1" \
"python3-pip=25.1.1+dfsg-1" \
&& rm -rf /var/lib/apt/lists/* \
&& pip3 install --break-system-packages --no-cache-dir --only-binary :all: gcovr==8.6

COPY --from=builder ${WORKDIR} ${WORKDIR}

Expand All @@ -141,7 +143,7 @@ FROM debian:stable-20261005-slim AS production

ENV LOG_LEVEL=INFO
ENV BRUTEFORCE=false
ENV WORKDIR=/app
ENV WORKDIR=/workspace
WORKDIR ${WORKDIR}

RUN apt-get update \
Expand Down
13 changes: 8 additions & 5 deletions Dockerfile.ubuntu
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ubuntu:26.04 AS init

ENV WORKDIR=/app
ENV WORKDIR=/workspace
WORKDIR ${WORKDIR}

ARG DEBIAN_FRONTEND=noninteractive
Expand All @@ -10,6 +10,7 @@ RUN apt-get update \
&& apt-get -y install --no-install-recommends --no-install-suggests \
## common permanent packages
"make=4.4.1-3" \
"gcc=4:15.2.0-5ubuntu1" \
&& rm -rf /var/lib/apt/lists/*

COPY ./Makefile ${WORKDIR}/
Expand Down Expand Up @@ -47,7 +48,6 @@ RUN apt-get update \
&& apt-get -y install --no-install-recommends --no-install-suggests \
"build-essential=12.12ubuntu2.26.04.2" \
"g++=4:15.2.0-5ubuntu1" \
"gcc=4:15.2.0-5ubuntu1" \
"pkg-config=2.5.1-4" \
## clean up
&& apt-get clean \
Expand Down Expand Up @@ -134,8 +134,11 @@ FROM init AS testing

RUN apt-get -y update && \
apt-get -y install --no-install-recommends --no-install-suggests \
"lcov=2.4-3" && \
rm -rf /var/lib/apt/lists/*
"libasan8=16-20260322-1ubuntu1" \
"python3-minimal=3.14.3-0ubuntu2" \
"python3-pip=25.1.1+dfsg-1ubuntu2" \
&& rm -rf /var/lib/apt/lists/* \
&& pip3 install --break-system-packages --no-cache-dir --only-binary :all: gcovr==8.6

COPY --from=builder ${WORKDIR} ${WORKDIR}

Expand All @@ -145,7 +148,7 @@ FROM ubuntu:26.04 AS production

ENV LOG_LEVEL=INFO
ENV BRUTEFORCE=false
ENV WORKDIR=/app
ENV WORKDIR=/workspace
WORKDIR ${WORKDIR}

RUN apt-get update \
Expand Down
26 changes: 15 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ DOCKER_COMPOSE=docker compose
COVERAGE_TOOL_OPTS = \
--root . \
--filter 'src/lib/*' \
--exclude-unreachable-branches \
--exclude-throw-branches \
--exclude-noncode-lines \
--exclude "tests/*" \
--exclude 'build/*' \
--exclude-noncode-lines \
--exclude-throw-branches \
--exclude-unreachable-branches \
--txt \
--txt-metric line \
--txt-metric branch \
Expand All @@ -42,7 +42,7 @@ SRC_DIR = src
FILES := $(shell find $(SRC_DIR) -name '*.cpp' -o -name '*.c' -o -name '*.h' -o -name '*.hpp' -o -name '*.inl')

.MAIN: test
.PHONY: all clean dependencies help list test outdated
.PHONY: all clean coverage dependencies help list test outdated
.EXPORT_ALL_VARIABLES: # (2)

define crono
Expand Down Expand Up @@ -108,7 +108,6 @@ test/static-no-deps:
--project=build/compile_commands.json \
--enable=all \
--check-level=exhaustive \
--std=c++17 \
--library=posix \
--inconclusive \
--inline-suppr \
Expand All @@ -129,18 +128,23 @@ format/json:

format: format/sources format/json

test: env dependencies build clean/test
cd build && make test
test: env dependencies build clean/test test-no-deps

test-no-deps:
cd build && make test
cd build && echo "current working directory: $(pwd)" && make test

coverage: test
coverage/report:
mkdir -p coverage
gcovr ${COVERAGE_TOOL_OPTS} \
--lcov coverage/coverage.lcov \
--sonarqube coverage/coverage.xml

coverage/html: test
coverage/test: test-no-deps coverage/report

coverage: coverage/report

coverage/html:
mkdir -p coverage
gcovr ${COVERAGE_TOOL_OPTS} \
--html-details coverage/index.html

Expand Down Expand Up @@ -199,7 +203,7 @@ compose/lint: compose/test/styling compose/test/static
compose/lint/all: compose/lint/markdown compose/lint/yaml compose/lint/json compose/test/styling compose/test/static

compose/test:
${DOCKER_COMPOSE} --profile testing run --rm algorithm-exercises-cpp-test make test-no-deps
${DOCKER_COMPOSE} --profile testing run --rm algorithm-exercises-cpp-test make coverage

compose/run: compose/build
${DOCKER_COMPOSE} --profile production run --rm algorithm-exercises-cpp ls -alhR
Expand Down
12 changes: 6 additions & 6 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
LOG_LEVEL: ${LOG_LEVEL:-info} ## (1) ## info | debug
BRUTEFORCE: ${BRUTEFORCE:-false} ## (1) ## true | false
volumes:
- ./coverage:/app/coverage
- ./coverage:/workspace/coverage
profiles: ['testing']

algorithm-exercises-cpp-lint:
Expand All @@ -20,9 +20,9 @@ services:
dockerfile: Dockerfile.${BASE_IMAGE:-alpine}
target: lint
volumes:
- ./.clang-format:/app/.clang-format
- ./Makefile:/app/Makefile
- ./src:/app/src
- ./.clang-format:/workspace/.clang-format
- ./Makefile:/workspace/Makefile
- ./src:/workspace/src
profiles: ['lint']

markdownlint:
Expand Down Expand Up @@ -56,7 +56,7 @@ services:
LOG_LEVEL: ${LOG_LEVEL:-info} ## (1) ## info | debug
BRUTEFORCE: ${BRUTEFORCE:-false} ## (1) ## true | false
volumes:
- ./:/app
- ./:/workspace
profiles: ['development']

algorithm-exercises-cpp:
Expand All @@ -66,7 +66,7 @@ services:
dockerfile: Dockerfile.${BASE_IMAGE:-alpine}
target: production
# volumes:
# - ./:/app
# - ./:/workspace
profiles: ['production']

## REFERENCES:
Expand Down
Loading