Skip to content

Commit

Permalink
Add source files for coverage run (PowerShell#4925)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JamesWTruher authored and adityapatwardhan committed Sep 27, 2017
1 parent df1993a commit d20d6a6
Showing 1 changed file with 64 additions and 7 deletions.
71 changes: 64 additions & 7 deletions test/tools/CodeCoverageAutomation/Start-CodeCoverageRun.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,60 @@ try
$openCoverParams.Add('SuppressQuiet', $true)
}

# grab the commitID, we need this to grab the right sources
$gitCommitId = & "$psBinPath\powershell.exe" -noprofile -command { $PSVersiontable.GitCommitId }
$commitId = $gitCommitId.substring($gitCommitId.LastIndexOf('-g') + 2)

# download the src directory
try
{
$gitexe = "C:\Program Files\git\bin\git.exe"
# operations relative to where the test location is.
# some tests rely on source files being available in $outputBaseFolder/test
Push-Location $outputBaseFolder
# clean up partial repo clone before starting
if ( Test-Path "$outputBaseFolder/.git" )
{
remove-item -force -recurse "${outputBaseFolder}/.git"
}
if ( Test-Path "$outputBaseFolder/src" )
{
remove-item -force -recurse "${outputBaseFolder}/src"
}
Write-LogPassThru -Message "initializing repo in $outputBaseFolder"
& $gitexe init
Write-LogPassThru -Message "git operation 'init' returned $LASTEXITCODE"

Write-LogPassThru -Message "adding remote"
& $gitexe remote add origin https://github.com/PowerShell/PowerShell
Write-LogPassThru -Message "git operation 'remote add' returned $LASTEXITCODE"

Write-LogPassThru -Message "setting sparse-checkout"
& $gitexe config core.sparsecheckout true
Write-LogPassThru -Message "git operation 'set sparse-checkout' returned $LASTEXITCODE"

Write-LogPassThru -Message "pulling sparse repo"
"src" | out-file -encoding ascii .git\info\sparse-checkout
& $gitexe pull origin master
Write-LogPassThru -Message "git operation 'pull' returned $LASTEXITCODE"

Write-LogPassThru -Message "checkout commit $commitId"
& $gitexe checkout $commitId
Write-LogPassThru -Message "git operation 'checkout' returned $LASTEXITCODE"
}
finally
{
Pop-Location
}

$openCoverParams | Out-String | Write-LogPassThru
Write-LogPassThru -Message "Starting test run."

if(Test-Path $outputLog)
{
Remove-Item $outputLog -Force -ErrorAction SilentlyContinue
}

# now invoke opencover
Invoke-OpenCover @openCoverParams

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

Write-LogPassThru -Message "Test run done."

$gitCommitId = & "$psBinPath\powershell.exe" -noprofile -command { $PSVersiontable.GitCommitId }
$commitId = $gitCommitId.substring($gitCommitId.LastIndexOf('-g') + 2)

Write-LogPassThru -Message $commitId

$coverallsPath = "$outputBaseFolder\coveralls"
Expand All @@ -242,17 +285,29 @@ try
& $coverallsExe """$coverallsParams"""

Write-LogPassThru -Message "Uploading to CodeCov"
ConvertTo-CodeCovJson -Path $outputLog -DestinationPath $jsonFile
Push-CodeCovData -file $jsonFile -CommitID $commitId -token $codecovToken -Branch 'master'
if ( test-path $outputLog ) {
ConvertTo-CodeCovJson -Path $outputLog -DestinationPath $jsonFile
Push-CodeCovData -file $jsonFile -CommitID $commitId -token $codecovToken -Branch 'master'

Write-LogPassThru -Message "Upload complete."
Write-LogPassThru -Message "Upload complete."
}
else {
Write-LogPassThru -Message "ERROR: Could not find $outputLog - no upload"
}
}
catch
{
Write-LogPassThru -Message $_
}
finally
{
# the powershell execution should be done, be sure that there are no PowerShell test executables running because
# they will cause subsequent coverage runs to behave poorly. Make sure that the path is properly formatted, and
# we need to use like rather than match because on Windows, there will be "\" as path separators which would need
# escaping for -match
$ResolvedPSBinPath = (Resolve-Path ${psbinpath}).Path
Get-Process PowerShell | Where-Object { $_.Path -like "*${ResolvedPSBinPath}*" } | Stop-Process -Force -ErrorAction Continue

## See if Azure log directory is mounted
if(Test-Path $azureLogDrive)
{
Expand All @@ -268,6 +323,8 @@ finally
Remove-Item -Path $destinationPath -Force -ErrorAction SilentlyContinue
}

Write-LogPassThru -Message "**** COMPLETE ****"

## Disable the cleanup till we stabilize.
#Remove-Item -recurse -force -path $outputBaseFolder
$ErrorActionPreference = $oldErrorActionPreference
Expand Down

0 comments on commit d20d6a6

Please sign in to comment.