@@ -196,14 +196,60 @@ try
196
196
$openCoverParams.Add (' SuppressQuiet' , $true )
197
197
}
198
198
199
+ # grab the commitID, we need this to grab the right sources
200
+ $gitCommitId = & " $psBinPath \powershell.exe" - noprofile - command { $PSVersiontable.GitCommitId }
201
+ $commitId = $gitCommitId.substring ($gitCommitId.LastIndexOf (' -g' ) + 2 )
202
+
203
+ # download the src directory
204
+ try
205
+ {
206
+ $gitexe = " C:\Program Files\git\bin\git.exe"
207
+ # operations relative to where the test location is.
208
+ # some tests rely on source files being available in $outputBaseFolder/test
209
+ Push-Location $outputBaseFolder
210
+ # clean up partial repo clone before starting
211
+ if ( Test-Path " $outputBaseFolder /.git" )
212
+ {
213
+ remove-item - force - recurse " ${outputBaseFolder} /.git"
214
+ }
215
+ if ( Test-Path " $outputBaseFolder /src" )
216
+ {
217
+ remove-item - force - recurse " ${outputBaseFolder} /src"
218
+ }
219
+ Write-LogPassThru - Message " initializing repo in $outputBaseFolder "
220
+ & $gitexe init
221
+ Write-LogPassThru - Message " git operation 'init' returned $LASTEXITCODE "
222
+
223
+ Write-LogPassThru - Message " adding remote"
224
+ & $gitexe remote add origin https:// github.com / PowerShell/ PowerShell
225
+ Write-LogPassThru - Message " git operation 'remote add' returned $LASTEXITCODE "
226
+
227
+ Write-LogPassThru - Message " setting sparse-checkout"
228
+ & $gitexe config core.sparsecheckout true
229
+ Write-LogPassThru - Message " git operation 'set sparse-checkout' returned $LASTEXITCODE "
230
+
231
+ Write-LogPassThru - Message " pulling sparse repo"
232
+ " src" | out-file - encoding ascii .git\info\sparse- checkout
233
+ & $gitexe pull origin master
234
+ Write-LogPassThru - Message " git operation 'pull' returned $LASTEXITCODE "
235
+
236
+ Write-LogPassThru - Message " checkout commit $commitId "
237
+ & $gitexe checkout $commitId
238
+ Write-LogPassThru - Message " git operation 'checkout' returned $LASTEXITCODE "
239
+ }
240
+ finally
241
+ {
242
+ Pop-Location
243
+ }
244
+
199
245
$openCoverParams | Out-String | Write-LogPassThru
200
246
Write-LogPassThru - Message " Starting test run."
201
247
202
248
if (Test-Path $outputLog )
203
249
{
204
250
Remove-Item $outputLog - Force - ErrorAction SilentlyContinue
205
251
}
206
-
252
+ # now invoke opencover
207
253
Invoke-OpenCover @openCoverParams
208
254
209
255
if (Test-Path $outputLog )
213
259
214
260
Write-LogPassThru - Message " Test run done."
215
261
216
- $gitCommitId = & " $psBinPath \powershell.exe" - noprofile - command { $PSVersiontable.GitCommitId }
217
- $commitId = $gitCommitId.substring ($gitCommitId.LastIndexOf (' -g' ) + 2 )
218
-
219
262
Write-LogPassThru - Message $commitId
220
263
221
264
$coverallsPath = " $outputBaseFolder \coveralls"
@@ -242,17 +285,29 @@ try
242
285
& $coverallsExe " "" $coverallsParams "" "
243
286
244
287
Write-LogPassThru - Message " Uploading to CodeCov"
245
- ConvertTo-CodeCovJson - Path $outputLog - DestinationPath $jsonFile
246
- Push-CodeCovData - file $jsonFile - CommitID $commitId - token $codecovToken - Branch ' master'
288
+ if ( test-path $outputLog ) {
289
+ ConvertTo-CodeCovJson - Path $outputLog - DestinationPath $jsonFile
290
+ Push-CodeCovData - file $jsonFile - CommitID $commitId - token $codecovToken - Branch ' master'
247
291
248
- Write-LogPassThru - Message " Upload complete."
292
+ Write-LogPassThru - Message " Upload complete."
293
+ }
294
+ else {
295
+ Write-LogPassThru - Message " ERROR: Could not find $outputLog - no upload"
296
+ }
249
297
}
250
298
catch
251
299
{
252
300
Write-LogPassThru - Message $_
253
301
}
254
302
finally
255
303
{
304
+ # the powershell execution should be done, be sure that there are no PowerShell test executables running because
305
+ # they will cause subsequent coverage runs to behave poorly. Make sure that the path is properly formatted, and
306
+ # we need to use like rather than match because on Windows, there will be "\" as path separators which would need
307
+ # escaping for -match
308
+ $ResolvedPSBinPath = (Resolve-Path ${psbinpath} ).Path
309
+ Get-Process PowerShell | Where-Object { $_.Path -like " *${ResolvedPSBinPath} *" } | Stop-Process - Force - ErrorAction Continue
310
+
256
311
# # See if Azure log directory is mounted
257
312
if (Test-Path $azureLogDrive )
258
313
{
@@ -268,6 +323,8 @@ finally
268
323
Remove-Item - Path $destinationPath - Force - ErrorAction SilentlyContinue
269
324
}
270
325
326
+ Write-LogPassThru - Message " **** COMPLETE ****"
327
+
271
328
# # Disable the cleanup till we stabilize.
272
329
# Remove-Item -recurse -force -path $outputBaseFolder
273
330
$ErrorActionPreference = $oldErrorActionPreference
0 commit comments