danielpalme / ReportGenerator

ReportGenerator converts coverage reports generated by coverlet, OpenCover, dotCover, Visual Studio, NCover, Cobertura, JaCoCo, Clover, gcov or lcov into human readable reports in various formats.
https://reportgenerator.io
Apache License 2.0
2.58k stars 281 forks source link

Issue with running the report generator in docker with image "mcr.microsoft.com/dotnet/sdk:7.0" #617

Closed ferryferry closed 1 year ago

ferryferry commented 1 year ago

Describe the bug We are using the report tool already a couple of years in all our .NET services in a docker build scenario. We are piloting .NET 7 to later target .NET 8 in our images and I faced an issue in the report generator targeting the dotnet/sdk:7.0 image.

I took a look in our existing microservice Dockerfiles (which do work) and it looks like this: RUN dotnet test "./path-to-csproj.csproj" --collect:"XPlat Code Coverage" -c Release --logger:"trx;LogFileName=api-results.xml" -r ./test-results/api-tests; exit 0

RUN dotnet test "./path-to-csproj.csproj" --collect:"XPlat Code Coverage" -c Release --logger:"trx;LogFileName=api-results.xml" -r ./test-results/service-tests; exit 0

RUN dotnet tool install -g dotnet-reportgenerator-globaltool && \ export PATH="$PATH:/root/.dotnet/tools" && \ reportgenerator "-reports:./test-results/**/coverage.cobertura.xml" "-targetdir:./test-results/coverage-report" -reporttypes:cobertura

So, this works perfectly fine in the "mcr.microsoft.com/dotnet/sdk:6.0" image but not in the "mcr.microsoft.com/dotnet/sdk:7.0" image. So only thing to get it to fail is to change the dotnet sdk version from 6 to 7.

To Reproduce The following input helps to reproduce your issue:

  1. Console output of ReportGenerator
 => ERROR [tests 5/5] RUN dotnet tool install -g dotnet-reportgenerator-globaltool &&   export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.dotnet/tools" &&   reportgenerator "-reports:./test  6.4s
------
 > [tests 5/5] RUN dotnet tool install -g dotnet-reportgenerator-globaltool &&   export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.dotnet/tools" &&   reportgenerator "-reports:./test-results/**/coverage.cobertura.xml" "-targetdir:./test-results/coverage-report" -reporttypes:cobertura:
6.131 Tools directory '/root/.dotnet/tools' is not currently on the PATH environment variable.
6.131 If you are using bash, you can add it to your profile by running the following command:
6.131 
6.131 cat << \EOF >> ~/.bash_profile
6.131 # Add .NET Core SDK tools
6.131 export PATH="$PATH:/root/.dotnet/tools"
6.131 EOF
6.131 
6.131 You can add it to the current session by running the following command:
6.131 
6.131 export PATH="$PATH:/root/.dotnet/tools"
6.131 
6.134 You can invoke the tool using the following command: reportgenerator
6.134 Tool 'dotnet-reportgenerator-globaltool' (version '5.1.23') was successfully installed.
6.221 2023-08-08T09:14:54: Arguments
6.221 2023-08-08T09:14:54:  -reports:./test-results/**/coverage.cobertura.xml
6.221 2023-08-08T09:14:54:  -targetdir:./test-results/coverage-report
6.221 2023-08-08T09:14:54:  -reporttypes:cobertura
6.315 2023-08-08T09:14:54: The report file pattern './test-results/**/coverage.cobertura.xml' found no matching files.
6.315 2023-08-08T09:14:54: No report files specified.
------
ferryferry commented 1 year ago

Never mind, I see the behaviour changed around the -r parameter: see here: https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-test#options

So this now works:


COPY "./dotnet/UserDocuments/Paragon.UserDocuments.Tests" "./dotnet/UserDocuments/Paragon.UserDocuments.Tests"
RUN dotnet test "./dotnet/UserDocuments/Paragon.UserDocuments.Tests/Paragon.UserDocuments.Tests.csproj" --collect:"XPlat Code Coverage" -c Release --logger:"trx;LogFileName=coverage-results.xml" --results-directory ./test-results; exit 0
RUN dotnet tool install -g dotnet-reportgenerator-globaltool && \
  export PATH="$PATH:/root/.dotnet/tools" && \
  reportgenerator "-reports:./test-results/**/coverage-results.xml" "-targetdir:./test-results/coverage-report" -reporttypes:cobertura```
danielpalme commented 1 year ago

Great that you figured it out!