Skip to content

Commit d20d6a6

Browse files
JamesWTruheradityapatwardhan
authored andcommitted
Add source files for coverage run (PowerShell#4925)
A number of tests require the sources to be present in order to work correctly. During cleanup be sure to remove any lingering powershell.exe processes because subsequent runs will not be able to update the test binaries.
1 parent df1993a commit d20d6a6

File tree

1 file changed

+64
-7
lines changed

1 file changed

+64
-7
lines changed

test/tools/CodeCoverageAutomation/Start-CodeCoverageRun.ps1

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,60 @@ try
196196
$openCoverParams.Add('SuppressQuiet', $true)
197197
}
198198

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+
199245
$openCoverParams | Out-String | Write-LogPassThru
200246
Write-LogPassThru -Message "Starting test run."
201247

202248
if(Test-Path $outputLog)
203249
{
204250
Remove-Item $outputLog -Force -ErrorAction SilentlyContinue
205251
}
206-
252+
# now invoke opencover
207253
Invoke-OpenCover @openCoverParams
208254

209255
if(Test-Path $outputLog)
@@ -213,9 +259,6 @@ try
213259

214260
Write-LogPassThru -Message "Test run done."
215261

216-
$gitCommitId = & "$psBinPath\powershell.exe" -noprofile -command { $PSVersiontable.GitCommitId }
217-
$commitId = $gitCommitId.substring($gitCommitId.LastIndexOf('-g') + 2)
218-
219262
Write-LogPassThru -Message $commitId
220263

221264
$coverallsPath = "$outputBaseFolder\coveralls"
@@ -242,17 +285,29 @@ try
242285
& $coverallsExe """$coverallsParams"""
243286

244287
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'
247291

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+
}
249297
}
250298
catch
251299
{
252300
Write-LogPassThru -Message $_
253301
}
254302
finally
255303
{
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+
256311
## See if Azure log directory is mounted
257312
if(Test-Path $azureLogDrive)
258313
{
@@ -268,6 +323,8 @@ finally
268323
Remove-Item -Path $destinationPath -Force -ErrorAction SilentlyContinue
269324
}
270325

326+
Write-LogPassThru -Message "**** COMPLETE ****"
327+
271328
## Disable the cleanup till we stabilize.
272329
#Remove-Item -recurse -force -path $outputBaseFolder
273330
$ErrorActionPreference = $oldErrorActionPreference

0 commit comments

Comments
 (0)