From 073553bd7ccc08749ff4751c8c2304339330b9fe Mon Sep 17 00:00:00 2001 From: Adrian Vladu Date: Tue, 24 Sep 2024 09:30:02 +0300 Subject: [PATCH] Add github actions Github actions for: * PSScryptAnalyzer * Pester minimal functional mocked testing --- .github/workflows/tests.yml | 63 +++++++++++++++++++++++++++++++++ Tests/WinImageBuilder.Tests.ps1 | 5 ++- appveyor.yml | 20 ----------- 3 files changed, 67 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/tests.yml delete mode 100644 appveyor.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..52a6e900 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,63 @@ +name: Windows Image Builder tests + +on: [push, pull_request] + +jobs: + code_checks: + runs-on: windows-2019 + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - name: Install Dependencies + shell: powershell + run: | + Install-Module -Force -AllowClobber -Confirm:$false "PSScriptAnalyzer" + - name: Run code checks + shell: powershell + run: | + $rules = @("PSProvideCommentHelp","PSUseDeclaredVarsMoreThanAssignments","PSAvoidUsingEmptyCatchBlock","PSAvoidUsingCmdletAliases","PSAvoidDefaultValueForMandatoryParameter","PSAvoidDefaultValueSwitchParameter","PSUseToExportFieldsInManifest","PSAvoidUsingPositionalParameters"); + $resScryptAnalyzer = Invoke-ScriptAnalyzer -Path . -IncludeRule $rules; + if ($resScryptAnalyzer.Count -gt 0) { + throw "$($resScryptAnalyzer.Count) failed style warnings found." + } + functional_tests_2019: + runs-on: windows-2019 + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - name: Install Dependencies + shell: powershell + run: | + Uninstall-Module "Pester" -Force + Install-Module -Force -AllowClobber -Confirm:$false "Pester" -RequiredVersion 4.10.1 -SkipPublisherCheck + - name: Run code checks + shell: powershell + run: | + Import-Module Pester + $res = Invoke-Pester -OutputFormat NUnitXml -OutputFile TestsResults.xml -PassThru + if (($res.FailedCount -gt 0)) { + Get-Content -Path TestsResults.xml -Encoding Ascii | Write-Output + throw "$($res.FailedCount) Pester tests failed." + } + functional_tests_latest: + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - name: Install Dependencies + shell: powershell + run: | + Uninstall-Module "Pester" -Force + Install-Module -Force -AllowClobber -Confirm:$false "Pester" -RequiredVersion 4.10.1 -SkipPublisherCheck + - name: Run code checks + shell: powershell + run: | + Import-Module Pester + $res = Invoke-Pester -OutputFormat NUnitXml -OutputFile TestsResults.xml -PassThru + if (($res.FailedCount -gt 0)) { + Get-Content -Path TestsResults.xml -Encoding Ascii | Write-Output + throw "$($res.FailedCount) Pester tests failed." + } diff --git a/Tests/WinImageBuilder.Tests.ps1 b/Tests/WinImageBuilder.Tests.ps1 index fb8c8e5c..cba4fd46 100644 --- a/Tests/WinImageBuilder.Tests.ps1 +++ b/Tests/WinImageBuilder.Tests.ps1 @@ -74,7 +74,10 @@ function Get-VMSwitch {} function Optimize-VHD {} -Import-Module $modulePath +$LastErrorActionPreference = $ErrorActionPreference +$ErrorActionPreference = "Stop" +Import-Module "${modulePath}" +$ErrorActionPreference = $LastErrorActionPreference Describe "Test New-WindowsCloudImage" { Mock Write-Host -Verifiable -ModuleName $moduleName { return 0 } diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 33f5552a..00000000 --- a/appveyor.yml +++ /dev/null @@ -1,20 +0,0 @@ -version: 1.0.{build} - -branches: - only: - - master - -build: false - -install: - - cinst pester - - git submodule update --init --recursive - -test_script: - - ps: Install-Module -Name PSScriptAnalyzer - - ps: $rules = @("PSProvideCommentHelp","PSUseDeclaredVarsMoreThanAssignments","PSAvoidUsingEmptyCatchBlock","PSAvoidUsingCmdletAliases","PSAvoidDefaultValueForMandatoryParameter","PSAvoidDefaultValueSwitchParameter","PSUseToExportFieldsInManifest","PSAvoidUsingPositionalParameters") - - ps: $resScryptAnalyzer = Invoke-ScriptAnalyzer -Path . -IncludeRule $rules - - ps: echo $resScryptAnalyzer - - ps: $res = Invoke-Pester -OutputFormat NUnitXml -OutputFile TestsResults.xml -PassThru - - ps: (New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\TestsResults.xml)) - - ps: if (($res.FailedCount -gt 0) -or ($resScryptAnalyzer.Count -gt 0)) { throw "$($res.FailedCount) Pester tests failed. $($resScryptAnalyzer.Count) failed style warnings found."}