From ead4df409748b3347af04977a06b3c16a75a3000 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Wed, 23 Nov 2016 12:22:18 -0800 Subject: [PATCH] Moved publishing of code coverage artifacts to test_script phase (#2760) * Moved publishing of code coverage artifacts to after_test phase The webhook for build completion is called after the after_test phase hence we needed to publish code coverage artifacts before that. Moved the logic for compression and publish the artifacts after running tests. * Added check for daily build * Address code review comments. * Addressed code review comments Addressed comments about definition of artifacts. Defined new function for after_test phase. --- appveyor.yml | 3 +++ tools/appveyor.psm1 | 65 ++++++++++++++++++++++++++++++--------------- 2 files changed, 46 insertions(+), 22 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 5cc8bc0b7..2682dd618 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,5 +20,8 @@ build_script: test_script: - ps: Invoke-AppveyorTest +after_test: + - ps: Invoke-AppVeyorAfterTest + on_finish: - ps: Invoke-AppveyorFinish diff --git a/tools/appveyor.psm1 b/tools/appveyor.psm1 index 033415d86..4fe0c2496 100644 --- a/tools/appveyor.psm1 +++ b/tools/appveyor.psm1 @@ -326,9 +326,6 @@ function Invoke-AppVeyorTest Write-Host -Foreground Green 'Upload FullCLR test results' Update-AppVeyorTestResults -resultsFile $testResultsFileFullCLR - ## CodeCoverage - $env:CodeCoverageOutput = Split-Path -Parent (Get-PSOutput -Options (New-PSOptions -Configuration CodeCoverage)) - # # Fail the build, if tests failed @( @@ -342,6 +339,49 @@ function Invoke-AppVeyorTest Set-BuildVariable -Name TestPassed -Value True } +#Implement AppVeyor 'after_test' phase +function Invoke-AppVeyorAfterTest +{ + [CmdletBinding()] + param() + + if(Test-DailyBuild) + { + ## Publish code coverage build, tests and OpenCover module to artifacts, so webhook has the information. + ## Build webhook is called after 'after_test' phase, hence we need to do this here and not in AppveyorFinish. + $codeCoverageOutput = Split-Path -Parent (Get-PSOutput -Options (New-PSOptions -Configuration CodeCoverage)) + $codeCoverageArtifacts = Compress-CoverageArtifacts -CodeCoverageOutput $codeCoverageOutput + + Write-Host -ForegroundColor Green 'Upload CodeCoverage artifacts' + $codeCoverageArtifacts | % { Push-AppveyorArtifact $_ } + } +} + +function Compress-CoverageArtifacts +{ + param([string] $CodeCoverageOutput) + + # Create archive for test content, OpenCover module and CodeCoverage build + $artifacts = New-Object System.Collections.ArrayList + + $zipTestContentPath = Join-Path $pwd 'tests.zip' + Compress-TestContent -Destination $zipTestContentPath + $artifacts.Add($zipTestContentPath) + + Add-Type -AssemblyName System.IO.Compression.FileSystem + $resolvedPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath((Join-Path $PSScriptRoot '..\test\tools\OpenCover')) + $zipOpenCoverPath = Join-Path $pwd 'OpenCover.zip' + [System.IO.Compression.ZipFile]::CreateFromDirectory($resolvedPath, $zipOpenCoverPath) + $artifacts.Add($zipOpenCoverPath) + + $zipCodeCoveragePath = Join-Path $pwd "$name.CodeCoverage.zip" + Write-Verbose "Zipping ${CodeCoverageOutput} into $zipCodeCoveragePath" -verbose + [System.IO.Compression.ZipFile]::CreateFromDirectory($CodeCoverageOutput, $zipCodeCoveragePath) + $artifacts.Add($zipCodeCoveragePath) + + return $artifacts +} + # Implements AppVeyor 'on_finish' step function Invoke-AppveyorFinish { @@ -373,25 +413,6 @@ function Invoke-AppveyorFinish $artifacts.Add($zipFilePath) $artifacts.Add($zipFileFullPath) - # Create archive for test content, OpenCover module and CodeCoverage build - if(Test-DailyBuild) - { - $zipTestContentPath = Join-Path $pwd 'tests.zip' - Compress-TestContent -Destination $zipTestContentPath - $artifacts.Add($zipTestContentPath) - - Add-Type -AssemblyName System.IO.Compression.FileSystem - $resolvedPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath((Join-Path $PSScriptRoot '..\test\tools\OpenCover')) - $zipOpenCoverPath = Join-Path $pwd 'OpenCover.zip' - [System.IO.Compression.ZipFile]::CreateFromDirectory($resolvedPath, $zipOpenCoverPath) - $artifacts.Add($zipOpenCoverPath) - - $zipCodeCoveragePath = Join-Path $pwd "$name.CodeCoverage.zip" - Write-Verbose "Zipping ${env:CodeCoverageOutput} into $zipCodeCoveragePath" -verbose - [System.IO.Compression.ZipFile]::CreateFromDirectory($env:CodeCoverageOutput, $zipCodeCoveragePath) - $artifacts.Add($zipCodeCoveragePath) - } - if ($env:APPVEYOR_REPO_TAG_NAME) { # ignore the first part of semver, use the preview part