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
+
1
5
#load nuget: ? package = Cake . Recipe & version = 3.1 .1
2
6
3
7
//*************************************************************************************************
@@ -23,6 +27,9 @@ BuildParameters.SetParameters(
23
27
BuildParameters. PrintParameters ( Context ) ;
24
28
25
29
ToolSettings. 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" ,
26
33
gitReleaseManagerGlobalTool : "#tool dotnet:?package=GitReleaseManager.Tool&version=0.17.0" ,
27
34
nugetTool : "#tool nuget:?package=NuGet.CommandLine&version=6.9.1"
28
35
) ;
@@ -127,6 +134,43 @@ BuildParameters.Tasks.InspectCodeTask
127
134
} )
128
135
) ;
129
136
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
+ ) ;
173
+
130
174
// Upload only .NET 8 coverage results to avoid issues with files being too large
131
175
( ( CakeTask ) BuildParameters . Tasks . UploadCodecovReportTask . Task ) . Actions . Clear ( ) ;
132
176
BuildParameters. Tasks . UploadCodecovReportTask
0 commit comments