refactor(ci,tests): Support both AppVeyor and GitHub Actions (#4655)

This commit is contained in:
Chawye Hsu
2022-01-14 19:40:35 +08:00
committed by GitHub
parent d7fb97f517
commit d9f55a3a0a
10 changed files with 265 additions and 222 deletions

35
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,35 @@
name: Tests
on:
pull_request:
types: [ opened ]
push:
workflow_dispatch:
jobs:
test_powershell:
name: WindowsPowerShell
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Init and Test
shell: powershell
run: |
.\test\bin\init.ps1
.\test\bin\test.ps1
test_pwsh:
name: PowerShell
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Init and Test
shell: pwsh
run: |
.\test\bin\init.ps1
.\test\bin\test.ps1

View File

@@ -27,6 +27,7 @@
- **checkver:** Fix output with '-Version' ([#3774](https://github.com/ScoopInstaller/Scoop/issues/3774))
- **schema:** Add '$schema' property ([#4623](https://github.com/ScoopInstaller/Scoop/issues/4623))
- **schema:** Add explicit escape to opening bracket matcher in jp/jsonpath regex ([#3719](https://github.com/ScoopInstaller/Scoop/issues/3719))
- **tests:** Support both AppVeyor and GitHub Actions ([#4655](https://github.com/ScoopInstaller/Scoop/issues/4655))
- **vscode-settings:** Remove 'formatOnSave' trigger ([#4635](https://github.com/ScoopInstaller/Scoop/issues/4635))
### Styles

View File

@@ -5,7 +5,7 @@
# Only diagnostic records of the specified severity will be generated.
# Uncomment the following line if you only want Errors and Warnings but
# not Information diagnostic records.
Severity = @('Error','Warning')
Severity = @('Error')
# Analyze **only** the following rules. Use IncludeRules when you want
# to invoke only a small subset of the defualt rules.

View File

@@ -4,31 +4,32 @@ branches:
- gh-pages
build: false
deploy: false
clone_depth: 49
image: Visual Studio 2019
clone_depth: 2
image: Visual Studio 2022
environment:
scoop: C:\projects\scoop
scoop_home: C:\projects\scoop
matrix:
- PowerShell: 5
- PowerShell: 6
cache:
- '%USERPROFILE%\Documents\WindowsPowerShell\Modules -> appveyor.yml, test\bin\*.ps1'
- C:\projects\helpers -> appveyor.yml, test\bin\*.ps1
- PowerShell: 7
matrix:
fast_finish: true
for:
- matrix:
only:
- PowerShell: 5
cache:
- '%USERPROFILE%\Documents\WindowsPowerShell\Modules -> appveyor.yml, test\bin\*.ps1'
- C:\projects\helpers -> appveyor.yml, test\bin\*.ps1
install:
- ps: . "$env:SCOOP_HOME\test\bin\init.ps1"
- ps: .\test\bin\init.ps1
test_script:
- ps: . "$env:SCOOP_HOME\test\bin\test.ps1" -TestPath "$env:APPVEYOR_BUILD_FOLDER"
- ps: .\test\bin\test.ps1
- matrix:
only:
- PowerShell: 6
- PowerShell: 7
cache:
- '%USERPROFILE%\Documents\PowerShell\Modules -> appveyor.yml, test\bin\*.ps1'
- C:\projects\helpers -> appveyor.yml, test\bin\*.ps1
install:
- pwsh: . "$env:SCOOP_HOME\test\bin\init.ps1"
- pwsh: .\test\bin\init.ps1
test_script:
- pwsh: . "$env:SCOOP_HOME\test\bin\test.ps1" -TestPath "$env:APPVEYOR_BUILD_FOLDER"
- pwsh: .\test\bin\test.ps1

View File

@@ -1,22 +1,14 @@
[CmdletBinding()]
#Requires -Version 5.0
#Requires -Modules @{ ModuleName = 'Pester'; RequiredVersion = '4.10.1' }
param(
[ValidateNotNullOrEmpty()]
[String]
$repo_dir = (Get-Item $MyInvocation.PSScriptRoot).FullName
$repo_dir = (Split-Path -Path $MyInvocation.PSCommandPath -Parent)
)
. "$psscriptroot\Scoop-TestLib.ps1"
. "$psscriptroot\..\lib\core.ps1"
. "$psscriptroot\..\lib\manifest.ps1"
. "$psscriptroot\..\lib\unix.ps1"
$repo_files = @(Get-ChildItem $repo_dir -File -Recurse)
$project_file_exclusions = @(
'[\\/]\.git[\\/]',
'.sublime-workspace$',
'.DS_Store$'
)
. "$PSScriptRoot\Scoop-TestLib.ps1"
. "$PSScriptRoot\..\lib\manifest.ps1"
. "$PSScriptRoot\..\lib\unix.ps1"
$bucketdir = $repo_dir
if (Test-Path("$repo_dir\..\bucket")) {
@@ -25,5 +17,112 @@ if (Test-Path("$repo_dir\..\bucket")) {
$bucketdir = "$repo_dir\bucket"
}
. "$psscriptroot\Import-File-Tests.ps1"
. "$psscriptroot\Scoop-Manifest.Tests.ps1" -bucketdir $bucketdir
# Tests for non manifest files
$repo_files = @(Get-ChildItem -Path $repo_dir -File -Recurse)
$project_file_exclusions = @(
'[\\/]\.git[\\/]',
'.sublime-workspace$',
'.DS_Store$'
)
. "$PSScriptRoot\Import-File-Tests.ps1"
# Tests for manifest files
Describe 'Manifest Validator' -Tag 'Validator' {
BeforeAll {
$schema = "$PSScriptRoot\..\schema.json"
$working_dir = setup_working 'manifest'
Add-Type -Path "$PSScriptRoot\..\supporting\validator\bin\Newtonsoft.Json.dll"
Add-Type -Path "$PSScriptRoot\..\supporting\validator\bin\Newtonsoft.Json.Schema.dll"
Add-Type -Path "$PSScriptRoot\..\supporting\validator\bin\Scoop.Validator.dll"
}
It 'Scoop.Validator is available' {
([System.Management.Automation.PSTypeName]'Scoop.Validator').Type | Should -Be 'Scoop.Validator'
}
Context 'parse_json function' {
It 'fails with invalid json' {
{ parse_json "$working_dir\broken_wget.json" } | Should -Throw
}
}
Context 'schema validation' {
It 'fails with broken schema' {
$validator = New-Object Scoop.Validator("$working_dir\broken_schema.json", $true)
$validator.Validate("$working_dir\wget.json") | Should -BeFalse
$validator.Errors.Count | Should -Be 1
$validator.Errors | Select-Object -First 1 | Should -Match 'broken_schema.*(line 6).*(position 4)'
}
It 'fails with broken manifest' {
$validator = New-Object Scoop.Validator($schema, $true)
$validator.Validate("$working_dir\broken_wget.json") | Should -BeFalse
$validator.Errors.Count | Should -Be 1
$validator.Errors | Select-Object -First 1 | Should -Match 'broken_wget.*(line 5).*(position 4)'
}
It 'fails with invalid manifest' {
$validator = New-Object Scoop.Validator($schema, $true)
$validator.Validate("$working_dir\invalid_wget.json") | Should -BeFalse
$validator.Errors.Count | Should -Be 16
$validator.Errors | Select-Object -First 1 | Should -Match "Property 'randomproperty' has not been defined and the schema does not allow additional properties\."
$validator.Errors | Select-Object -Last 1 | Should -Match 'Required properties are missing from object: version, description\.'
}
}
}
Describe 'manifest validates against the schema' -Tag 'Manifests' {
BeforeAll {
$schema = "$PSScriptRoot\..\schema.json"
$changed_manifests = @()
if ($env:CI -eq $true) {
# AppVeyor
$commit = if ($env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT) { $env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT } else { $env:APPVEYOR_REPO_COMMIT }
# GitHub Actions
if ($env:GITHUB_SHA) {
$commit = $env:GITHUB_SHA
}
$changed_manifests = (Get-GitChangedFile -Path $repo_dir -Include '*.json' -Commit $commit)
}
$manifest_files = Get-ChildItem $bucketdir *.json
$validator = New-Object Scoop.Validator($schema, $true)
}
$quota_exceeded = $false
$manifest_files | ForEach-Object {
$skip_manifest = ($changed_manifests -inotcontains $_.FullName)
if ($env:CI -ne $true -or $changed_manifests -imatch 'schema.json') {
$skip_manifest = $false
}
It "$_" -Skip:$skip_manifest {
$file = $_ # exception handling may overwrite $_
if (!($quota_exceeded)) {
try {
$validator.Validate($file.fullname)
if ($validator.Errors.Count -gt 0) {
Write-Host -f red " [-] $_ has $($validator.Errors.Count) Error$(If($validator.Errors.Count -gt 1) { 's' })!"
Write-Host -f yellow $validator.ErrorsAsString
}
$validator.Errors.Count | Should -Be 0
} catch {
if ($_.exception.message -like '*The free-quota limit of 1000 schema validations per hour has been reached.*') {
$quota_exceeded = $true
Write-Host -f darkyellow 'Schema validation limit exceeded. Will skip further validations.'
} else {
throw
}
}
}
$manifest = parse_json $file.fullname
$url = arch_specific 'url' $manifest '32bit'
$url64 = arch_specific 'url' $manifest '64bit'
if (!$url) {
$url = $url64
}
$url | Should -Not -BeNullOrEmpty
}
}
}

View File

@@ -32,7 +32,7 @@ Describe 'add_alias' -Tag 'Scoop' {
}
}
Describe 'rm_alias' {
Describe 'rm_alias' -Tag 'Scoop' {
Mock shimdir { 'TestDrive:\shim' }
Mock set_config { }
Mock get_config { @{} }

View File

@@ -1,6 +1,6 @@
$repo_dir = (Get-Item $MyInvocation.MyCommand.Path).directory.parent.FullName
Describe -Tag 'Linter' 'PSScriptAnalyzer' {
Describe 'PSScriptAnalyzer' -Tag 'Linter' {
$scoop_modules = Get-ChildItem $repo_dir -Recurse -Include *.psd1, *.psm1, *.ps1
$scoop_modules = $scoop_modules | Where-Object { $_.DirectoryName -notlike '*\supporting*' -and $_.DirectoryName -notlike '*\test*' }
$scoop_modules = $scoop_modules | Select-Object -ExpandProperty Directory -Unique

View File

@@ -1,97 +0,0 @@
param($bucketdir = "$PSScriptRoot\..\bucket")
. "$PSScriptRoot\Scoop-TestLib.ps1"
. "$PSScriptRoot\..\lib\core.ps1"
. "$PSScriptRoot\..\lib\manifest.ps1"
Describe 'Manifest Validator' -Tag 'Validator' {
BeforeAll {
$working_dir = setup_working 'manifest'
$schema = "$PSScriptRoot/../schema.json"
Add-Type -Path "$PSScriptRoot\..\supporting\validator\bin\Newtonsoft.Json.dll"
Add-Type -Path "$PSScriptRoot\..\supporting\validator\bin\Newtonsoft.Json.Schema.dll"
Add-Type -Path "$PSScriptRoot\..\supporting\validator\bin\Scoop.Validator.dll"
}
It 'Scoop.Validator is available' {
([System.Management.Automation.PSTypeName]'Scoop.Validator').Type | Should -Be 'Scoop.Validator'
}
Context 'parse_json function' {
It 'fails with invalid json' {
{ parse_json "$working_dir\broken_wget.json" } | Should -Throw
}
}
Context 'schema validation' {
It 'fails with broken schema' {
$validator = New-Object Scoop.Validator("$working_dir/broken_schema.json", $true)
$validator.Validate("$working_dir/wget.json") | Should -BeFalse
$validator.Errors.Count | Should -Be 1
$validator.Errors | Select-Object -First 1 | Should -Match 'broken_schema.*(line 6).*(position 4)'
}
It 'fails with broken manifest' {
$validator = New-Object Scoop.Validator($schema, $true)
$validator.Validate("$working_dir/broken_wget.json") | Should -BeFalse
$validator.Errors.Count | Should -Be 1
$validator.Errors | Select-Object -First 1 | Should -Match 'broken_wget.*(line 5).*(position 4)'
}
It 'fails with invalid manifest' {
$validator = New-Object Scoop.Validator($schema, $true)
$validator.Validate("$working_dir/invalid_wget.json") | Should -BeFalse
$validator.Errors.Count | Should -Be 16
$validator.Errors | Select-Object -First 1 | Should -Match "Property 'randomproperty' has not been defined and the schema does not allow additional properties\."
$validator.Errors | Select-Object -Last 1 | Should -Match 'Required properties are missing from object: version, description\.'
}
}
}
Describe 'manifest validates against the schema' -Tag 'Manifests' {
BeforeAll {
$changed_manifests = @()
if ($env:CI -eq $true) {
$commit = if ($env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT) { $env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT } else { $env:APPVEYOR_REPO_COMMIT }
$changed_manifests = (Get-GitChangedFile -Include 'bucket\*.json' -Commit $commit)
}
$manifest_files = Get-ChildItem $bucketdir *.json
$validator = New-Object Scoop.Validator($schema, $true)
}
$quota_exceeded = $false
$manifest_files | ForEach-Object {
$skip_manifest = ($changed_manifests -inotcontains $_.FullName)
if ($env:CI -ne $true -or $changed_manifests -imatch 'schema.json') {
$skip_manifest = $false
}
It "$_" -Skip:$skip_manifest {
$file = $_ # exception handling may overwrite $_
if (!($quota_exceeded)) {
try {
$validator.Validate($file.fullname)
if ($validator.Errors.Count -gt 0) {
Write-Host -f red " [-] $_ has $($validator.Errors.Count) Error$(If($validator.Errors.Count -gt 1) { 's' })!"
Write-Host -f yellow $validator.ErrorsAsString
}
$validator.Errors.Count | Should -Be 0
} catch {
if ($_.exception.message -like '*The free-quota limit of 1000 schema validations per hour has been reached.*') {
$quota_exceeded = $true
Write-Host -f darkyellow 'Schema validation limit exceeded. Will skip further validations.'
} else {
throw
}
}
}
$manifest = parse_json $file.fullname
$url = arch_specific 'url' $manifest '32bit'
$url64 = arch_specific 'url' $manifest '64bit'
if (!$url) {
$url = $url64
}
$url | Should -Not -BeNullOrEmpty
}
}
}

View File

@@ -1,20 +1,6 @@
#Requires -Version 5.0
Write-Host "PowerShell: $($PSVersionTable.PSVersion)"
Write-Host (7z.exe | Select-String -Pattern '7-Zip').ToString()
Write-Host 'Install dependencies ...'
Write-Host 'Install testsuite dependencies ...'
Install-Module -Repository PSGallery -Scope CurrentUser -Force -Name Pester -RequiredVersion 4.10.1 -SkipPublisherCheck
Install-Module -Repository PSGallery -Scope CurrentUser -Force -Name PSScriptAnalyzer, BuildHelpers
if ($env:CI -eq $true) {
Write-Host "Load 'BuildHelpers' environment variables ..."
Set-BuildEnvironment -Force
}
$buildVariables = ( Get-ChildItem -Path 'Env:' ).Where( { $_.Name -match '^(?:BH|CI(?:_|$)|APPVEYOR)' } )
$buildVariables += ( Get-Variable -Name 'CI_*' -Scope 'Script' )
$details = $buildVariables |
Where-Object -FilterScript { $_.Name -notmatch 'EMAIL' } |
Sort-Object -Property 'Name' |
Format-Table -AutoSize -Property 'Name', 'Value' |
Out-String
Write-Host 'CI variables:'
Write-Host $details -ForegroundColor DarkGray

View File

@@ -3,7 +3,7 @@
#Requires -Modules @{ ModuleName = 'Pester'; RequiredVersion = '4.10.1' }
#Requires -Modules @{ ModuleName = 'PSScriptAnalyzer'; ModuleVersion = '1.17.1' }
param(
[String] $TestPath = 'test/'
[String] $TestPath = $(Resolve-Path "$PSScriptRoot\..\")
)
$splat = @{
@@ -11,92 +11,110 @@ $splat = @{
PassThru = $true
}
$excludes = @()
if ($env:CI -eq $true) {
$resultsXml = "$PSScriptRoot/TestResults.xml"
Write-Host "Load 'BuildHelpers' environment variables ..."
Set-BuildEnvironment -Force
$CI_WIN = (($env:RUNNER_OS -eq 'Windows') -or ($env:CI_WINDOWS -eq $true))
$splat += @{
OutputFile = $resultsXml
OutputFormat = 'NUnitXML'
}
$excludes = @()
$commit = $env:BHCommitHash
$commitMessage = $env:BHCommitMessage
$commit = if ($env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT) { $env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT } else { $env:APPVEYOR_REPO_COMMIT }
$commitMessage = "$env:APPVEYOR_REPO_COMMIT_MESSAGE $env:APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED".TrimEnd()
if ($commitMessage -match '!linter') {
Write-Warning "Skipping code linting per commit flag '!linter'"
$excludes += 'Linter'
}
$changed_scripts = (Get-GitChangedFile -Include '*.ps1' -Commit $commit)
if (!$changed_scripts) {
Write-Warning "Skipping tests and code linting for *.ps1 files because they didn't change"
$excludes += 'Linter'
$excludes += 'Scoop'
}
if (!($changed_scripts -like '*decompress.ps1')) {
Write-Warning "Skipping tests and code linting for decompress.ps1 files because it didn't change"
$excludes += 'Decompress'
}
if ($env:CI_WINDOWS -ne $true) {
Write-Warning 'Skipping tests and code linting for decompress.ps1 because they only work on Windows'
$excludes += 'Decompress'
}
if ($commitMessage -match '!manifests') {
Write-Warning "Skipping manifest validation per commit flag '!manifests'"
$excludes += 'Manifests'
}
$changed_manifests = (Get-GitChangedFile -Include 'bucket\*.json' -Commit $commit)
if (!$changed_manifests) {
Write-Warning "Skipping tests and validation for manifest files because they didn't change"
$excludes += 'Manifests'
}
if ('Decompress' -notin $excludes) {
Write-Host 'Install decompress dependencies ...'
$env:SCOOP_HELPERS_PATH = 'C:\projects\helpers'
if (!(Test-Path $env:SCOOP_HELPERS_PATH)) {
New-Item -ItemType Directory -Path $env:SCOOP_HELPERS_PATH
# Check if tests are called from the Core itself, if so, adding excludes
if ($TestPath -eq $(Resolve-Path "$PSScriptRoot\..\")) {
if ($commitMessage -match '!linter') {
Write-Warning "Skipping code linting per commit flag '!linter'"
$excludes += 'Linter'
}
if (!(Test-Path "$env:SCOOP_HELPERS_PATH\lessmsi\lessmsi.exe")) {
Start-FileDownload 'https://github.com/activescott/lessmsi/releases/download/v1.10.0/lessmsi-v1.10.0.zip' -FileName "$env:SCOOP_HELPERS_PATH\lessmsi.zip"
& 7z.exe x "$env:SCOOP_HELPERS_PATH\lessmsi.zip" -o"$env:SCOOP_HELPERS_PATH\lessmsi" -y
if (!$CI_WIN) {
Write-Warning 'Skipping tests and code linting for decompress.ps1 because they only work on Windows'
$excludes += 'Decompress'
}
$changedScripts = (Get-GitChangedFile -Include '*.ps1' -Commit $commit)
if (!$changedScripts) {
Write-Warning "Skipping tests and code linting for *.ps1 files because they didn't change"
$excludes += 'Linter'
$excludes += 'Scoop'
}
if (!($changedScripts -like '*decompress.ps1') -and !($changedScripts -like '*Decompress.Tests.ps1')) {
Write-Warning "Skipping tests and code linting for decompress.ps1 files because it didn't change"
$excludes += 'Decompress'
}
if ('Decompress' -notin $excludes) {
Write-Host 'Install decompress dependencies ...'
$env:SCOOP_HELPERS_PATH = 'C:\projects\helpers'
if (!(Test-Path $env:SCOOP_HELPERS_PATH)) {
New-Item -ItemType Directory -Path $env:SCOOP_HELPERS_PATH
}
$env:SCOOP_LESSMSI_PATH = "$env:SCOOP_HELPERS_PATH\lessmsi\lessmsi.exe"
}
if (!(Test-Path "$env:SCOOP_HELPERS_PATH\innounp\innounp.exe")) {
Start-FileDownload 'https://raw.githubusercontent.com/ScoopInstaller/Binary/master/innounp/innounp050.rar' -FileName "$env:SCOOP_HELPERS_PATH\innounp.rar"
& 7z.exe x "$env:SCOOP_HELPERS_PATH\innounp.rar" -o"$env:SCOOP_HELPERS_PATH\innounp" -y
if (!(Test-Path $env:SCOOP_LESSMSI_PATH)) {
$source = 'https://github.com/activescott/lessmsi/releases/download/v1.10.0/lessmsi-v1.10.0.zip'
$destination = "$env:SCOOP_HELPERS_PATH\lessmsi.zip"
Invoke-WebRequest -Uri $source -OutFile $destination
& 7z.exe x "$env:SCOOP_HELPERS_PATH\lessmsi.zip" -o"$env:SCOOP_HELPERS_PATH\lessmsi" -y | Out-Null
}
$env:SCOOP_INNOUNP_PATH = "$env:SCOOP_HELPERS_PATH\innounp\innounp.exe"
if (!(Test-Path $env:SCOOP_INNOUNP_PATH)) {
$source = 'https://raw.githubusercontent.com/ScoopInstaller/Binary/master/innounp/innounp050.rar'
$destination = "$env:SCOOP_HELPERS_PATH\innounp.rar"
Invoke-WebRequest -Uri $source -OutFile $destination
& 7z.exe x "$env:SCOOP_HELPERS_PATH\innounp.rar" -o"$env:SCOOP_HELPERS_PATH\innounp" -y | Out-Null
}
# Only download zstd for AppVeyor, GitHub Actions has zstd installed by default
if ($env:BHBuildSystem -eq 'AppVeyor') {
$env:SCOOP_ZSTD_PATH = "$env:SCOOP_HELPERS_PATH\zstd\zstd.exe"
if (!(Test-Path $env:SCOOP_ZSTD_PATH)) {
$source = 'https://github.com/facebook/zstd/releases/download/v1.5.1/zstd-v1.5.1-win32.zip'
$destination = "$env:SCOOP_HELPERS_PATH\zstd.zip"
Invoke-WebRequest -Uri $source -OutFile $destination
& 7z.exe x "$env:SCOOP_HELPERS_PATH\zstd.zip" -o"$env:SCOOP_HELPERS_PATH\zstd" -y | Out-Null
}
} else {
$env:SCOOP_ZSTD_PATH = (Get-Command zstd.exe).Path
}
}
if (!(Test-Path "$env:SCOOP_HELPERS_PATH\zstd\zstd.exe")) {
Start-FileDownload 'https://github.com/facebook/zstd/releases/download/v1.5.1/zstd-v1.5.1-win32.zip' -FileName "$env:SCOOP_HELPERS_PATH\zstd.zip"
& 7z.exe x "$env:SCOOP_HELPERS_PATH\zstd.zip" -o"$env:SCOOP_HELPERS_PATH\zstd" -y
$env:SCOOP_ZSTD_PATH = "$env:SCOOP_HELPERS_PATH\zstd\zstd.exe"
}
if ($excludes.Length -gt 0) {
$splat.ExcludeTag = $excludes
}
# Display CI environment variables
$buildVariables = ( Get-ChildItem -Path 'Env:' ).Where( { $_.Name -match '^(?:BH|CI(?:_|$)|APPVEYOR|GITHUB_|RUNNER_|SCOOP_)' } )
$buildVariables += ( Get-Variable -Name 'CI_*' -Scope 'Script' )
$details = $buildVariables |
Where-Object -FilterScript { $_.Name -notmatch 'EMAIL' } |
Sort-Object -Property 'Name' |
Format-Table -AutoSize -Property 'Name', 'Value' |
Out-String
Write-Host 'CI variables:'
Write-Host $details -ForegroundColor DarkGray
# AppVeyor
if ($env:BHBuildSystem -eq "AppVeyor") {
$resultsXml = "$PSScriptRoot\TestResults.xml"
$splat += @{
OutputFile = $resultsXml
OutputFormat = 'NUnitXML'
}
Write-Host 'Invoke-Pester' @splat
$result = Invoke-Pester @splat
(New-Object Net.WebClient).UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", $resultsXml)
exit $result.FailedCount
}
}
if (!(Test-Path "$PSScriptRoot\..\..\bucket")) {
Write-Warning 'Skipping tests and validation for manifest files because there is no bucket'
$excludes += 'Manifests'
}
if ($excludes.Length -gt 0) {
$splat.ExcludeTag = $excludes
}
# GitHub Actions / Local
Write-Host 'Invoke-Pester' @splat
$result = Invoke-Pester @splat
if ($env:CI -eq $true) {
(New-Object Net.WebClient).UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", $resultsXml)
}
if ($result.FailedCount -gt 0) {
exit $result.FailedCount
}
exit $result.FailedCount