Add support for running all tests on scheduled builds

Only produce nuget packages if tests pass
This commit is contained in:
Travis Plunk 2016-08-31 13:02:12 -07:00
parent 55f78781e9
commit 0d5ae4692b

View file

@ -3,14 +3,79 @@ $repoRoot = Join-Path $PSScriptRoot '..'
Import-Module (Join-Path $repoRoot 'build.psm1')
# tests if we should run a daily build
# returns true if the build is scheduled
# or is a pushed tag
Function Test-DailyBuild
{
if($env:APPVEYOR_SCHEDULED_BUILD -eq 'True')
{
return $true
}
if($env:APPVEYOR_REPO_TAG_NAME)
{
return $true
}
return $false
}
# Sets a build variable
Function Set-BuildVariable
{
param(
[Parameter(Mandatory=$true)]
[string]
$Name,
[Parameter(Mandatory=$true)]
[string]
$Value
)
if($env:AppVeyor)
{
Set-AppveyorBuildVariable @PSBoundParameters
}
else
{
Set-Item env:/$name -Value $Value
}
}
# Emulates running all of AppVeyor but locally
# should not be used on AppVeyor
function Invoke-AppVeyorFull
{
Invoke-AppVeyorInstall
Invoke-AppVeyorBuild
Invoke-AppVeyorTest -ErrorAction Continue
Invoke-AppveyorFinish
param(
[switch] $APPVEYOR_SCHEDULED_BUILD,
[switch] $CleanRepo
)
if($CleanRepo)
{
Clear-PSRepo
}
if($env:APPVEYOR)
{
throw "This function is to simulate appveyor, but not to be run from appveyor!"
}
if($APPVEYOR_SCHEDULED_BUILD)
{
$env:APPVEYOR_SCHEDULED_BUILD = 'True'
}
try {
Invoke-AppVeyorInstall
Invoke-AppVeyorBuild
Invoke-AppVeyorTest -ErrorAction Continue
Invoke-AppveyorFinish
}
finally {
if($APPVEYOR_SCHEDULED_BUILD -and $env:APPVEYOR_SCHEDULED_BUILD)
{
Remove-Item env:APPVEYOR_SCHEDULED_BUILD
}
}
}
# Implements the AppVeyor 'build_script' step
@ -29,6 +94,21 @@ function Invoke-AppVeyorBuild
# Implements the AppVeyor 'install' step
function Invoke-AppVeyorInstall
{
if(Test-DailyBuild){
$buildName = "[Daily]"
if($env:APPVEYOR_PULL_REQUEST_TITLE)
{
$buildName += $env:APPVEYOR_PULL_REQUEST_TITLE
}
else
{
$buildName += $env:APPVEYOR_REPO_COMMIT_MESSAGE
}
Update-AppveyorBuild -message $buildName
}
Set-BuildVariable -Name TestPassed -Value False
Start-PSBootstrap -Force
}
@ -90,6 +170,7 @@ function Invoke-AppVeyorTest
param()
#
# CoreCLR
$env:CoreOutput = Split-Path -Parent (Get-PSOutput -Options (New-PSOptions -Publish -Configuration $buildConfiguration))
Write-Host -Foreground Green 'Run CoreCLR tests'
$testResultsFile = "$pwd\TestsResults.xml"
@ -98,7 +179,23 @@ function Invoke-AppVeyorTest
throw "CoreCLR PowerShell.exe was not built"
}
Start-PSPester -bindir $env:CoreOutput -outputFile $testResultsFile
$coreClrTestParams = @{
Tag = @('CI')
ExcludeTag = @('Slow')
}
if(Test-DailyBuild)
{
Write-Host -Foreground Green 'Running all CorCLR tests..'
$coreClrTestParams.Tag = $null
$coreClrTestParams.ExcludeTag = $null
}
else
{
Write-Host -Foreground Green 'Running "CI" CorCLR tests..'
}
Start-PSPester -bindir $env:CoreOutput -outputFile $testResultsFile @coreClrTestParams
Write-Host -Foreground Green 'Upload CoreCLR test results'
Update-AppVeyorTestResults -resultsFile $testResultsFile
@ -118,20 +215,21 @@ function Invoke-AppVeyorTest
Test-PSPesterResults -TestResultsFile $testResultsFile
Test-PSPesterResults -TestResultsFile $testResultsFileFullCLR
Set-BuildVariable -Name TestPassed -Value True
}
# Implements AppVeyor 'on_finish' step
function Invoke-AppveyorFinish
{
try {
try {
# Build packages
$packages = Start-PSPackage
# Creating project artifact
$name = git describe
# Remove 'v' from version, append 'PowerShell' - to be consistent with other package names
$name = $name -replace 'v',''
$name = $name -replace 'v',''
$name = 'PowerShell_' + $name
$zipFilePath = Join-Path $pwd "$name.zip"
@ -141,36 +239,41 @@ function Invoke-AppveyorFinish
[System.IO.Compression.ZipFile]::CreateFromDirectory($env:CoreOutput, $zipFilePath)
Write-Verbose "Zipping ${env:FullOutput} into $zipFileFullPath" -verbose
[System.IO.Compression.ZipFile]::CreateFromDirectory($env:FullOutput, $zipFileFullPath)
$artifacts = New-Object System.Collections.ArrayList
foreach ($package in $packages) {
$artifacts.Add($package)
}
$artifacts.Add($zipFilePath)
$artifacts.Add($zipFileFullPath)
if ($env:APPVEYOR_REPO_TAG_NAME)
{
# ignore the first part of semver, use the preview part
$preReleaseVersion = ($env:APPVEYOR_REPO_TAG_NAME).Split('-')[1]
# ignore the first part of semver, use the preview part
$preReleaseVersion = ($env:APPVEYOR_REPO_TAG_NAME).Split('-')[1]
}
else
{
$previewLabel = (git describe --abbrev=0).Split('-')[1]
$preReleaseVersion = "$previewLabel.$($env:APPVEYOR_BUILD_NUMBER)"
$previewLabel = (git describe --abbrev=0).Split('-')[1].replace('.','')
if(Test-DailyBuild)
{
$previewLabel= "daily-{0}" -f $previewLabel
}
$preReleaseVersion = "$previewLabel-$($env:APPVEYOR_BUILD_NUMBER.replace('.','-'))"
}
# only publish to nuget feed if it is not a pull request
if(!$env:APPVEYOR_PULL_REQUEST_NUMBER)
# only publish to nuget feed if it is a daily build and tests passed
if((Test-DailyBuild) -and $env:TestPassed -eq 'True')
{
Publish-NuGetFeed -OutputPath .\nuget-artifacts -VersionSuffix $preReleaseVersion
}
$artifacts += (ls .\nuget-artifacts | % {$_.FullName})
$artifacts += (Get-ChildItem .\nuget-artifacts -ErrorAction SilentlyContinue | ForEach-Object {$_.FullName})
$pushedAllArtifacts = $true
$artifacts | % {
$artifacts | ForEach-Object {
Write-Host "Pushing $_ as Appveyor artifact"
if(Test-Path $_)
{
@ -181,15 +284,16 @@ function Invoke-AppveyorFinish
}
else
{
$pushedAllArtifacts = $false
Write-Warning "Artifact $_ does not exist."
$pushedAllArtifacts = $false
Write-Warning "Artifact $_ does not exist."
}
}
}
if(!$pushedAllArtifacts)
{
throw "Some artifacts did not exist!"
throw "Some artifacts did not exist!"
}
} catch {
}
catch {
Write-Host -Foreground Red $_
}
}
}
}