2016-08-30 04:12:01 +08:00
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
$repoRoot = Join-Path $PSScriptRoot '..'
|
|
|
|
|
|
|
|
Import-Module (Join-Path $repoRoot 'build.psm1')
|
|
|
|
|
2016-09-01 04:02:12 +08:00
|
|
|
# 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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-30 05:21:48 +08:00
|
|
|
# Emulates running all of AppVeyor but locally
|
|
|
|
# should not be used on AppVeyor
|
2016-08-30 04:12:01 +08:00
|
|
|
function Invoke-AppVeyorFull
|
|
|
|
{
|
2016-09-01 04:02:12 +08:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2016-08-30 04:12:01 +08:00
|
|
|
}
|
|
|
|
|
2016-08-30 05:21:48 +08:00
|
|
|
# Implements the AppVeyor 'build_script' step
|
2016-08-30 04:12:01 +08:00
|
|
|
function Invoke-AppVeyorBuild
|
|
|
|
{
|
|
|
|
# check to be sure our test tags are correct
|
|
|
|
$result = Get-PesterTag
|
|
|
|
if ( $result.Result -ne "Pass" ) {
|
|
|
|
$result.Warnings
|
|
|
|
throw "Tags must be CI, Feature, Scenario, or Slow"
|
|
|
|
}
|
|
|
|
Start-PSBuild -FullCLR
|
2016-09-29 01:47:16 +08:00
|
|
|
Start-PSBuild -CrossGen -Configuration $buildConfiguration
|
2016-08-30 04:12:01 +08:00
|
|
|
}
|
|
|
|
|
2016-08-30 05:21:48 +08:00
|
|
|
# Implements the AppVeyor 'install' step
|
2016-08-30 04:12:01 +08:00
|
|
|
function Invoke-AppVeyorInstall
|
|
|
|
{
|
2016-09-01 04:02:12 +08:00
|
|
|
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
|
2016-08-30 04:12:01 +08:00
|
|
|
Start-PSBootstrap -Force
|
|
|
|
}
|
|
|
|
|
2016-08-30 05:21:48 +08:00
|
|
|
# A wrapper to ensure that we upload test results
|
|
|
|
# and that if we are not able to that it does not fail
|
|
|
|
# the CI build
|
2016-08-30 04:12:01 +08:00
|
|
|
function Update-AppVeyorTestResults
|
|
|
|
{
|
|
|
|
param(
|
|
|
|
[string] $resultsFile
|
|
|
|
)
|
|
|
|
|
|
|
|
if($env:Appveyor)
|
|
|
|
{
|
2016-08-30 04:57:20 +08:00
|
|
|
$retryCount = 0
|
|
|
|
$pushedResults = $false
|
|
|
|
$pushedArtifacts = $false
|
|
|
|
while( (!$pushedResults -or !$pushedResults) -and $retryCount -lt 3)
|
|
|
|
{
|
|
|
|
if($retryCount -gt 0)
|
|
|
|
{
|
|
|
|
Write-Verbose "Retrying updating test artifacts..."
|
|
|
|
}
|
|
|
|
|
|
|
|
$retryCount++
|
|
|
|
$resolvedResultsPath = (Resolve-Path $resultsFile)
|
|
|
|
try {
|
|
|
|
(New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", $resolvedResultsPath)
|
|
|
|
$pushedResults = $true
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
Write-Warning "Pushing test result failed..."
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
Push-AppveyorArtifact $resolvedResultsPath
|
|
|
|
$pushedArtifacts = $true
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
Write-Warning "Pushing test Artifact failed..."
|
|
|
|
}
|
|
|
|
}
|
2016-08-30 05:21:48 +08:00
|
|
|
|
2016-08-30 04:57:20 +08:00
|
|
|
if(!$pushedResults -or !$pushedResults)
|
|
|
|
{
|
|
|
|
Write-Warning "Failed to push all artifacts for $resultsFile"
|
|
|
|
}
|
2016-08-30 04:12:01 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Write-Warning "Not running in appveyor, skipping upload of test results: $resultsFile"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-30 05:21:48 +08:00
|
|
|
# Implement AppVeyor 'Test_script'
|
2016-08-30 04:12:01 +08:00
|
|
|
function Invoke-AppVeyorTest
|
|
|
|
{
|
2016-08-31 02:47:27 +08:00
|
|
|
[CmdletBinding()]
|
|
|
|
param()
|
2016-08-30 04:12:01 +08:00
|
|
|
#
|
|
|
|
# CoreCLR
|
2016-09-01 04:02:12 +08:00
|
|
|
|
2016-08-30 04:12:01 +08:00
|
|
|
$env:CoreOutput = Split-Path -Parent (Get-PSOutput -Options (New-PSOptions -Publish -Configuration $buildConfiguration))
|
|
|
|
Write-Host -Foreground Green 'Run CoreCLR tests'
|
|
|
|
$testResultsFile = "$pwd\TestsResults.xml"
|
|
|
|
if(!(Test-Path "$env:CoreOutput\powershell.exe"))
|
|
|
|
{
|
2016-08-30 05:52:50 +08:00
|
|
|
throw "CoreCLR PowerShell.exe was not built"
|
2016-08-30 04:12:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-01 04:02:12 +08:00
|
|
|
$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
|
2016-08-31 02:47:27 +08:00
|
|
|
Write-Host -Foreground Green 'Upload CoreCLR test results'
|
2016-08-30 04:12:01 +08:00
|
|
|
Update-AppVeyorTestResults -resultsFile $testResultsFile
|
|
|
|
|
|
|
|
#
|
|
|
|
# FullCLR
|
|
|
|
$env:FullOutput = Split-Path -Parent (Get-PSOutput -Options (New-PSOptions -FullCLR))
|
|
|
|
Write-Host -Foreground Green 'Run FullCLR tests'
|
|
|
|
$testResultsFileFullCLR = "$pwd\TestsResults.FullCLR.xml"
|
2016-08-31 02:47:27 +08:00
|
|
|
Start-PSPester -FullCLR -bindir $env:FullOutput -outputFile $testResultsFileFullCLR -Tag $null -path 'test/fullCLR'
|
|
|
|
|
|
|
|
Write-Host -Foreground Green 'Upload FullCLR test results'
|
2016-08-30 04:12:01 +08:00
|
|
|
Update-AppVeyorTestResults -resultsFile $testResultsFileFullCLR
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Fail the build, if tests failed
|
2016-08-31 02:47:27 +08:00
|
|
|
Test-PSPesterResults -TestResultsFile $testResultsFile
|
2016-08-30 04:12:01 +08:00
|
|
|
|
2016-08-31 02:47:27 +08:00
|
|
|
Test-PSPesterResults -TestResultsFile $testResultsFileFullCLR
|
2016-09-01 04:02:12 +08:00
|
|
|
Set-BuildVariable -Name TestPassed -Value True
|
2016-08-30 04:12:01 +08:00
|
|
|
}
|
|
|
|
|
2016-08-30 05:21:48 +08:00
|
|
|
# Implements AppVeyor 'on_finish' step
|
2016-08-30 04:12:01 +08:00
|
|
|
function Invoke-AppveyorFinish
|
|
|
|
{
|
2016-09-01 04:02:12 +08:00
|
|
|
try {
|
2016-08-30 04:12:01 +08:00
|
|
|
# Build packages
|
|
|
|
$packages = Start-PSPackage
|
2016-09-01 04:02:12 +08:00
|
|
|
|
2016-08-30 04:12:01 +08:00
|
|
|
# Creating project artifact
|
|
|
|
$name = git describe
|
|
|
|
|
|
|
|
# Remove 'v' from version, append 'PowerShell' - to be consistent with other package names
|
2016-09-01 04:02:12 +08:00
|
|
|
$name = $name -replace 'v',''
|
2016-08-30 04:12:01 +08:00
|
|
|
$name = 'PowerShell_' + $name
|
|
|
|
|
|
|
|
$zipFilePath = Join-Path $pwd "$name.zip"
|
|
|
|
$zipFileFullPath = Join-Path $pwd "$name.FullCLR.zip"
|
|
|
|
Add-Type -assemblyname System.IO.Compression.FileSystem
|
|
|
|
Write-Verbose "Zipping ${env:CoreOutput} into $zipFilePath" -verbose
|
|
|
|
[System.IO.Compression.ZipFile]::CreateFromDirectory($env:CoreOutput, $zipFilePath)
|
|
|
|
Write-Verbose "Zipping ${env:FullOutput} into $zipFileFullPath" -verbose
|
|
|
|
[System.IO.Compression.ZipFile]::CreateFromDirectory($env:FullOutput, $zipFileFullPath)
|
2016-09-01 04:02:12 +08:00
|
|
|
|
2016-08-30 04:12:01 +08:00
|
|
|
$artifacts = New-Object System.Collections.ArrayList
|
|
|
|
foreach ($package in $packages) {
|
|
|
|
$artifacts.Add($package)
|
|
|
|
}
|
2016-09-01 04:02:12 +08:00
|
|
|
|
2016-08-30 04:12:01 +08:00
|
|
|
$artifacts.Add($zipFilePath)
|
|
|
|
$artifacts.Add($zipFileFullPath)
|
|
|
|
|
|
|
|
if ($env:APPVEYOR_REPO_TAG_NAME)
|
|
|
|
{
|
2016-09-01 04:02:12 +08:00
|
|
|
# ignore the first part of semver, use the preview part
|
|
|
|
$preReleaseVersion = ($env:APPVEYOR_REPO_TAG_NAME).Split('-')[1]
|
2016-08-30 04:12:01 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-01 04:02:12 +08:00
|
|
|
$previewLabel = (git describe --abbrev=0).Split('-')[1].replace('.','')
|
|
|
|
if(Test-DailyBuild)
|
|
|
|
{
|
|
|
|
$previewLabel= "daily-{0}" -f $previewLabel
|
|
|
|
}
|
|
|
|
|
|
|
|
$preReleaseVersion = "$previewLabel-$($env:APPVEYOR_BUILD_NUMBER.replace('.','-'))"
|
2016-08-30 04:12:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-01 04:02:12 +08:00
|
|
|
# only publish to nuget feed if it is a daily build and tests passed
|
|
|
|
if((Test-DailyBuild) -and $env:TestPassed -eq 'True')
|
2016-08-30 04:12:01 +08:00
|
|
|
{
|
|
|
|
Publish-NuGetFeed -OutputPath .\nuget-artifacts -VersionSuffix $preReleaseVersion
|
|
|
|
}
|
|
|
|
|
2016-09-01 04:02:12 +08:00
|
|
|
$artifacts += (Get-ChildItem .\nuget-artifacts -ErrorAction SilentlyContinue | ForEach-Object {$_.FullName})
|
2016-08-30 04:12:01 +08:00
|
|
|
|
|
|
|
$pushedAllArtifacts = $true
|
2016-09-01 04:02:12 +08:00
|
|
|
$artifacts | ForEach-Object {
|
2016-08-30 04:12:01 +08:00
|
|
|
Write-Host "Pushing $_ as Appveyor artifact"
|
|
|
|
if(Test-Path $_)
|
|
|
|
{
|
|
|
|
if($env:Appveyor)
|
|
|
|
{
|
|
|
|
Push-AppveyorArtifact $_
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-01 04:02:12 +08:00
|
|
|
$pushedAllArtifacts = $false
|
|
|
|
Write-Warning "Artifact $_ does not exist."
|
2016-08-30 04:12:01 +08:00
|
|
|
}
|
2016-09-01 04:02:12 +08:00
|
|
|
}
|
2016-08-30 04:12:01 +08:00
|
|
|
if(!$pushedAllArtifacts)
|
|
|
|
{
|
2016-09-01 04:02:12 +08:00
|
|
|
throw "Some artifacts did not exist!"
|
2016-08-30 04:12:01 +08:00
|
|
|
}
|
2016-09-01 04:02:12 +08:00
|
|
|
}
|
|
|
|
catch {
|
2016-08-30 04:12:01 +08:00
|
|
|
Write-Host -Foreground Red $_
|
2016-09-01 04:02:12 +08:00
|
|
|
}
|
|
|
|
}
|