2020-03-24 19:08:37 +01:00
|
|
|
# Copyright (c) Microsoft Corporation.
|
2018-02-13 18:23:53 +01:00
|
|
|
# Licensed under the MIT License.
|
2019-02-08 23:37:36 +01:00
|
|
|
|
2020-02-03 18:44:10 +01:00
|
|
|
Set-StrictMode -Version 3.0
|
|
|
|
|
2019-02-08 23:37:36 +01:00
|
|
|
$ErrorActionPreference = 'continue'
|
2016-08-29 22:12:01 +02:00
|
|
|
$repoRoot = Join-Path $PSScriptRoot '..'
|
2016-10-11 00:24:04 +02:00
|
|
|
$script:administratorsGroupSID = "S-1-5-32-544"
|
|
|
|
$script:usersGroupSID = "S-1-5-32-545"
|
2016-08-29 22:12:01 +02:00
|
|
|
|
2019-02-08 23:37:36 +01:00
|
|
|
# set .NET path
|
2017-07-18 20:39:04 +02:00
|
|
|
$dotNetPath = "$env:USERPROFILE\Appdata\Local\Microsoft\dotnet"
|
|
|
|
if(Test-Path $dotNetPath)
|
|
|
|
{
|
|
|
|
$env:PATH = $dotNetPath + ';' + $env:PATH
|
|
|
|
}
|
|
|
|
|
2019-02-08 23:37:36 +01:00
|
|
|
# import build into the global scope so it can be used by packaging
|
2017-07-23 21:29:33 +02:00
|
|
|
Import-Module (Join-Path $repoRoot 'build.psm1') -Scope Global
|
2020-05-07 14:00:30 +02:00
|
|
|
Import-Module (Join-Path $repoRoot 'tools\packaging') -Scope Global
|
2016-08-29 22:12:01 +02:00
|
|
|
|
2019-03-11 21:00:22 +01:00
|
|
|
# import the windows specific functcion only in Windows PowerShell or on Windows
|
2020-01-13 20:27:21 +01:00
|
|
|
if($PSVersionTable.PSEdition -eq 'Desktop' -or $IsWindows)
|
2016-10-11 00:24:04 +02:00
|
|
|
{
|
2020-05-07 14:00:30 +02:00
|
|
|
Import-Module (Join-Path $PSScriptRoot 'WindowsCI.psm1') -Scope Global
|
2016-10-11 00:24:04 +02:00
|
|
|
}
|
|
|
|
|
2016-08-31 22:02:12 +02:00
|
|
|
# tests if we should run a daily build
|
2017-01-16 22:31:14 +01:00
|
|
|
# returns true if the build is scheduled
|
2016-08-31 22:02:12 +02:00
|
|
|
# or is a pushed tag
|
|
|
|
Function Test-DailyBuild
|
|
|
|
{
|
2017-07-23 00:34:03 +02:00
|
|
|
$trueString = 'True'
|
2019-01-26 00:30:31 +01:00
|
|
|
if(($env:PS_DAILY_BUILD -eq $trueString) -or $env:BUILD_REASON -eq 'Schedule')
|
2016-08-31 22:02:12 +02:00
|
|
|
{
|
|
|
|
return $true
|
|
|
|
}
|
2019-03-27 21:29:15 +01:00
|
|
|
return $false
|
2018-11-10 00:11:02 +01:00
|
|
|
}
|
|
|
|
|
2016-08-31 22:02:12 +02:00
|
|
|
# Sets a build variable
|
|
|
|
Function Set-BuildVariable
|
|
|
|
{
|
|
|
|
param(
|
|
|
|
[Parameter(Mandatory=$true)]
|
|
|
|
[string]
|
|
|
|
$Name,
|
|
|
|
|
|
|
|
[Parameter(Mandatory=$true)]
|
|
|
|
[string]
|
|
|
|
$Value
|
|
|
|
)
|
|
|
|
|
2019-01-26 00:30:31 +01:00
|
|
|
if($env:TF_BUILD)
|
2018-08-18 07:06:51 +02:00
|
|
|
{
|
2019-02-08 23:37:36 +01:00
|
|
|
# In VSTS
|
2018-08-18 07:06:51 +02:00
|
|
|
Write-Host "##vso[task.setvariable variable=$Name;]$Value"
|
|
|
|
# The variable will not show up until the next task.
|
2019-02-08 23:37:36 +01:00
|
|
|
# Setting in the current session for the same behavior as the CI
|
2018-08-18 07:06:51 +02:00
|
|
|
Set-Item env:/$name -Value $Value
|
|
|
|
}
|
2017-01-16 22:31:14 +01:00
|
|
|
else
|
2016-08-31 22:02:12 +02:00
|
|
|
{
|
|
|
|
Set-Item env:/$name -Value $Value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-08 23:37:36 +01:00
|
|
|
# Emulates running all of CI but locally
|
2019-02-19 21:44:00 +01:00
|
|
|
function Invoke-CIFull
|
2016-08-29 22:12:01 +02:00
|
|
|
{
|
2016-08-31 22:02:12 +02:00
|
|
|
param(
|
|
|
|
[switch] $CleanRepo
|
|
|
|
)
|
|
|
|
if($CleanRepo)
|
|
|
|
{
|
|
|
|
Clear-PSRepo
|
|
|
|
}
|
|
|
|
|
2019-02-19 21:44:00 +01:00
|
|
|
Invoke-CIInstall
|
|
|
|
Invoke-CIBuild
|
|
|
|
Invoke-CITest -ErrorAction Continue
|
|
|
|
Invoke-CIFinish
|
2016-08-29 22:12:01 +02:00
|
|
|
}
|
|
|
|
|
2019-02-08 23:37:36 +01:00
|
|
|
# Implements the CI 'build_script' step
|
2019-02-19 21:44:00 +01:00
|
|
|
function Invoke-CIBuild
|
2016-08-29 22:12:01 +02:00
|
|
|
{
|
2017-11-21 22:51:10 +01:00
|
|
|
$releaseTag = Get-ReleaseTag
|
|
|
|
# check to be sure our test tags are correct
|
|
|
|
$result = Get-PesterTag
|
2019-02-08 23:37:36 +01:00
|
|
|
if ( $result.Result -ne "Pass" )
|
|
|
|
{
|
2016-08-29 22:12:01 +02:00
|
|
|
$result.Warnings
|
|
|
|
throw "Tags must be CI, Feature, Scenario, or Slow"
|
2017-11-21 22:51:10 +01:00
|
|
|
}
|
2016-11-11 20:12:07 +01:00
|
|
|
|
2017-11-21 22:51:10 +01:00
|
|
|
if(Test-DailyBuild)
|
|
|
|
{
|
2017-12-05 02:16:53 +01:00
|
|
|
Start-PSBuild -Configuration 'CodeCoverage' -PSModuleRestore -CI -ReleaseTag $releaseTag
|
2017-11-21 22:51:10 +01:00
|
|
|
}
|
2016-11-11 20:12:07 +01:00
|
|
|
|
2017-12-05 02:16:53 +01:00
|
|
|
Start-PSBuild -CrossGen -PSModuleRestore -Configuration 'Release' -CI -ReleaseTag $releaseTag
|
2019-02-15 01:33:19 +01:00
|
|
|
Save-PSOptions
|
|
|
|
|
|
|
|
$options = (Get-PSOptions)
|
|
|
|
|
2020-05-07 14:00:30 +02:00
|
|
|
$path = Split-Path -Path $options.Output
|
2019-02-15 01:33:19 +01:00
|
|
|
|
|
|
|
$psOptionsPath = (Join-Path -Path $PSScriptRoot -ChildPath '../psoptions.json')
|
|
|
|
$buildZipPath = (Join-Path -Path $PSScriptRoot -ChildPath '../build.zip')
|
|
|
|
|
|
|
|
Compress-Archive -Path $path -DestinationPath $buildZipPath
|
|
|
|
|
|
|
|
Push-Artifact -Path $psOptionsPath -Name 'build'
|
|
|
|
Push-Artifact -Path $buildZipPath -Name 'build'
|
2016-08-29 22:12:01 +02:00
|
|
|
}
|
|
|
|
|
2019-02-08 23:37:36 +01:00
|
|
|
# Implements the CI 'install' step
|
2019-02-19 21:44:00 +01:00
|
|
|
function Invoke-CIInstall
|
2016-08-29 22:12:01 +02:00
|
|
|
{
|
2019-03-11 21:00:22 +01:00
|
|
|
param(
|
|
|
|
[switch]
|
|
|
|
$SkipUser
|
|
|
|
)
|
2017-08-01 23:35:50 +02:00
|
|
|
# Make sure we have all the tags
|
|
|
|
Sync-PSTags -AddRemoteIfMissing
|
|
|
|
|
2019-02-08 23:37:36 +01:00
|
|
|
if(Test-DailyBuild)
|
|
|
|
{
|
|
|
|
if ($env:BUILD_REASON -eq 'Schedule')
|
|
|
|
{
|
2020-05-07 14:00:30 +02:00
|
|
|
Write-Host "##vso[build.updatebuildnumber]Daily-$env:BUILD_SOURCEBRANCHNAME-$env:BUILD_SOURCEVERSION-$((Get-Date).ToString("yyyyMMddhhss"))"
|
2017-07-20 01:47:11 +02:00
|
|
|
}
|
2016-08-31 22:02:12 +02:00
|
|
|
}
|
|
|
|
|
2019-03-11 21:00:22 +01:00
|
|
|
if ($env:TF_BUILD -and !$SkipUser.IsPresent)
|
2016-10-11 00:24:04 +02:00
|
|
|
{
|
2019-02-08 23:37:36 +01:00
|
|
|
# Generate new credential for CI (only) remoting tests.
|
2019-03-27 21:29:15 +01:00
|
|
|
Write-Verbose "Creating account for remoting tests in CI." -Verbose
|
2016-10-11 00:24:04 +02:00
|
|
|
|
|
|
|
# Password
|
|
|
|
$randomObj = [System.Random]::new()
|
|
|
|
$password = ""
|
2017-07-22 06:03:49 +02:00
|
|
|
1..(Get-Random -Minimum 15 -Maximum 126) | ForEach-Object { $password = $password + [char]$randomObj.next(45,126) }
|
2016-10-11 00:24:04 +02:00
|
|
|
|
|
|
|
# Account
|
2019-01-26 00:30:31 +01:00
|
|
|
$userName = 'ciRemote'
|
2020-05-07 14:00:30 +02:00
|
|
|
New-LocalUser -username $userName -Password $password
|
2016-10-11 00:24:04 +02:00
|
|
|
Add-UserToGroup -username $userName -groupSid $script:administratorsGroupSID
|
|
|
|
|
|
|
|
# Provide credentials globally for remote tests.
|
|
|
|
$ss = ConvertTo-SecureString -String $password -AsPlainText -Force
|
2019-02-08 23:37:36 +01:00
|
|
|
$ciRemoteCredential = [PSCredential]::new("$env:COMPUTERNAME\$userName", $ss)
|
2019-02-19 21:44:00 +01:00
|
|
|
$ciRemoteCredential | Export-Clixml -Path "$env:TEMP\CIRemoteCred.xml" -Force
|
2016-10-11 00:24:04 +02:00
|
|
|
|
|
|
|
# Check that LocalAccountTokenFilterPolicy policy is set, since it is needed for remoting
|
|
|
|
# using above local admin account.
|
2019-02-08 23:37:36 +01:00
|
|
|
Write-Log -Message "Checking for LocalAccountTokenFilterPolicy in the CI."
|
2016-10-11 00:24:04 +02:00
|
|
|
$haveLocalAccountTokenFilterPolicy = $false
|
|
|
|
try
|
|
|
|
{
|
|
|
|
$haveLocalAccountTokenFilterPolicy = ((Get-ItemPropertyValue -Path HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name LocalAccountTokenFilterPolicy) -eq 1)
|
|
|
|
}
|
2019-02-08 23:37:36 +01:00
|
|
|
# ignore if anything is caught:
|
|
|
|
catch {}
|
2016-10-11 00:24:04 +02:00
|
|
|
if (!$haveLocalAccountTokenFilterPolicy)
|
|
|
|
{
|
|
|
|
Write-Verbose "Setting the LocalAccountTokenFilterPolicy for remoting tests"
|
|
|
|
Set-ItemProperty -Path HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name LocalAccountTokenFilterPolicy -Value 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-31 22:02:12 +02:00
|
|
|
Set-BuildVariable -Name TestPassed -Value False
|
2017-07-18 20:39:04 +02:00
|
|
|
Start-PSBootstrap -Confirm:$false
|
2016-08-29 22:12:01 +02:00
|
|
|
}
|
|
|
|
|
2019-02-15 01:33:19 +01:00
|
|
|
function Invoke-CIxUnit
|
|
|
|
{
|
|
|
|
param(
|
|
|
|
[switch]
|
|
|
|
$SkipFailing
|
|
|
|
)
|
|
|
|
$env:CoreOutput = Split-Path -Parent (Get-PSOutput -Options (Get-PSOptions))
|
2019-03-11 21:00:22 +01:00
|
|
|
$path = "$env:CoreOutput\pwsh.exe"
|
|
|
|
if($IsMacOS -or $IsLinux)
|
|
|
|
{
|
|
|
|
$path = "$env:CoreOutput\pwsh"
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!(Test-Path $path))
|
2019-02-15 01:33:19 +01:00
|
|
|
{
|
|
|
|
throw "CoreCLR pwsh.exe was not built"
|
|
|
|
}
|
|
|
|
|
2020-05-07 14:00:30 +02:00
|
|
|
$xUnitTestResultsFile = Join-Path -Path $PWD -ChildPath "xUnitTestResults.xml"
|
2019-02-15 01:33:19 +01:00
|
|
|
|
2019-02-22 20:57:10 +01:00
|
|
|
Start-PSxUnit -xUnitTestResultsFile $xUnitTestResultsFile
|
|
|
|
Push-Artifact -Path $xUnitTestResultsFile -name xunit
|
2019-02-15 01:33:19 +01:00
|
|
|
|
|
|
|
if(!$SkipFailing.IsPresent)
|
|
|
|
{
|
|
|
|
# Fail the build, if tests failed
|
2019-02-22 20:57:10 +01:00
|
|
|
Test-XUnitTestResults -TestResultsFile $xUnitTestResultsFile
|
2019-02-15 01:33:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-08 23:37:36 +01:00
|
|
|
# Implement CI 'Test_script'
|
2019-02-19 21:44:00 +01:00
|
|
|
function Invoke-CITest
|
2016-08-29 22:12:01 +02:00
|
|
|
{
|
2016-08-30 20:47:27 +02:00
|
|
|
[CmdletBinding()]
|
2018-06-11 23:18:51 +02:00
|
|
|
param(
|
2019-02-15 01:33:19 +01:00
|
|
|
[ValidateSet('UnelevatedPesterTests', 'ElevatedPesterTests')]
|
|
|
|
[string] $Purpose,
|
|
|
|
[ValidateSet('CI', 'Others')]
|
|
|
|
[string] $TagSet
|
2018-06-11 23:18:51 +02:00
|
|
|
)
|
2017-01-16 22:31:14 +01:00
|
|
|
|
2018-06-11 23:18:51 +02:00
|
|
|
# Pester doesn't allow Invoke-Pester -TagAll@('CI', 'RequireAdminOnWindows') currently
|
|
|
|
# https://github.com/pester/Pester/issues/608
|
|
|
|
# To work-around it, we exlude all categories, but 'CI' from the list
|
2019-02-15 01:33:19 +01:00
|
|
|
switch ($TagSet) {
|
|
|
|
'CI' {
|
|
|
|
Write-Host -Foreground Green 'Running "CI" CoreCLR tests..'
|
|
|
|
$ExcludeTag = @('Slow', 'Feature', 'Scenario')
|
|
|
|
}
|
|
|
|
'Others' {
|
|
|
|
Write-Host -Foreground Green 'Running non-CI CoreCLR tests..'
|
|
|
|
$ExcludeTag = @('CI')
|
|
|
|
}
|
|
|
|
Default {
|
2019-03-27 21:29:15 +01:00
|
|
|
throw "Unknown TagSet: '$TagSet'"
|
2019-02-15 01:33:19 +01:00
|
|
|
}
|
2018-06-11 23:18:51 +02:00
|
|
|
}
|
2017-01-16 22:31:14 +01:00
|
|
|
|
2019-03-11 21:00:22 +01:00
|
|
|
if($IsLinux -or $IsMacOS)
|
|
|
|
{
|
|
|
|
return Invoke-LinuxTestsCore -Purpose $Purpose -ExcludeTag $ExcludeTag -TagSet $TagSet
|
|
|
|
}
|
|
|
|
|
|
|
|
# CoreCLR
|
|
|
|
|
|
|
|
$env:CoreOutput = Split-Path -Parent (Get-PSOutput -Options (Get-PSOptions))
|
|
|
|
Write-Host -Foreground Green 'Run CoreCLR tests'
|
2020-01-13 20:24:10 +01:00
|
|
|
$testResultsNonAdminFile = "$PWD\TestsResultsNonAdmin-$TagSet.xml"
|
|
|
|
$testResultsAdminFile = "$PWD\TestsResultsAdmin-$TagSet.xml"
|
2019-03-11 21:00:22 +01:00
|
|
|
if(!(Test-Path "$env:CoreOutput\pwsh.exe"))
|
|
|
|
{
|
|
|
|
throw "CoreCLR pwsh.exe was not built"
|
|
|
|
}
|
|
|
|
|
2018-08-03 20:20:14 +02:00
|
|
|
# Get the experimental feature names and the tests associated with them
|
|
|
|
$ExperimentalFeatureTests = Get-ExperimentalFeatureTests
|
|
|
|
|
2018-06-11 23:18:51 +02:00
|
|
|
if ($Purpose -eq 'UnelevatedPesterTests') {
|
2018-08-03 20:20:14 +02:00
|
|
|
$arguments = @{
|
|
|
|
Bindir = $env:CoreOutput
|
|
|
|
OutputFile = $testResultsNonAdminFile
|
|
|
|
Unelevate = $true
|
|
|
|
Terse = $true
|
|
|
|
Tag = @()
|
|
|
|
ExcludeTag = $ExcludeTag + 'RequireAdminOnWindows'
|
|
|
|
}
|
2019-03-11 21:00:22 +01:00
|
|
|
|
2019-02-15 01:33:19 +01:00
|
|
|
Start-PSPester @arguments -Title "Pester Unelevated - $TagSet"
|
2018-06-11 23:18:51 +02:00
|
|
|
# Fail the build, if tests failed
|
|
|
|
Test-PSPesterResults -TestResultsFile $testResultsNonAdminFile
|
2018-08-03 20:20:14 +02:00
|
|
|
|
|
|
|
# Run tests with specified experimental features enabled
|
2019-02-08 23:37:36 +01:00
|
|
|
foreach ($entry in $ExperimentalFeatureTests.GetEnumerator())
|
|
|
|
{
|
2018-08-03 20:20:14 +02:00
|
|
|
$featureName = $entry.Key
|
|
|
|
$testFiles = $entry.Value
|
|
|
|
|
2020-01-13 20:24:10 +01:00
|
|
|
$expFeatureTestResultFile = "$PWD\TestsResultsNonAdmin.$featureName.xml"
|
2018-08-03 20:20:14 +02:00
|
|
|
$arguments['OutputFile'] = $expFeatureTestResultFile
|
|
|
|
$arguments['ExperimentalFeatureName'] = $featureName
|
|
|
|
if ($testFiles.Count -eq 0) {
|
|
|
|
# If an empty array is specified for the feature name, we run all tests with the feature enabled.
|
|
|
|
# This allows us to prevent regressions to a critical engine experimental feature.
|
|
|
|
$arguments.Remove('Path')
|
|
|
|
} else {
|
|
|
|
# If a non-empty string or array is specified for the feature name, we only run those test files.
|
|
|
|
$arguments['Path'] = $testFiles
|
|
|
|
}
|
2019-03-11 21:00:22 +01:00
|
|
|
|
2018-08-18 07:06:51 +02:00
|
|
|
Start-PSPester @arguments -Title "Pester Experimental Unelevated - $featureName"
|
2018-08-03 20:20:14 +02:00
|
|
|
|
|
|
|
# Fail the build, if tests failed
|
|
|
|
Test-PSPesterResults -TestResultsFile $expFeatureTestResultFile
|
|
|
|
}
|
2016-09-16 04:33:54 +02:00
|
|
|
}
|
2016-08-29 22:12:01 +02:00
|
|
|
|
2019-02-15 01:33:19 +01:00
|
|
|
if ($Purpose -eq 'ElevatedPesterTests') {
|
2018-08-03 20:20:14 +02:00
|
|
|
$arguments = @{
|
|
|
|
Terse = $true
|
|
|
|
Bindir = $env:CoreOutput
|
|
|
|
OutputFile = $testResultsAdminFile
|
|
|
|
Tag = @('RequireAdminOnWindows')
|
|
|
|
ExcludeTag = $ExcludeTag
|
|
|
|
}
|
2019-03-11 21:00:22 +01:00
|
|
|
|
2019-02-15 01:33:19 +01:00
|
|
|
Start-PSPester @arguments -Title "Pester Elevated - $TagSet"
|
2018-06-11 23:18:51 +02:00
|
|
|
|
|
|
|
# Fail the build, if tests failed
|
|
|
|
Test-PSPesterResults -TestResultsFile $testResultsAdminFile
|
2018-08-03 20:20:14 +02:00
|
|
|
|
|
|
|
# Run tests with specified experimental features enabled
|
2019-02-08 23:37:36 +01:00
|
|
|
foreach ($entry in $ExperimentalFeatureTests.GetEnumerator())
|
|
|
|
{
|
2018-08-03 20:20:14 +02:00
|
|
|
$featureName = $entry.Key
|
|
|
|
$testFiles = $entry.Value
|
|
|
|
|
2020-01-13 20:24:10 +01:00
|
|
|
$expFeatureTestResultFile = "$PWD\TestsResultsAdmin.$featureName.xml"
|
2018-08-03 20:20:14 +02:00
|
|
|
$arguments['OutputFile'] = $expFeatureTestResultFile
|
|
|
|
$arguments['ExperimentalFeatureName'] = $featureName
|
2019-02-08 23:37:36 +01:00
|
|
|
if ($testFiles.Count -eq 0)
|
|
|
|
{
|
2018-08-03 20:20:14 +02:00
|
|
|
# If an empty array is specified for the feature name, we run all tests with the feature enabled.
|
|
|
|
# This allows us to prevent regressions to a critical engine experimental feature.
|
|
|
|
$arguments.Remove('Path')
|
2019-02-08 23:37:36 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-03 20:20:14 +02:00
|
|
|
# If a non-empty string or array is specified for the feature name, we only run those test files.
|
|
|
|
$arguments['Path'] = $testFiles
|
|
|
|
}
|
2018-08-18 07:06:51 +02:00
|
|
|
Start-PSPester @arguments -Title "Pester Experimental Elevated - $featureName"
|
2018-08-03 20:20:14 +02:00
|
|
|
|
|
|
|
# Fail the build, if tests failed
|
|
|
|
Test-PSPesterResults -TestResultsFile $expFeatureTestResultFile
|
|
|
|
}
|
2018-01-03 21:43:28 +01:00
|
|
|
}
|
2017-11-30 23:44:41 +01:00
|
|
|
|
2016-08-31 22:02:12 +02:00
|
|
|
Set-BuildVariable -Name TestPassed -Value True
|
2016-08-29 22:12:01 +02:00
|
|
|
}
|
|
|
|
|
2019-04-17 00:13:30 +02:00
|
|
|
function New-CodeCoverageAndTestPackage
|
2016-11-23 21:22:18 +01:00
|
|
|
{
|
|
|
|
[CmdletBinding()]
|
|
|
|
param()
|
|
|
|
|
2018-06-11 23:18:51 +02:00
|
|
|
if (Test-DailyBuild)
|
2016-11-23 21:22:18 +01:00
|
|
|
{
|
2019-05-24 20:13:40 +02:00
|
|
|
Start-PSBootstrap -Verbose
|
|
|
|
|
2019-02-25 22:03:06 +01:00
|
|
|
Start-PSBuild -Configuration 'CodeCoverage' -Clean
|
|
|
|
|
|
|
|
$codeCoverageOutput = Split-Path -Parent (Get-PSOutput)
|
2016-11-23 21:22:18 +01:00
|
|
|
$codeCoverageArtifacts = Compress-CoverageArtifacts -CodeCoverageOutput $codeCoverageOutput
|
|
|
|
|
2019-04-02 20:56:48 +02:00
|
|
|
$destBasePath = if ($env:TF_BUILD) {
|
|
|
|
$env:BUILD_ARTIFACTSTAGINGDIRECTORY
|
|
|
|
} else {
|
|
|
|
Join-Path (Get-Location).Path "out"
|
|
|
|
}
|
|
|
|
|
|
|
|
if (-not (Test-Path $destBasePath))
|
|
|
|
{
|
|
|
|
$null = New-Item -ItemType Directory -Path $destBasePath
|
|
|
|
}
|
|
|
|
|
2016-11-23 21:22:18 +01:00
|
|
|
Write-Host -ForegroundColor Green 'Upload CodeCoverage artifacts'
|
2018-11-10 00:11:02 +01:00
|
|
|
$codeCoverageArtifacts | ForEach-Object {
|
2019-04-02 20:56:48 +02:00
|
|
|
Copy-Item -Path $_ -Destination $destBasePath
|
|
|
|
$newPath = Join-Path $destBasePath (Split-Path $_ -Leaf)
|
|
|
|
Push-Artifact -Path $newPath -Name 'CodeCoverage'
|
2018-11-10 00:11:02 +01:00
|
|
|
}
|
2018-11-26 19:44:42 +01:00
|
|
|
|
2019-04-02 20:56:48 +02:00
|
|
|
New-TestPackage -Destination $destBasePath
|
|
|
|
$testPackageFullName = Join-Path $destBasePath 'TestPackage.zip'
|
2018-11-26 19:44:42 +01:00
|
|
|
Write-Verbose "Created TestPackage.zip" -Verbose
|
|
|
|
Write-Host -ForegroundColor Green 'Upload test package'
|
2019-02-28 23:38:45 +01:00
|
|
|
Push-Artifact $testPackageFullName -Name 'CodeCoverage'
|
2018-11-10 00:11:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Wrapper to push artifact
|
|
|
|
function Push-Artifact
|
|
|
|
{
|
|
|
|
param(
|
|
|
|
[Parameter(Mandatory)]
|
|
|
|
[ValidateScript({Test-Path -Path $_})]
|
2018-12-06 01:21:08 +01:00
|
|
|
$Path,
|
|
|
|
[string]
|
|
|
|
$Name
|
2018-11-10 00:11:02 +01:00
|
|
|
)
|
2018-10-19 23:56:58 +02:00
|
|
|
|
2018-12-06 01:21:08 +01:00
|
|
|
if(!$Name)
|
|
|
|
{
|
|
|
|
$artifactName = [system.io.path]::GetFileName($Path)
|
|
|
|
}
|
|
|
|
else
|
2018-11-10 00:11:02 +01:00
|
|
|
{
|
2018-12-06 01:21:08 +01:00
|
|
|
$artifactName = $Name
|
2018-11-10 00:11:02 +01:00
|
|
|
}
|
2018-12-06 01:21:08 +01:00
|
|
|
|
|
|
|
if ($env:TF_BUILD) {
|
2019-02-08 23:37:36 +01:00
|
|
|
# In Azure DevOps
|
2018-12-06 01:21:08 +01:00
|
|
|
Write-Host "##vso[artifact.upload containerfolder=$artifactName;artifactname=$artifactName;]$Path"
|
2016-11-23 21:22:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function Compress-CoverageArtifacts
|
|
|
|
{
|
|
|
|
param([string] $CodeCoverageOutput)
|
|
|
|
|
|
|
|
# Create archive for test content, OpenCover module and CodeCoverage build
|
|
|
|
$artifacts = New-Object System.Collections.ArrayList
|
|
|
|
|
|
|
|
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
|
|
|
$resolvedPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath((Join-Path $PSScriptRoot '..\test\tools\OpenCover'))
|
2020-01-13 20:24:10 +01:00
|
|
|
$zipOpenCoverPath = Join-Path $PWD 'OpenCover.zip'
|
2017-01-16 22:31:14 +01:00
|
|
|
[System.IO.Compression.ZipFile]::CreateFromDirectory($resolvedPath, $zipOpenCoverPath)
|
2016-11-24 01:38:50 +01:00
|
|
|
$null = $artifacts.Add($zipOpenCoverPath)
|
2016-11-23 21:22:18 +01:00
|
|
|
|
2020-01-13 20:24:10 +01:00
|
|
|
$zipCodeCoveragePath = Join-Path $PWD "CodeCoverage.zip"
|
2020-05-07 14:00:30 +02:00
|
|
|
Write-Verbose "Zipping ${CodeCoverageOutput} into $zipCodeCoveragePath" -Verbose
|
2016-11-23 21:22:18 +01:00
|
|
|
[System.IO.Compression.ZipFile]::CreateFromDirectory($CodeCoverageOutput, $zipCodeCoveragePath)
|
2016-11-24 01:38:50 +01:00
|
|
|
$null = $artifacts.Add($zipCodeCoveragePath)
|
2016-11-23 21:22:18 +01:00
|
|
|
|
|
|
|
return $artifacts
|
|
|
|
}
|
|
|
|
|
2017-11-21 22:51:10 +01:00
|
|
|
function Get-ReleaseTag
|
|
|
|
{
|
|
|
|
$metaDataPath = Join-Path -Path $PSScriptRoot -ChildPath 'metadata.json'
|
|
|
|
$metaData = Get-Content $metaDataPath | ConvertFrom-Json
|
2019-05-21 21:19:13 +02:00
|
|
|
$releaseTag = $metadata.NextReleaseTag
|
2019-02-08 23:37:36 +01:00
|
|
|
if($env:BUILD_BUILID)
|
2017-11-21 22:51:10 +01:00
|
|
|
{
|
2018-11-10 00:11:02 +01:00
|
|
|
$releaseTag = $releaseTag.split('.')[0..2] -join '.'
|
|
|
|
$releaseTag = $releaseTag + '.' + $env:BUILD_BUILID
|
2017-11-21 22:51:10 +01:00
|
|
|
}
|
|
|
|
return $releaseTag
|
|
|
|
}
|
|
|
|
|
2019-02-08 23:37:36 +01:00
|
|
|
# Implements CI 'on_finish' step
|
2019-02-19 21:44:00 +01:00
|
|
|
function Invoke-CIFinish
|
2016-08-29 22:12:01 +02:00
|
|
|
{
|
2018-12-14 02:23:41 +01:00
|
|
|
param(
|
|
|
|
[string] $NuGetKey
|
|
|
|
)
|
2019-03-11 21:00:22 +01:00
|
|
|
|
2020-02-14 03:46:10 +01:00
|
|
|
if($PSEdition -eq 'Core' -and ($IsLinux -or $IsMacOS))
|
2019-03-11 21:00:22 +01:00
|
|
|
{
|
|
|
|
return New-LinuxPackage -NugetKey $NugetKey
|
|
|
|
}
|
|
|
|
|
2016-08-31 22:02:12 +02:00
|
|
|
try {
|
2017-11-21 22:51:10 +01:00
|
|
|
$releaseTag = Get-ReleaseTag
|
|
|
|
|
2018-12-14 00:25:22 +01:00
|
|
|
$previewVersion = $releaseTag.Split('-')
|
|
|
|
$previewPrefix = $previewVersion[0]
|
|
|
|
$previewLabel = $previewVersion[1].replace('.','')
|
|
|
|
|
|
|
|
if(Test-DailyBuild)
|
|
|
|
{
|
|
|
|
$previewLabel= "daily{0}" -f $previewLabel
|
|
|
|
}
|
|
|
|
|
|
|
|
$preReleaseVersion = "$previewPrefix-$previewLabel.$env:BUILD_BUILDID"
|
|
|
|
|
2018-03-08 04:47:21 +01:00
|
|
|
# Build clean before backing to remove files from testing
|
2018-12-14 00:25:22 +01:00
|
|
|
Start-PSBuild -CrossGen -PSModuleRestore -Configuration 'Release' -ReleaseTag $preReleaseVersion -Clean
|
2018-03-08 04:47:21 +01:00
|
|
|
|
2016-08-29 22:12:01 +02:00
|
|
|
# Build packages
|
2020-03-21 20:36:10 +01:00
|
|
|
$packages = Start-PSPackage -Type msi,nupkg,zip,zip-pdb -ReleaseTag $preReleaseVersion -SkipReleaseChecks
|
2016-08-31 22:02:12 +02:00
|
|
|
|
2016-08-29 22:12:01 +02:00
|
|
|
$artifacts = New-Object System.Collections.ArrayList
|
|
|
|
foreach ($package in $packages) {
|
2019-02-08 23:37:36 +01:00
|
|
|
if (Test-Path $package)
|
2019-02-09 01:52:20 +01:00
|
|
|
{
|
2019-06-20 22:03:56 +02:00
|
|
|
Write-Log "Package found: $package"
|
2019-02-08 23:37:36 +01:00
|
|
|
}
|
2019-06-20 22:03:56 +02:00
|
|
|
else
|
2019-02-08 23:37:36 +01:00
|
|
|
{
|
|
|
|
Write-Warning -Message "Package NOT found: $package"
|
|
|
|
}
|
|
|
|
|
2018-03-08 04:47:21 +01:00
|
|
|
if($package -is [string])
|
|
|
|
{
|
|
|
|
$null = $artifacts.Add($package)
|
|
|
|
}
|
2020-02-03 18:44:10 +01:00
|
|
|
elseif($package -is [pscustomobject] -and $package.psobject.Properties['msi'])
|
2018-03-08 04:47:21 +01:00
|
|
|
{
|
|
|
|
$null = $artifacts.Add($package.msi)
|
|
|
|
$null = $artifacts.Add($package.wixpdb)
|
|
|
|
}
|
2016-08-29 22:12:01 +02:00
|
|
|
}
|
2016-08-31 22:02:12 +02:00
|
|
|
|
2018-04-02 19:47:29 +02:00
|
|
|
# the packaging tests find the MSI package using env:PSMsiX64Path
|
|
|
|
$env:PSMsiX64Path = $artifacts | Where-Object { $_.EndsWith(".msi")}
|
2018-03-21 20:23:24 +01:00
|
|
|
|
2018-04-02 19:47:29 +02:00
|
|
|
# Install the latest Pester and import it
|
2020-04-14 08:21:19 +02:00
|
|
|
$maximumPesterVersion = '4.99'
|
|
|
|
Install-Module Pester -Force -SkipPublisherCheck -MaximumVersion $maximumPesterVersion
|
|
|
|
Import-Module Pester -Force -MaximumVersion $maximumPesterVersion
|
2018-02-08 00:00:42 +01:00
|
|
|
|
2018-04-02 19:47:29 +02:00
|
|
|
# start the packaging tests and get the results
|
|
|
|
$packagingTestResult = Invoke-Pester -Script (Join-Path $repoRoot '.\test\packaging\windows\') -PassThru
|
2018-03-21 20:23:24 +01:00
|
|
|
|
2018-04-02 19:47:29 +02:00
|
|
|
# fail the CI job if the tests failed, or nothing passed
|
2020-02-03 18:44:10 +01:00
|
|
|
if(-not $packagingTestResult -is [pscustomobject] -or $packagingTestResult.FailedCount -ne 0 -or $packagingTestResult.PassedCount -eq 0)
|
2018-03-21 20:23:24 +01:00
|
|
|
{
|
2018-04-02 19:47:29 +02:00
|
|
|
throw "Packaging tests failed ($($packagingTestResult.FailedCount) failed/$($packagingTestResult.PassedCount) passed)"
|
2018-03-21 20:23:24 +01:00
|
|
|
}
|
|
|
|
|
2017-12-11 22:57:02 +01:00
|
|
|
# only publish assembly nuget packages if it is a daily build and tests passed
|
2019-04-02 01:58:43 +02:00
|
|
|
if(Test-DailyBuild)
|
2016-08-29 22:12:01 +02:00
|
|
|
{
|
2019-04-03 22:22:51 +02:00
|
|
|
$nugetArtifacts = Get-ChildItem $PSScriptRoot\packaging\nugetOutput -ErrorAction SilentlyContinue -Filter *.nupkg | Select-Object -ExpandProperty FullName
|
2017-12-11 22:57:02 +01:00
|
|
|
if($nugetArtifacts)
|
|
|
|
{
|
2019-04-03 22:22:51 +02:00
|
|
|
$artifacts.AddRange(@($nugetArtifacts))
|
2017-12-11 22:57:02 +01:00
|
|
|
}
|
2016-08-29 22:12:01 +02:00
|
|
|
}
|
|
|
|
|
2019-03-27 21:29:15 +01:00
|
|
|
# produce win-arm and win-arm64 packages if it is a daily build
|
|
|
|
Start-PSBuild -Restore -Runtime win-arm -PSModuleRestore -Configuration 'Release' -ReleaseTag $releaseTag
|
|
|
|
$arm32Package = Start-PSPackage -Type zip -WindowsRuntime win-arm -ReleaseTag $releaseTag -SkipReleaseChecks
|
|
|
|
$artifacts.Add($arm32Package)
|
|
|
|
|
|
|
|
Start-PSBuild -Restore -Runtime win-arm64 -PSModuleRestore -Configuration 'Release' -ReleaseTag $releaseTag
|
|
|
|
$arm64Package = Start-PSPackage -Type zip -WindowsRuntime win-arm64 -ReleaseTag $releaseTag -SkipReleaseChecks
|
|
|
|
$artifacts.Add($arm64Package)
|
2016-08-29 22:12:01 +02:00
|
|
|
|
|
|
|
$pushedAllArtifacts = $true
|
2019-04-03 22:22:51 +02:00
|
|
|
|
2017-01-16 22:31:14 +01:00
|
|
|
$artifacts | ForEach-Object {
|
2019-02-08 23:37:36 +01:00
|
|
|
Write-Log -Message "Pushing $_ as CI artifact"
|
2016-08-29 22:12:01 +02:00
|
|
|
if(Test-Path $_)
|
|
|
|
{
|
2019-02-04 23:53:25 +01:00
|
|
|
Push-Artifact -Path $_ -Name 'artifacts'
|
2016-08-29 22:12:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-31 22:02:12 +02:00
|
|
|
$pushedAllArtifacts = $false
|
|
|
|
Write-Warning "Artifact $_ does not exist."
|
2016-08-29 22:12:01 +02:00
|
|
|
}
|
2017-08-01 23:35:50 +02:00
|
|
|
|
2018-12-14 02:23:41 +01:00
|
|
|
if($NuGetKey -and $env:NUGET_URL -and [system.io.path]::GetExtension($_) -ieq '.nupkg')
|
2017-08-01 23:35:50 +02:00
|
|
|
{
|
2018-03-08 19:47:20 +01:00
|
|
|
Write-Log "pushing $_ to $env:NUGET_URL"
|
2018-12-14 02:23:41 +01:00
|
|
|
Start-NativeExecution -sb {dotnet nuget push $_ --api-key $NuGetKey --source "$env:NUGET_URL/api/v2/package"} -IgnoreExitcode
|
2017-09-07 00:20:25 +02:00
|
|
|
}
|
2016-08-31 22:02:12 +02:00
|
|
|
}
|
2016-08-29 22:12:01 +02:00
|
|
|
if(!$pushedAllArtifacts)
|
|
|
|
{
|
2016-08-31 22:02:12 +02:00
|
|
|
throw "Some artifacts did not exist!"
|
2016-08-29 22:12:01 +02:00
|
|
|
}
|
2017-01-16 22:31:14 +01:00
|
|
|
}
|
2019-02-08 23:37:36 +01:00
|
|
|
catch
|
|
|
|
{
|
2016-08-29 22:12:01 +02:00
|
|
|
Write-Host -Foreground Red $_
|
2018-08-31 21:50:51 +02:00
|
|
|
Write-Host -Foreground Red $_.ScriptStackTrace
|
2018-03-09 00:58:59 +01:00
|
|
|
throw $_
|
2018-02-08 00:00:42 +01:00
|
|
|
}
|
2016-08-31 22:02:12 +02:00
|
|
|
}
|
2019-02-08 23:37:36 +01:00
|
|
|
|
|
|
|
# Bootstrap script for Linux and macOS
|
2019-03-11 21:00:22 +01:00
|
|
|
function Invoke-BootstrapStage
|
2019-02-08 23:37:36 +01:00
|
|
|
{
|
|
|
|
$createPackages = Test-DailyBuild
|
|
|
|
Write-Log -Message "Executing ci.psm1 Bootstrap Stage"
|
|
|
|
# Make sure we have all the tags
|
|
|
|
Sync-PSTags -AddRemoteIfMissing
|
|
|
|
Start-PSBootstrap -Package:$createPackages
|
|
|
|
}
|
|
|
|
|
2019-03-11 21:00:22 +01:00
|
|
|
# Run pester tests for Linux and macOS
|
|
|
|
function Invoke-LinuxTestsCore
|
2019-02-08 23:37:36 +01:00
|
|
|
{
|
2019-03-11 21:00:22 +01:00
|
|
|
[CmdletBinding()]
|
|
|
|
param(
|
|
|
|
[ValidateSet('UnelevatedPesterTests', 'ElevatedPesterTests', 'All')]
|
|
|
|
[string] $Purpose = 'All',
|
|
|
|
[string[]] $ExcludeTag = @('Slow', 'Feature', 'Scenario'),
|
|
|
|
[string] $TagSet = 'CI'
|
|
|
|
)
|
2019-02-08 23:37:36 +01:00
|
|
|
|
|
|
|
$output = Split-Path -Parent (Get-PSOutput -Options (Get-PSOptions))
|
2020-01-13 20:24:10 +01:00
|
|
|
$testResultsNoSudo = "$PWD/TestResultsNoSudo.xml"
|
|
|
|
$testResultsSudo = "$PWD/TestResultsSudo.xml"
|
2019-03-11 21:00:22 +01:00
|
|
|
$testExcludeTag = $ExcludeTag + 'RequireSudoOnUnix'
|
2020-02-03 18:44:10 +01:00
|
|
|
$pesterPassThruNoSudoObject = $null
|
|
|
|
$pesterPassThruSudoObject = $null
|
|
|
|
$noSudoResultsWithExpFeatures = $null
|
|
|
|
$sudoResultsWithExpFeatures = $null
|
2019-02-08 23:37:36 +01:00
|
|
|
|
|
|
|
$noSudoPesterParam = @{
|
|
|
|
'BinDir' = $output
|
|
|
|
'PassThru' = $true
|
|
|
|
'Terse' = $true
|
|
|
|
'Tag' = @()
|
2019-03-11 21:00:22 +01:00
|
|
|
'ExcludeTag' = $testExcludeTag
|
2019-02-08 23:37:36 +01:00
|
|
|
'OutputFile' = $testResultsNoSudo
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get the experimental feature names and the tests associated with them
|
|
|
|
$ExperimentalFeatureTests = Get-ExperimentalFeatureTests
|
|
|
|
|
|
|
|
# Running tests which do not require sudo.
|
2019-03-11 21:00:22 +01:00
|
|
|
if($Purpose -eq 'UnelevatedPesterTests' -or $Purpose -eq 'All')
|
|
|
|
{
|
|
|
|
$pesterPassThruNoSudoObject = Start-PSPester @noSudoPesterParam -Title "Pester No Sudo - $TagSet"
|
|
|
|
|
|
|
|
# Running tests that do not require sudo, with specified experimental features enabled
|
|
|
|
$noSudoResultsWithExpFeatures = @()
|
|
|
|
foreach ($entry in $ExperimentalFeatureTests.GetEnumerator()) {
|
|
|
|
$featureName = $entry.Key
|
|
|
|
$testFiles = $entry.Value
|
|
|
|
|
2020-01-13 20:24:10 +01:00
|
|
|
$expFeatureTestResultFile = "$PWD\TestResultsNoSudo.$featureName.xml"
|
2019-03-11 21:00:22 +01:00
|
|
|
$noSudoPesterParam['OutputFile'] = $expFeatureTestResultFile
|
|
|
|
$noSudoPesterParam['ExperimentalFeatureName'] = $featureName
|
|
|
|
if ($testFiles.Count -eq 0) {
|
|
|
|
# If an empty array is specified for the feature name, we run all tests with the feature enabled.
|
|
|
|
# This allows us to prevent regressions to a critical engine experimental feature.
|
|
|
|
$noSudoPesterParam.Remove('Path')
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
# If a non-empty string or array is specified for the feature name, we only run those test files.
|
|
|
|
$noSudoPesterParam['Path'] = $testFiles
|
|
|
|
}
|
|
|
|
$passThruResult = Start-PSPester @noSudoPesterParam -Title "Pester Experimental No Sudo - $featureName - $TagSet"
|
|
|
|
$noSudoResultsWithExpFeatures += $passThruResult
|
2019-02-08 23:37:36 +01:00
|
|
|
}
|
|
|
|
}
|
2019-03-11 21:00:22 +01:00
|
|
|
|
2019-02-08 23:37:36 +01:00
|
|
|
# Running tests, which require sudo.
|
2019-03-11 21:00:22 +01:00
|
|
|
if($Purpose -eq 'ElevatedPesterTests' -or $Purpose -eq 'All')
|
|
|
|
{
|
|
|
|
$sudoPesterParam = $noSudoPesterParam.Clone()
|
|
|
|
$sudoPesterParam.Remove('Path')
|
|
|
|
$sudoPesterParam['Tag'] = @('RequireSudoOnUnix')
|
|
|
|
$sudoPesterParam['ExcludeTag'] = $ExcludeTag
|
|
|
|
$sudoPesterParam['Sudo'] = $true
|
|
|
|
$sudoPesterParam['OutputFile'] = $testResultsSudo
|
|
|
|
$pesterPassThruSudoObject = Start-PSPester @sudoPesterParam -Title "Pester Sudo - $TagSet"
|
|
|
|
|
|
|
|
# Running tests that require sudo, with specified experimental features enabled
|
|
|
|
$sudoResultsWithExpFeatures = @()
|
|
|
|
foreach ($entry in $ExperimentalFeatureTests.GetEnumerator()) {
|
|
|
|
$featureName = $entry.Key
|
|
|
|
$testFiles = $entry.Value
|
|
|
|
|
2020-01-13 20:24:10 +01:00
|
|
|
$expFeatureTestResultFile = "$PWD\TestResultsSudo.$featureName.xml"
|
2019-03-11 21:00:22 +01:00
|
|
|
$sudoPesterParam['OutputFile'] = $expFeatureTestResultFile
|
|
|
|
$sudoPesterParam['ExperimentalFeatureName'] = $featureName
|
|
|
|
if ($testFiles.Count -eq 0)
|
|
|
|
{
|
|
|
|
# If an empty array is specified for the feature name, we run all tests with the feature enabled.
|
|
|
|
# This allows us to prevent regressions to a critical engine experimental feature.
|
|
|
|
$sudoPesterParam.Remove('Path')
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
# If a non-empty string or array is specified for the feature name, we only run those test files.
|
|
|
|
$sudoPesterParam['Path'] = $testFiles
|
|
|
|
}
|
|
|
|
$passThruResult = Start-PSPester @sudoPesterParam -Title "Pester Experimental Sudo - $featureName - $TagSet"
|
|
|
|
$sudoResultsWithExpFeatures += $passThruResult
|
2019-02-08 23:37:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Determine whether the build passed
|
|
|
|
try {
|
|
|
|
$allTestResultsWithNoExpFeature = @($pesterPassThruNoSudoObject, $pesterPassThruSudoObject)
|
2019-04-06 00:49:30 +02:00
|
|
|
$allTestResultsWithExpFeatures = @($noSudoResultsWithExpFeatures, $sudoResultsWithExpFeatures)
|
2019-02-08 23:37:36 +01:00
|
|
|
# This throws if there was an error:
|
2019-04-06 02:00:41 +02:00
|
|
|
$allTestResultsWithNoExpFeature | Where-Object {$null -ne $_} | ForEach-Object { Test-PSPesterResults -ResultObject $_ }
|
|
|
|
$allTestResultsWithExpFeatures | Where-Object {$null -ne $_} | ForEach-Object { Test-PSPesterResults -ResultObject $_ -CanHaveNoResult }
|
2019-02-08 23:37:36 +01:00
|
|
|
$result = "PASS"
|
|
|
|
} catch {
|
|
|
|
# The build failed, set the result:
|
|
|
|
$resultError = $_
|
|
|
|
$result = "FAIL"
|
|
|
|
}
|
|
|
|
|
2019-03-11 21:00:22 +01:00
|
|
|
# If the tests did not pass, throw the reason why
|
|
|
|
if ( $result -eq "FAIL" )
|
|
|
|
{
|
|
|
|
Write-Warning "Tests failed. See the issue below."
|
|
|
|
Throw $resultError
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Write-Verbose "Tests did not fail! Nice job!"
|
|
|
|
}
|
|
|
|
}
|
2019-02-08 23:37:36 +01:00
|
|
|
|
2019-03-11 21:00:22 +01:00
|
|
|
function New-LinuxPackage
|
|
|
|
{
|
|
|
|
param(
|
|
|
|
[string]
|
|
|
|
$NugetKey
|
|
|
|
)
|
2019-02-08 23:37:36 +01:00
|
|
|
|
2019-03-11 21:00:22 +01:00
|
|
|
$isFullBuild = Test-DailyBuild
|
|
|
|
$releaseTag = Get-ReleaseTag
|
|
|
|
$packageParams = @{}
|
|
|
|
$packageParams += @{ReleaseTag=$releaseTag}
|
|
|
|
|
|
|
|
# Only build packages for PowerShell/PowerShell repository
|
|
|
|
# branches, not pull requests
|
|
|
|
$packages = @(Start-PSPackage @packageParams -SkipReleaseChecks)
|
|
|
|
foreach($package in $packages)
|
|
|
|
{
|
|
|
|
if (Test-Path $package)
|
|
|
|
{
|
|
|
|
Write-Log "Package found: $package"
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Write-Error -Message "Package NOT found: $package"
|
2019-02-08 23:37:36 +01:00
|
|
|
}
|
|
|
|
|
2019-03-11 21:00:22 +01:00
|
|
|
# Publish the packages to the nuget feed if:
|
|
|
|
# 1 - It's a Daily build (already checked, for not a PR)
|
|
|
|
# 2 - We have the info to publish (NUGET_KEY and NUGET_URL)
|
|
|
|
# 3 - it's a nupkg file
|
|
|
|
if($isFullBuild -and $NugetKey -and $env:NUGET_URL -and [system.io.path]::GetExtension($package) -ieq '.nupkg')
|
2019-02-08 23:37:36 +01:00
|
|
|
{
|
2019-03-11 21:00:22 +01:00
|
|
|
Write-Log "pushing $package to $env:NUGET_URL"
|
|
|
|
Start-NativeExecution -sb {dotnet nuget push $package --api-key $NugetKey --source "$env:NUGET_URL/api/v2/package"} -IgnoreExitcode
|
2019-02-08 23:37:36 +01:00
|
|
|
}
|
|
|
|
|
2019-03-11 21:00:22 +01:00
|
|
|
if($isFullBuild)
|
2019-02-08 23:37:36 +01:00
|
|
|
{
|
2019-03-11 21:00:22 +01:00
|
|
|
if ($package -isnot [System.IO.FileInfo])
|
|
|
|
{
|
2019-06-20 22:03:56 +02:00
|
|
|
$packageObj = Get-Item $package
|
|
|
|
Write-Error -Message "The PACKAGE is not a FileInfo object"
|
2019-03-11 21:00:22 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-20 22:03:56 +02:00
|
|
|
$packageObj = $package
|
2019-03-11 21:00:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Write-Log -message "Artifacts directory: ${env:BUILD_ARTIFACTSTAGINGDIRECTORY}"
|
|
|
|
Copy-Item $packageObj.FullName -Destination "${env:BUILD_ARTIFACTSTAGINGDIRECTORY}" -Force
|
2019-02-08 23:37:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-11 21:00:22 +01:00
|
|
|
if ($IsLinux)
|
2019-02-08 23:37:36 +01:00
|
|
|
{
|
2019-03-11 21:00:22 +01:00
|
|
|
# Create and package Raspbian .tgz
|
|
|
|
Start-PSBuild -PSModuleRestore -Clean -Runtime linux-arm -Configuration 'Release'
|
|
|
|
$armPackage = Start-PSPackage @packageParams -Type tar-arm -SkipReleaseChecks
|
|
|
|
Copy-Item $armPackage -Destination "${env:BUILD_ARTIFACTSTAGINGDIRECTORY}" -Force
|
2019-02-08 23:37:36 +01:00
|
|
|
}
|
|
|
|
}
|