From 77c95321966c4375c9c636ed2f7acf016ee2dc9b Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Sun, 18 Oct 2026 12:53:25 -0300 Subject: [PATCH] fix: [Docker] [Github Actions] test in docker now run from "coverage" workflow. [Docker] coverage workflow fixed. Coverage dependencies fixed. --- .github/workflows/cpp-coverage.yml | 12 +++++++----- .github/workflows/docker-image.yml | 4 +++- Dockerfile.alpine | 8 ++++---- Dockerfile.debian | 12 +++++++----- Dockerfile.ubuntu | 13 ++++++++----- Makefile | 26 +++++++++++++++----------- compose.yaml | 12 ++++++------ 7 files changed, 50 insertions(+), 37 deletions(-) diff --git a/.github/workflows/cpp-coverage.yml b/.github/workflows/cpp-coverage.yml index acaacc7..0efeb8f 100644 --- a/.github/workflows/cpp-coverage.yml +++ b/.github/workflows/cpp-coverage.yml @@ -32,6 +32,8 @@ jobs: - name: Check Tools run: | + echo "-----------" + gcc --version echo "-----------" g++ --version echo "-----------" @@ -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 diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index fa78cb8..fb47812 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -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: @@ -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: @@ -272,6 +273,7 @@ jobs: actions: read contents: read security-events: write + steps: - name: Download artifact uses: actions/download-artifact@v8 diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 8b0c1b1..55f75d1 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -1,6 +1,6 @@ FROM alpine:3.24 AS init -ENV WORKDIR=/app +ENV WORKDIR=/workspace WORKDIR ${WORKDIR} ARG DEBIAN_FRONTEND=noninteractive @@ -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" @@ -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 diff --git a/Dockerfile.debian b/Dockerfile.debian index 314fc7e..7d343b2 100644 --- a/Dockerfile.debian +++ b/Dockerfile.debian @@ -1,6 +1,6 @@ FROM debian:stable-20261005-slim AS init -ENV WORKDIR=/app +ENV WORKDIR=/workspace WORKDIR ${WORKDIR} ARG DEBIAN_FRONTEND=noninteractive @@ -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}/ @@ -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 \ @@ -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} @@ -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 \ diff --git a/Dockerfile.ubuntu b/Dockerfile.ubuntu index 45612da..fbfbc42 100644 --- a/Dockerfile.ubuntu +++ b/Dockerfile.ubuntu @@ -1,6 +1,6 @@ FROM ubuntu:26.04 AS init -ENV WORKDIR=/app +ENV WORKDIR=/workspace WORKDIR ${WORKDIR} ARG DEBIAN_FRONTEND=noninteractive @@ -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}/ @@ -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 \ @@ -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} @@ -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 \ diff --git a/Makefile b/Makefile index 913d715..cbb151c 100644 --- a/Makefile +++ b/Makefile @@ -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 \ @@ -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 @@ -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 \ @@ -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 @@ -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 diff --git a/compose.yaml b/compose.yaml index d9f1f26..4840b7e 100644 --- a/compose.yaml +++ b/compose.yaml @@ -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: @@ -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: @@ -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: @@ -66,7 +66,7 @@ services: dockerfile: Dockerfile.${BASE_IMAGE:-alpine} target: production # volumes: - # - ./:/app + # - ./:/workspace profiles: ['production'] ## REFERENCES: