22#tool dotnet : ? package= GitVersion . Tool & version = 5.12 .0
33#tool dotnet: ? package = coveralls . net & version = 4.0 .1
44#tool nuget: ? package = GitReleaseManager & version = 0.13 .0
5- #tool nuget: ? package = ReportGenerator & version = 5.1 .16
5+ #tool nuget: ? package = ReportGenerator & version = 5.1 .21
66#tool nuget: ? package = xunit . runner . console & version = 2.4 .2
77#tool nuget: ? package = Codecov & version = 1.13 .0
88
@@ -66,6 +66,7 @@ var sourceFolder = "./Source/";
6666var outputDir = "./artifacts/" ;
6767var codeCoverageDir = $"{outputDir}CodeCoverage/" ;
6868var benchmarkDir = $"{outputDir}Benchmark/" ;
69+ var coverageFile = $"{codeCoverageDir}coverage.{DefaultFramework}.xml" ;
6970
7071var solutionFile = $"{sourceFolder}{libraryName}.sln" ;
7172var sourceProject = $"{sourceFolder}{libraryName}/{libraryName}.csproj" ;
@@ -85,13 +86,15 @@ var isIntegrationTestsProjectPresent = FileExists(integrationTestsProject);
8586var isUnitTestsProjectPresent = FileExists ( unitTestsProject ) ;
8687var isBenchmarkProjectPresent = FileExists ( benchmarkProject ) ;
8788
89+ var publishingError = false;
90+
8891// Generally speaking, we want to honor all the TFM configured in the source project and the unit test project.
8992// However, there are a few scenarios where a single framework is sufficient. Here are a few examples that come to mind:
9093// - when building source project on Ubuntu
9194// - when running unit tests on Ubuntu
9295// - when calculating code coverage
9396// FYI, this will cause an error if the source project and/or the unit test project are not configured to target this desired framework:
94- const string DefaultFramework = "net6 .0" ;
97+ const string DefaultFramework = "net7 .0" ;
9598var desiredFramework = (
9699 ! IsRunningOnWindows ( ) ||
97100 target . Equals ( "Coverage" , StringComparison . OrdinalIgnoreCase ) ||
@@ -257,6 +260,7 @@ Task("Build")
257260} ) ;
258261
259262Task( "Run-Unit-Tests" )
263+ . WithCriteria ( ( ) => isUnitTestsProjectPresent )
260264 . IsDependentOn ( "Build" )
261265 . Does ( ( ) =>
262266{
@@ -270,6 +274,7 @@ Task("Run-Unit-Tests")
270274} ) ;
271275
272276Task( "Run-Code-Coverage" )
277+ . WithCriteria ( ( ) => isUnitTestsProjectPresent )
273278 . IsDependentOn ( "Build" )
274279 . Does ( ( ) =>
275280{
@@ -297,29 +302,46 @@ Task("Run-Code-Coverage")
297302
298303Task( "Upload-Coverage-Result-Coveralls" )
299304 . IsDependentOn ( "Run-Code-Coverage" )
300- . OnError ( exception => Information ( $ "ONERROR: Failed to upload coverage result to Coveralls: { exception . Message } ") )
305+ . WithCriteria ( ( ) => FileExists ( coverageFile ) )
306+ . WithCriteria ( ( ) => ! isLocalBuild )
307+ . WithCriteria ( ( ) => ! isPullRequest )
308+ . WithCriteria ( ( ) => isMainRepo )
301309 . Does ( ( ) =>
302310{
303- //CoverallsNet(new FilePath($"{codeCoverageDir}coverage.{DefaultFramework}.xml"), CoverallsNetReportType.OpenCover, new CoverallsNetSettings()
304- //{
305- // RepoToken = coverallsToken
306- //});
311+ CoverallsNet ( new FilePath ( coverageFile ) , CoverallsNetReportType . OpenCover , new CoverallsNetSettings ( )
312+ {
313+ RepoToken = coverallsToken ,
314+ UseRelativePaths = true
315+ } ) ;
316+ } ) . OnError ( exception =>
317+ {
318+ Error ( exception . Message ) ;
319+ Information ( $ "Failed to upload coverage result to Coveralls, but continuing with next Task...") ;
320+ publishingError = true ;
307321} ) ;
308322
309323Task( "Upload-Coverage-Result-Codecov" )
310324 . IsDependentOn ( "Run-Code-Coverage" )
311- . OnError ( exception => Information ( $ "ONERROR: Failed to upload coverage result to Codecov: { exception . Message } ") )
325+ . WithCriteria ( ( ) => FileExists ( coverageFile ) )
326+ . WithCriteria ( ( ) => ! isLocalBuild )
327+ . WithCriteria ( ( ) => ! isPullRequest )
328+ . WithCriteria ( ( ) => isMainRepo )
312329 . Does ( ( ) =>
313330{
314- //Codecov($"{codeCoverageDir}coverage.{DefaultFramework}.xml", codecovToken);
331+ Codecov ( coverageFile , codecovToken ) ;
332+ } ) . OnError ( exception =>
333+ {
334+ Error ( exception . Message ) ;
335+ Information ( $ "Failed to upload coverage result to Codecov, but continuing with next Task...") ;
336+ publishingError = true ;
315337} ) ;
316338
317339Task( "Generate-Code-Coverage-Report" )
318340 . IsDependentOn ( "Run-Code-Coverage" )
319341 . Does ( ( ) =>
320342{
321343 ReportGenerator (
322- new FilePath ( $ " { codeCoverageDir } coverage. { DefaultFramework } .xml" ) ,
344+ new FilePath ( coverageFile ) ,
323345 codeCoverageDir ,
324346 new ReportGeneratorSettings ( ) {
325347 ClassFilters = new [ ] { "*.UnitTests*" }
@@ -513,7 +535,14 @@ Task("AppVeyor")
513535 . IsDependentOn ( "Upload-AppVeyor-Artifacts" )
514536 . IsDependentOn ( "Publish-MyGet" )
515537 . IsDependentOn ( "Publish-NuGet" )
516- . IsDependentOn ( "Publish-GitHub-Release" ) ;
538+ . IsDependentOn ( "Publish-GitHub-Release" )
539+ . Finally ( ( ) =>
540+ {
541+ if ( publishingError )
542+ {
543+ throw new Exception ( "An error occurred during the publishing of [Http-Multipart-Data-Parser]. All publishing tasks have been attempted." ) ;
544+ }
545+ } ) ;
517546
518547Task( "Default" )
519548 . IsDependentOn ( "Run-Unit-Tests" )
0 commit comments