1+ // Use never version of Cake.Codecov
2+ // Can be removed once https://github.com/cake-contrib/Cake.Recipe/pull/1002 has shipped
3+ #addin nuget : ? package= Cake . Codecov & version = 1.0 .1
4+
15#load nuget: ? package = Cake . Recipe & version = 3.1 .1
26
37//*************************************************************************************************
@@ -23,6 +27,9 @@ BuildParameters.SetParameters(
2327BuildParameters. PrintParameters ( Context ) ;
2428
2529ToolSettings. SetToolPreprocessorDirectives (
30+ // Use CodecovUploader instead of unofficial Codecov exe.
31+ // Can be removed once https://github.com/cake-contrib/Cake.Recipe/pull/1002 has shipped
32+ codecovGlobalTool : "#tool nuget:?package=CodecovUploader&version=0.7.3" ,
2633 gitReleaseManagerGlobalTool : "#tool dotnet:?package=GitReleaseManager.Tool&version=0.17.0" ,
2734 nugetTool : "#tool nuget:?package=NuGet.CommandLine&version=6.9.1"
2835) ;
@@ -127,6 +134,48 @@ BuildParameters.Tasks.InspectCodeTask
127134 } )
128135) ;
129136
137+ // Updated for CodecovUploader
138+ // Can be removed once https://github.com/cake-contrib/Cake.Recipe/pull/1002 has shipped
139+ ( ( CakeTask ) BuildParameters . Tasks . UploadCodecovReportTask . Task ) . Actions . Clear ( ) ;
140+ BuildParameters. Tasks . UploadCodecovReportTask
141+ . WithCriteria ( ( ) => BuildParameters . IsMainRepository , "Skipping because not running from the main repository" )
142+ . WithCriteria ( ( ) => BuildParameters . ShouldRunCodecov , "Skipping because uploading to codecov is disabled" )
143+ . WithCriteria ( ( ) => BuildParameters . CanPublishToCodecov , "Skipping because repo token is missing, or not running on appveyor" )
144+ . Does < BuildVersion > ( ( context , buildVersion ) => RequireTool ( BuildParameters . IsDotNetCoreBuild ? ToolSettings . CodecovGlobalTool : ToolSettings . CodecovTool , ( ) => {
145+ var coverageFiles = GetFiles ( BuildParameters . Paths . Directories . TestCoverage + "/coverlet/*.xml" ) ;
146+ if ( FileExists ( BuildParameters . Paths . Files . TestCoverageOutputFilePath ) )
147+ {
148+ coverageFiles += BuildParameters . Paths . Files . TestCoverageOutputFilePath ;
149+ }
150+
151+ if ( coverageFiles . Any ( ) )
152+ {
153+ var settings = new CodecovSettings {
154+ Files = coverageFiles . Select ( f => f . FullPath ) ,
155+ Required = true ,
156+ Token = BuildParameters . Codecov . RepoToken
157+ } ;
158+ if ( buildVersion != null &&
159+ ! string . IsNullOrEmpty ( buildVersion . FullSemVersion ) &&
160+ BuildParameters . IsRunningOnAppVeyor )
161+ {
162+ // Required to work correctly with appveyor because environment changes isn't detected until cake is done running.
163+ var localBuildVersion = string . Format ( "{0}.build.{1}" ,
164+ buildVersion . FullSemVersion ,
165+ BuildSystem . AppVeyor . Environment . Build . Number ) ;
166+ settings . EnvironmentVariables = new Dictionary < string , string > { { "APPVEYOR_BUILD_VERSION" , localBuildVersion } } ;
167+ }
168+
169+ Codecov ( settings ) ;
170+ }
171+ } )
172+ ) . OnError ( exception =>
173+ {
174+ Error ( exception . Message ) ;
175+ Information ( "Upload-Codecov-Report Task failed, but continuing with next Task..." ) ;
176+ publishingError = true ;
177+ } ) ;
178+
130179// Upload only .NET 8 coverage results to avoid issues with files being too large
131180( ( CakeTask ) BuildParameters . Tasks . UploadCodecovReportTask . Task ) . Actions . Clear ( ) ;
132181BuildParameters. Tasks . UploadCodecovReportTask
0 commit comments