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.6k stars 280 forks source link

How to add multiple assemblies in assemblyfilters #84

Closed madhurbhandarkumthe closed 5 years ago

madhurbhandarkumthe commented 7 years ago

Hi daniel,

I have two doubts

1) I want to add multiple assemblies in the assemblyfilter,but at present it only takes the first assembly For example , currrently i an using following powershell command ReportGenerator.exe" -reports:"coverage.xml" -targetdir:Coverage -assemblyfilters:-tests;-fluentassertions*

but the final report only filters out the test assemly dll and not the fluentassertions. Is there any syntax error ,if yes then please specify the correct way to do this.

2) Also is there any way to use the output of report generator to add a build failure condition in teamcity for example: If the codecoverage is 40% ,then is there any way that i can add condition in teamcity build so that this build fails for codecoverage less than say 50%.

Thanks in advance :)

danielpalme commented 7 years ago

Regarding 1. The Syntax should be correct. Can you tell me the full name of one of the assemblies that does not get filtered?

Regarding 2. You could create a custom report that passes the overall coverage ratio to TeamCity. Perhaps TeamCity is able to read the value from a text file? Or maybe you can write the value to an environment variable?!

Here's some sample code to generate a text file containing the coverage ratio:

using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using Palmmedia.ReportGenerator.Parser.Analysis;
using Palmmedia.ReportGenerator.Properties;

namespace Palmmedia.ReportGenerator.Reporting
{
    /// <summary>
    /// Creates text file containing overall coverage ratio.
    /// </summary>
    [Export(typeof(IReportBuilder))]
    public class CoverageRatioReportBuilder : IReportBuilder
    {
        /// <summary>
        /// Gets the report type.
        /// </summary>
        /// <value>
        /// The report type.
        /// </value>
        public string ReportType => "CoverageRatio";

        /// <summary>
        /// Gets or sets the target directory where reports are stored.
        /// </summary>
        /// <value>
        /// The target directory.
        /// </value>
        public string TargetDirectory { get; set; }

        /// <summary>
        /// Creates a class report.
        /// </summary>
        /// <param name="class">The class.</param>
        /// <param name="fileAnalyses">The file analyses that correspond to the class.</param>
        public void CreateClassReport(Class @class, IEnumerable<FileAnalysis> fileAnalyses)
        {
        }

        /// <summary>
        /// Creates the summary report.
        /// </summary>
        /// <param name="summaryResult">The summary result.</param>
        public void CreateSummaryReport(SummaryResult summaryResult)
        {
            if (summaryResult == null)
            {
                throw new ArgumentNullException(nameof(summaryResult));
            }

            string targetPath = Path.Combine(this.TargetDirectory, "CoverageRatio.txt");
            File.WriteAllText(targetPath, summaryResult.CoverageQuota.GetValueOrDefault().ToString("f0", CultureInfo.InvariantCulture));
        }
    }
}
madhurbhandarkumthe commented 7 years ago

1)currently the dlls which are not getting filtered out are "fluentassertions.core.dll","fluentassertions.dll". However i have noticed that if i put the assembly filters in the order assemblyfilters:-fluentassertions;-tests* then the tests dll doesn't get filtered out.so i guess currently it is only taking the first filter from the assemblyfilters list.

2)regarding the teamcity ,i will try out your solution and update you once its done.

Thanks for your quick response.

danielpalme commented 7 years ago

1) I just tried this again. It works fine for me with both filters. Can you please send me your coverage file. That would help me to debug with the same input you have.

2) That would be great

madhurbhandarkumthe commented 7 years ago

1.so the problem was with the syntax of powershell command.Had to surround assembly filter vaules with double quotes eg : -assemblyfilters:-tests;-fluentassertions didn't work. -assemblyfilters:"-tests;-fluentassertions" worked. In first case powershell considered ';' as end of statement,so only first assembly was getting filtered.

2.I wrote powershell script which had following steps i)parse the out file to get the final line coverage value ii)compare this value with the minimum required line coverage value iii)using the teamcity service message echoed error on teamcity stdout script for the same is as follows Write-Host "##teamcity[message text='errorMessage ' errorDetails='' status='ERROR']"

And in the teamcity build definition added failure condition which will check for specific text in build log.

danielpalme commented 7 years ago

Perfect, then I can close this issue?

I think double quotes work best if placed before the complete argument, e.g.:

"-assemblyfilters:-tests;-fluentassertions*"

Also see usage section here: https://github.com/danielpalme/ReportGenerator#usage

TroySchmidt commented 5 years ago

Need to reopen this. When using the Azure DevOps Extension there is no way for you to surround the parameters with " so it always only picks the first exclude (or include). There isn't a way to supply multiple filters.

danielpalme commented 5 years ago

I will investigate this within the next days.

danielpalme commented 5 years ago

Could you please try again by triggering the build on Azure DevOps? I published a new release which should fix the issue.

TroySchmidt commented 5 years ago

Tested it and doesn't appear to be fixed. This is what is showing in the log for the translated command line that gets executed.

This is my task in the YAML.

- task: reportgenerator@4
    inputs:
      reports: '$(Build.SourcesDirectory)/**/coverage.cobertura.xml'
      targetdir: '$(Build.SourcesDirectory)/CodeCoverage'
      reporttypes: 'HtmlInline_AzurePipelines_Dark;Cobertura;Badges'
      assemblyfilters: '-Dapper.*;-Dommel.*'
:\Program Files\dotnet\dotnet.exe" D:\agent\_work\_tasks\reportgenerator_be803a55-9253-4895-a525-be570d86f161\4.2.7\tools\netcoreapp2.1\ReportGenerator.dll "\"-reports:D:\agent\_work\10\s/**/coverage.cobertura.xml\"" "\"-targetdir:D:\agent\_work\10\s/CodeCoverage\"" "\"-reporttypes:HtmlInline_AzurePipelines_Dark;Cobertura;Badges\"" "\"-sourcedirs:\"" "\"-historydir:\"" "\"-plugins:\"" "\"-assemblyfilters:-Dapper.*;-Dommel.*\"" "\"-classfilters:+*\"" "\"-filefilters:+*\"" "\"-verbosity:Verbose\"" "\"-tag:RCRMS Release Build_#1432\""
danielpalme commented 5 years ago

Can you please test once again. The log should now contain the list of arguments that ReportGenerator receives. E.g.

Arguments
 -reports:coverage.cobertura.xml
 -targetdir:CodeCoverage
 -reporttypes:HtmlInline_AzurePipelines_Dark;Cobertura;Badges
 -sourcedirs:
 -historydir:
 -plugins:
 -assemblyfilters:-Dapper.*;-Dommel.*
 -filefilters:+*
 -verbosity:Verbose
 -tag:RCRMS Release Build_#1432
TroySchmidt commented 5 years ago

:\Program Files\dotnet\dotnet.exe" D:\agent\_work\_tasks\reportgenerator_be803a55-9253-4895-a525-be570d86f161\4.2.8\tools\netcoreapp2.1\ReportGenerator.dll -reports:D:\agent\_work\10\s/**/coverage.cobertura.xml -targetdir:D:\agent\_work\10\s/CodeCoverage -reporttypes:HtmlInline_AzurePipelines_Dark;Cobertura;Badges -sourcedirs: -historydir: -plugins: -assemblyfilters:-Dapper.*;-Dommel.* -classfilters:+* -filefilters:+* -verbosity:Verbose "-tag:RCRMS Release Build_#1435" |  
-- | --
  | Arguments |  
  | -reports:D:\agent\_work\10\s/**/coverage.cobertura.xml |  
  | -targetdir:D:\agent\_work\10\s/CodeCoverage |  
  | -reporttypes:HtmlInline_AzurePipelines_Dark;Cobertura;Badges |  
  | -sourcedirs: |  
  | -historydir: |  
  | -plugins: |  
  | -assemblyfilters:-Dapper.*;-Dommel.* |  
  | -classfilters:+* |  
  | -filefilters:+* |  
  | -verbosity:Verbose |  
  | -tag:RCRMS Release Build_#1435 |  
  | Loading report 'D:\agent\_work\10\s\Tests\Rcrms.DataAccess.Tests\coverage.cobertura.xml' 1/2 |  
  | Preprocessing report |  
  | Initiating parser for Cobertura |  
  | Current Assembly: Dommel |  
  | Current Assembly: Rcrms.DataAccess |  
  | Current Assembly: Rcrms.Entities |  
  | Loading report 'D:\agent\_work\10\s\Tests\Rcrms.DataAccess.Tests\results\coverage.cobertura.xml' 2/2 |  
  | Preprocessing report |  
  | Initiating parser for Cobertura |  
  | Current Assembly: Dommel |  
  | Current Assembly: Rcrms.DataAccess |  
  | Current Assembly: Rcrms.Entities |  
  | Coverage report parsing took 0.4 seconds |  
  | Initializing report builders for report types: HtmlInline_AzurePipelines_Dark, Cobertura, Badges |  
  | Analyzing 216 classes |  
  | Creating report 1/216 (Assembly: Dommel, Class: Dommel.DefaultColumnNameResolver) |  
  | Writing report file 'Dommel_DefaultColumnNameResolver.htm' |  
  | Creating report 2/216 (Assembly: Dommel, Class: Dommel.DefaultForeignKeyPropertyResolver) |  
  | Writing report file 'Dommel_DefaultForeignKeyPropertyResolver.htm' |  
  | Creating report 3/216 (Assembly: Dommel, Class: Dommel.DefaultKeyPropertyResolver)

Still not working. It isn't wrapping the assemblyfilters option in quotes. So it still only processes the -Dapper.* and not the second -Dommel.* filter. Is there a different separator besides ; to use? What I understand that might resolve this is if the entire assemblyfilters option was surrounded with quotes(") in the command line where it passes it to the DLL. That still isn't happening right now when using the task. That still isn't wrapped. It could also be there is a problem with dotnet.exe and the additional parameters passing that is filtering it out when there is a semicolon.

danielpalme commented 5 years ago

Ok, The arguments seem to get passed correctly to ReportGeneratorr:

| -assemblyfilters:-Dapper.*;-Dommel.* |  

The problem is probably the filter definition itself. The filters are not interpreted as regular expressions but as text with wildcards. In your case Dommel.* does not match the assembly Dommel, it would only match Dommel.XYZ.

If you change the filter to -assemblyfilters:-Dapper.*;-Dommel or -assemblyfilters:-Dapper.*;-Dommel* it should work as expected.

TroySchmidt commented 5 years ago

That makes sense. Will retest and report.

On Fri, Jul 12, 2019, 3:03 AM Daniel Palme notifications@github.com wrote:

Ok, The arguments seem to get passed correctly to ReportGeneratorr:

| -assemblyfilters:-Dapper.;-Dommel. |

The problem is probably the filter definition itself. The filters are not interpreted as regular expressions but as text with wildcards. In your case Dommel.* does not match the assembly Dommel, it would only match Dommel.XYZ.

If you change the filter to -assemblyfilters:-Dapper.;-Dommel or -assemblyfilters:-Dapper.;-Dommel* it should work as expected.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/danielpalme/ReportGenerator/issues/84?email_source=notifications&email_token=AALXG3JHSNM4XDRW4R6C3ODP7AUFTA5CNFSM4DBL3H7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZY4MUA#issuecomment-510772816, or mute the thread https://github.com/notifications/unsubscribe-auth/AALXG3OKAPL7LVTPVZGCWQLP7AUFTANCNFSM4DBL3H7A .

TroySchmidt commented 5 years ago

Close this as resolved. Works!! Thanks so much!