diff --git a/.github/workflows/Tests.yml b/.github/workflows/Tests.yml new file mode 100644 index 0000000..3f2dd16 --- /dev/null +++ b/.github/workflows/Tests.yml @@ -0,0 +1,27 @@ +name: Run Tests + +# Controls when the workflow will run +on: + push: + branches: + - main + pull_request: + branches: + - main + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install ModuleTools module form PSGallery + run: | + Install-PSResource -Repository PSGallery -Name ModuleTools -TrustRepository + shell: pwsh + + - name: Install ModuleTools module form PSGallery + run: | + Invoke-MTTest + shell: pwsh diff --git a/project.json b/project.json index 459db85..7cb8f58 100644 --- a/project.json +++ b/project.json @@ -19,7 +19,10 @@ "LicenseUri": "https://github.com/belibug/SecretBackup/blob/main/LICENSE" }, "Pester": { - "TestResult": false, + "TestResult": { + "Enabled": true, + "OutputFormat": "NUnitXml" + }, "Output": { "Verbosity": "Detailed" } @@ -35,4 +38,4 @@ "PSAvoidUsingConvertToSecureStringWithPlainText" ] } -} +} \ No newline at end of file diff --git a/tests/integration/Module.Tests.ps1 b/tests/Module.Tests.ps1 similarity index 88% rename from tests/integration/Module.Tests.ps1 rename to tests/Module.Tests.ps1 index d0c644a..33e87d0 100644 --- a/tests/integration/Module.Tests.ps1 +++ b/tests/Module.Tests.ps1 @@ -1,6 +1,5 @@ BeforeAll { - Import-Module -Name .\PSPacker - $data = Import-ProjectData + $data = Get-MTProjectInfo } Describe 'General Module Control' { diff --git a/tests/integration/OutputFiles.Tests.ps1 b/tests/OutputFiles.Tests.ps1 similarity index 89% rename from tests/integration/OutputFiles.Tests.ps1 rename to tests/OutputFiles.Tests.ps1 index 960cd56..ce71a5e 100644 --- a/tests/integration/OutputFiles.Tests.ps1 +++ b/tests/OutputFiles.Tests.ps1 @@ -1,6 +1,5 @@ BeforeAll { - Import-Module -Name .\PSPacker - $data = Import-ProjectData + $data = Get-MTProjectInfo $files = Get-ChildItem $data.OutputModuleDir } @@ -19,8 +18,7 @@ Describe 'Module and Manifest testing' { $status = (Get-AuthenticodeSignature -FilePath $_).Status if ($status -eq 'NotSigned') { Set-TestInconclusive -Message 'Not yet signed' - } - else { + } else { $status | Should -Be 'Valid' } } diff --git a/tests/meta/ScriptAnalyzer.Tests.ps1 b/tests/ScriptAnalyzer.Tests.ps1 similarity index 72% rename from tests/meta/ScriptAnalyzer.Tests.ps1 rename to tests/ScriptAnalyzer.Tests.ps1 index 6a8df01..52134d9 100644 --- a/tests/meta/ScriptAnalyzer.Tests.ps1 +++ b/tests/ScriptAnalyzer.Tests.ps1 @@ -2,8 +2,11 @@ BeforeDiscovery { $files = Get-ChildItem -Path .\src -Filter '*.ps1' -Recurse } BeforeAll { - Import-Module -Name .\PSPacker -Force - $data = Import-ProjectData + $ScriptAnalyzerSettings = @{ + IncludeDefaultRules = $true + Severity = @('Warning', 'Error') + ExcludeRules = @('PSAvoidUsingWriteHost', 'PSAvoidUsingConvertToSecureStringWithPlainText') + } } Describe 'File: <_.basename>' -ForEach $files { Context 'Code Quality Check' { @@ -14,7 +17,7 @@ Describe 'File: <_.basename>' -ForEach $files { $errors.Count | Should -Be 0 } It 'passess ScriptAnalyzer' { - $saResults = Invoke-ScriptAnalyzer -Path $_ -Settings $data.PSScriptAnalyzer + $saResults = Invoke-ScriptAnalyzer -Path $_ -Settings $ScriptAnalyzerSettings $saResults | Should -BeNullOrEmpty -Because $($saResults.Message -join ';') } }