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.56k stars 279 forks source link

[Azure Devops] Combination of filefilters and sourcedirs filter out everything #678

Closed Suchomel closed 2 months ago

Suchomel commented 2 months ago

I use filefilters and sourcedirs in same time, report is generated but all files are filtered out. When I use only filefilters, in summary is correctly filtered and on the detail is not visible covered lines. And when I use only sourcedirs the covered files are visible in the detail but of course files on summary are not filtered.

I use it for filter PR changed files in code coverage.

Yaml Pipeline:

          - task: Bash@3
            displayName: "Prepare variables"
            inputs:
              targetType: 'inline'
              script: |
                filefilters=$(git diff --name-only origin/"$TARGET_BRANCH_NAME" HEAD | grep '\.kt$' | sed 's|.*/||' | sed 's/^/+/' | tr '\n' ';')
                echo "##vso[task.setvariable variable=filefilters]$filefilters"
                sourcedirs=$(git diff --name-only origin/"$TARGET_BRANCH_NAME" HEAD | grep '\.kt$' | sed 's|/kotlin/.*$|/kotlin/|' | sed "s|^|$DEFAULT_WORKING_DIR/|g" | tr '\n' ';')
                echo "##vso[task.setvariable variable=sourcedirs]$sourcedirs"

          - task: reportgenerator@5
            displayName: "Code coverage report"
            inputs:
              reports: '$(System.DefaultWorkingDirectory)/android/library/code-coverage/build/reports/kover/report.xml;'
              filefilters: '$(filefilters)'
              sourcedirs: '$(sourcedirs)'
              reporttypes: 'HtmlInline_AzurePipelines;Cobertura'
              publishCodeCoverageResults: true
danielpalme commented 2 months ago

Can you share a (minimal) coverage file and the filefilters and sourcedirs you are using? This would make it easier for me to reproduce your scenario.

Suchomel commented 2 months ago

filefilters

+GradleConfigurations.kt;+GradleExtensions.kt;+ProjectExtensions.kt;+AndroidApplicationPlugin.kt;+AndroidLibraryPlugin.kt;+MultiplatformLibraryPlugin.kt;+IsFeatureEnabledUseCase.kt;

sourcedirs

/Users/administrator/myagent/_work/2/s/gradle-config/src/main/kotlin/;/Users/administrator/myagent/_work/2/s/gradle-config/src/main/kotlin/;/Users/administrator/myagent/_work/2/s/gradle-config/src/main/kotlin/;/Users/administrator/myagent/_work/2/s/gradle-config/src/main/kotlin/;/Users/administrator/myagent/_work/2/s/gradle-config/src/main/kotlin/;/Users/administrator/myagent/_work/2/s/gradle-config/src/main/kotlin/;/Users/administrator/myagent/_work/2/s/multiplatform/library/feature-flag/src/commonMain/kotlin/;
danielpalme commented 2 months ago

If you prefix your filefilters with a * it should work.

In your example this would result in the following filefilters:

+*GradleConfigurations.kt;+*GradleExtensions.kt;+*ProjectExtensions.kt;+*AndroidApplicationPlugin.kt;+*AndroidLibraryPlugin.kt;+*MultiplatformLibraryPlugin.kt;+*IsFeatureEnabledUseCase.kt;

Does this work for you?

Suchomel commented 2 months ago

It's working. I don't expect that the "file" changed on add source path :)

Thank you so much.

danielpalme commented 2 months ago

Great that it works for you. Before the XML file gets processed, the files links are searched on disk and the path in the XML in modified. Therefore the path changes in the process.