-
Notifications
You must be signed in to change notification settings - Fork 410
Expand file tree
/
Copy pathappveyor.psm1
More file actions
107 lines (92 loc) · 5.14 KB
/
appveyor.psm1
File metadata and controls
107 lines (92 loc) · 5.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
$ErrorActionPreference = 'Stop'
# Implements the AppVeyor 'install' step and installs the required versions of Pester, platyPS and the .Net Core SDK if needed.
function Invoke-AppVeyorInstall {
$requiredPesterVersion = '4.4.4'
$pester = Get-Module Pester -ListAvailable | Where-Object { $_.Version -eq $requiredPesterVersion }
if ($null -eq $pester) {
if ($null -eq (Get-Module -ListAvailable PowershellGet)) {
# WMF 4 image build
Write-Verbose -Verbose "Installing Pester via nuget"
nuget install Pester -Version $requiredPesterVersion -source https://www.powershellgallery.com/api/v2 -outputDirectory "$env:ProgramFiles\WindowsPowerShell\Modules\." -ExcludeVersion
}
else {
# Visual Studio 2017 build (has already Pester v3, therefore a different installation mechanism is needed to make it also use the new version 4)
Write-Verbose -Verbose "Installing Pester via Install-Module"
Install-Module -Name Pester -Force -SkipPublisherCheck -Scope CurrentUser
}
}
$platyPSVersion = '0.13.0'
if ($null -eq (Get-Module -ListAvailable PowershellGet)) {
# WMF 4 image build
Write-Verbose -Verbose "Installing platyPS via nuget"
nuget install platyPS -Version $platyPSVersion -source https://www.powershellgallery.com/api/v2 -outputDirectory "$Env:ProgramFiles\WindowsPowerShell\Modules\." -ExcludeVersion
}
else {
Write-Verbose -Verbose "Installing platyPS via Install-Module"
Install-Module -Name platyPS -Force -Scope CurrentUser -RequiredVersion $platyPSVersion
}
# the build script sorts out the problems of WMF4 and earlier versions of dotnet CLI
Write-Verbose -Verbose "Installing required .Net CORE SDK"
Write-Verbose "& $buildScriptDir/build.ps1 -bootstrap"
$buildScriptDir = (Resolve-Path "$PSScriptRoot/..").Path
& "$buildScriptDir/build.ps1" -bootstrap
}
# Implements AppVeyor 'test_script' step
function Invoke-AppveyorTest {
Param(
[Parameter(Mandatory)]
[ValidateScript( {Test-Path $_})]
$CheckoutPath
)
# enforce the language to utf-8 to avoid issues
$env:LANG = "en_US.UTF-8"
Write-Verbose -Verbose ("Running tests on PowerShell version " + $PSVersionTable.PSVersion)
Write-Verbose -Verbose "Language set to '${env:LANG}'"
# set up env:PSModulePath to the build location, don't copy it to the "normal place"
$analyzerVersion = ([xml](Get-Content "${CheckoutPath}\Engine\Engine.csproj")).SelectSingleNode(".//VersionPrefix")."#text".Trim()
$majorVersion = ([System.Version]$analyzerVersion).Major
$psMajorVersion = $PSVersionTable.PSVersion.Major
if ( $psMajorVersion -lt 5 ) {
$versionModuleDir = "${CheckoutPath}\out\PSScriptAnalyzer\${analyzerVersion}"
$renameTarget = "${CheckoutPath}\out\PSScriptAnalyzer\PSScriptAnalyzer"
Rename-Item "${versionModuleDir}" "${renameTarget}"
$moduleDir = "${CheckoutPath}\out\PSScriptAnalyzer"
}
else{
$moduleDir = "${CheckoutPath}\out"
}
$env:PSModulePath = "${moduleDir}","${env:PSModulePath}" -join [System.IO.Path]::PathSeparator
Write-Verbose -Verbose "module path: ${env:PSModulePath}"
# Set up testing assets
$testResultsPath = Join-Path ${CheckoutPath} TestResults.xml
$testScripts = "${CheckoutPath}\Tests\Engine","${CheckoutPath}\Tests\Rules","${CheckoutPath}\Tests\Documentation","${CheckoutPath}\PSCompatibilityCollector\Tests"
# Change culture to Turkish to test that PSSA works well with different locales
[System.Threading.Thread]::CurrentThread.CurrentCulture = [cultureinfo]::CreateSpecificCulture('tr-TR')
[System.Threading.Thread]::CurrentThread.CurrentUICulture = [cultureinfo]::CreateSpecificCulture('tr-TR')
# Run all tests
$testResults = Invoke-Pester -Script $testScripts -OutputFormat NUnitXml -OutputFile $testResultsPath -PassThru
# Upload the test results
$uploadUrl = "https://ci.appveyor.com/api/testresults/nunit/${env:APPVEYOR_JOB_ID}"
Write-Verbose -Verbose "Uploading test results '$testResultsPath' to '${uploadUrl}'"
[byte[]]$response = (New-Object 'System.Net.WebClient').UploadFile("$uploadUrl" , $testResultsPath)
# Throw an error if any tests failed
if ($testResults.FailedCount -gt 0) {
throw "$($testResults.FailedCount) tests failed."
}
}
# Implements AppVeyor 'on_finish' step
function Invoke-AppveyorFinish {
$stagingDirectory = (Resolve-Path ..).Path
$zipFile = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath((Join-Path $stagingDirectory "$(Split-Path $pwd -Leaf).zip"))
Add-Type -AssemblyName 'System.IO.Compression.FileSystem'
$sourceDirectory = (Resolve-Path -Path (Join-Path -Path $pwd -ChildPath 'out')).Path
[System.IO.Compression.ZipFile]::CreateFromDirectory($sourceDirectory, $zipFile)
@(
# add test results as an artifact
(Get-ChildItem TestResults.xml)
# You can add other artifacts here
(Get-ChildItem $zipFile)
) | ForEach-Object { Push-AppveyorArtifact $_.FullName }
}