From 90d62baa6ad575b0da4fd8e393576bed810eba57 Mon Sep 17 00:00:00 2001 From: Stephan van Rooij <1292510+svrooij@users.noreply.github.com> Date: Sat, 4 May 2024 18:00:42 +0200 Subject: [PATCH] ci: First try to test powershell module --- .github/workflows/build.yml | 61 ++++++++++++++++++- .gitignore | 2 + src/Svrooij.WinTuner.CmdLets/WinTuner.psd1 | 18 +++--- .../Deploy-WtMsStoreApp.Tests.ps1 | 6 ++ .../Deploy-WtWin32App.Tests.ps1 | 6 ++ .../Get-WtWin32Apps.Tests.ps1 | 6 ++ .../New-IntuneWinPackage.ps1 | 6 ++ .../NewWtWingetPackage.Tests.ps1 | 6 ++ .../RemoveWtWin32App.Tests.ps1 | 6 ++ .../Unprotect-IntuneWinPackage.ps1 | 6 ++ .../Update-WtIntuneApp.ps1 | 6 ++ tests/WinTuner.Cmdlets.Tests/run.ps1 | 20 ++++++ 12 files changed, 139 insertions(+), 10 deletions(-) create mode 100644 tests/WinTuner.Cmdlets.Tests/Deploy-WtMsStoreApp.Tests.ps1 create mode 100644 tests/WinTuner.Cmdlets.Tests/Deploy-WtWin32App.Tests.ps1 create mode 100644 tests/WinTuner.Cmdlets.Tests/Get-WtWin32Apps.Tests.ps1 create mode 100644 tests/WinTuner.Cmdlets.Tests/New-IntuneWinPackage.ps1 create mode 100644 tests/WinTuner.Cmdlets.Tests/NewWtWingetPackage.Tests.ps1 create mode 100644 tests/WinTuner.Cmdlets.Tests/RemoveWtWin32App.Tests.ps1 create mode 100644 tests/WinTuner.Cmdlets.Tests/Unprotect-IntuneWinPackage.ps1 create mode 100644 tests/WinTuner.Cmdlets.Tests/Update-WtIntuneApp.ps1 create mode 100644 tests/WinTuner.Cmdlets.Tests/run.ps1 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 91f06ff..05280b1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,6 +4,7 @@ on: push: branches: - main + - ci/testing-ps tags: - v* pull_request: @@ -13,7 +14,7 @@ on: jobs: test: - name: πŸ› οΈ Build and Test + name: πŸ› οΈ Build and Test C# runs-on: ubuntu-latest permissions: contents: read @@ -61,6 +62,64 @@ jobs: if: always() run: dotnet format --verify-no-changes + testps: + name: πŸ› οΈ Build and Test PowerShell + runs-on: ubuntu-latest + permissions: + contents: read + issues: read + checks: write + steps: + - name: πŸ‘¨β€πŸ’» Check-out code + uses: actions/checkout@v4 + + - name: πŸ‘¨β€πŸ”§ Setup .NET Core SDK + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.x + + - name: πŸ” Enable problem matchers + run: echo "::add-matcher::.github/matchers/dotnet.json" + + - name: πŸ¦Έβ€β™‚οΈ Restore steriods + uses: actions/cache@v4 + with: + path: ~/.nuget/packages + # Look to see if there is a cache hit for the corresponding requirements file + key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} + restore-keys: | + ${{ runner.os }}-nuget + + - name: πŸŽ’ Load packages + run: dotnet restore + + - name: πŸ› οΈ Build module + shell: pwsh + run: dotnet build ./src/Svrooij.WinTuner.CmdLets/Svrooij.WinTuner.CmdLets.csproj --configuration Release --no-restore -p:Version=$("${{ github.ref_name }}".Substring(1)) -o ./dist/WinTuner + + - name: πŸ“¦ Install Pester + run: Install-Module -Name Pester -Force -SkipPublisherCheck -Scope CurrentUser + + - name: πŸ•΅οΈ Import module and list commands + shell: pwsh + run: | + Import-Module ./dist/WinTuner/WinTuner.psd1 + Get-Command -Module WinTuner + Get-Command -Module WinTuner | Select-Object -ExpandProperty Name | ForEach-Object { Get-Help -Name $_ -Full } + + - name: πŸ§ͺ Run test + shell: pwsh + run: + Import-Module Pester + Import-Module ./dist/WinTuner/WinTuner.psd1 + ./tests/run.ps1 + + - name: Publish Test Results + uses: EnricoMi/publish-unit-test-result-action@v1 + if: always() + with: + files: ./TestResults.xml + publish-nuget: name: πŸ“¦ Publish WinTuner to nuget runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index db8019b..f43c980 100644 --- a/.gitignore +++ b/.gitignore @@ -367,3 +367,5 @@ dist # LUT config file from Visual Studio *.lutconfig + +TestResults.xml \ No newline at end of file diff --git a/src/Svrooij.WinTuner.CmdLets/WinTuner.psd1 b/src/Svrooij.WinTuner.CmdLets/WinTuner.psd1 index 326d712..d3849cf 100644 --- a/src/Svrooij.WinTuner.CmdLets/WinTuner.psd1 +++ b/src/Svrooij.WinTuner.CmdLets/WinTuner.psd1 @@ -58,15 +58,15 @@ # FunctionsToExport = @() # Cmdlets to export from this module. - CmdletsToExport = @( - "Deploy-WtWin32App", - "Get-WtWin32Apps", - "New-IntuneWinPackage", - "New-WtWingetPackage", - "Remove-WtWin32App", - "Unprotect-IntuneWinPackage" - "Update-WtIntuneApp" - ) + # CmdletsToExport = @( + # "Deploy-WtWin32App", + # "Get-WtWin32Apps", + # "New-IntuneWinPackage", + # "New-WtWingetPackage", + # "Remove-WtWin32App", + # "Unprotect-IntuneWinPackage" + # "Update-WtIntuneApp" + # ) # Variables to export from this module. # VariablesToExport = @() diff --git a/tests/WinTuner.Cmdlets.Tests/Deploy-WtMsStoreApp.Tests.ps1 b/tests/WinTuner.Cmdlets.Tests/Deploy-WtMsStoreApp.Tests.ps1 new file mode 100644 index 0000000..e69dcc2 --- /dev/null +++ b/tests/WinTuner.Cmdlets.Tests/Deploy-WtMsStoreApp.Tests.ps1 @@ -0,0 +1,6 @@ +Describe 'Deploy-WtMsStoreApp' { + It 'Should be available' { + $cmdlet = Get-Command -Name 'Deploy-WtMsStoreApp' + $cmdlet.CommandType | Should -Be 'Cmdlet' + } +} \ No newline at end of file diff --git a/tests/WinTuner.Cmdlets.Tests/Deploy-WtWin32App.Tests.ps1 b/tests/WinTuner.Cmdlets.Tests/Deploy-WtWin32App.Tests.ps1 new file mode 100644 index 0000000..2ce8cc2 --- /dev/null +++ b/tests/WinTuner.Cmdlets.Tests/Deploy-WtWin32App.Tests.ps1 @@ -0,0 +1,6 @@ +Describe 'Deploy-WtWin32App' { + It 'Should be available' { + $cmdlet = Get-Command -Name 'Deploy-WtWin32App' + $cmdlet.CommandType | Should -Be 'Cmdlet' + } +} \ No newline at end of file diff --git a/tests/WinTuner.Cmdlets.Tests/Get-WtWin32Apps.Tests.ps1 b/tests/WinTuner.Cmdlets.Tests/Get-WtWin32Apps.Tests.ps1 new file mode 100644 index 0000000..f9bc6b1 --- /dev/null +++ b/tests/WinTuner.Cmdlets.Tests/Get-WtWin32Apps.Tests.ps1 @@ -0,0 +1,6 @@ +Describe 'Get-WtWin32Appsp' { + It 'Should be available' { + $cmdlet = Get-Command -Name 'Get-WtWin32Apps' + $cmdlet.CommandType | Should -Be 'Cmdlet' + } +} \ No newline at end of file diff --git a/tests/WinTuner.Cmdlets.Tests/New-IntuneWinPackage.ps1 b/tests/WinTuner.Cmdlets.Tests/New-IntuneWinPackage.ps1 new file mode 100644 index 0000000..4d32b28 --- /dev/null +++ b/tests/WinTuner.Cmdlets.Tests/New-IntuneWinPackage.ps1 @@ -0,0 +1,6 @@ +Describe 'New-IntuneWinPackage' { + It 'Should be available' { + $cmdlet = Get-Command -Name 'New-IntuneWinPackage' + $cmdlet.CommandType | Should -Be 'Cmdlet' + } +} \ No newline at end of file diff --git a/tests/WinTuner.Cmdlets.Tests/NewWtWingetPackage.Tests.ps1 b/tests/WinTuner.Cmdlets.Tests/NewWtWingetPackage.Tests.ps1 new file mode 100644 index 0000000..de3a223 --- /dev/null +++ b/tests/WinTuner.Cmdlets.Tests/NewWtWingetPackage.Tests.ps1 @@ -0,0 +1,6 @@ +Describe 'New-WtWingetPackage' { + It 'Should be available' { + $cmdlet = Get-Command -Name 'New-WtWingetPackage' + $cmdlet.CommandType | Should -Be 'Cmdlet' + } +} \ No newline at end of file diff --git a/tests/WinTuner.Cmdlets.Tests/RemoveWtWin32App.Tests.ps1 b/tests/WinTuner.Cmdlets.Tests/RemoveWtWin32App.Tests.ps1 new file mode 100644 index 0000000..17f6915 --- /dev/null +++ b/tests/WinTuner.Cmdlets.Tests/RemoveWtWin32App.Tests.ps1 @@ -0,0 +1,6 @@ +Describe 'Remove-WtWin32App' { + It 'Should be available' { + $cmdlet = Get-Command -Name 'Remove-WtWin32App' + $cmdlet.CommandType | Should -Be 'Cmdlet' + } +} \ No newline at end of file diff --git a/tests/WinTuner.Cmdlets.Tests/Unprotect-IntuneWinPackage.ps1 b/tests/WinTuner.Cmdlets.Tests/Unprotect-IntuneWinPackage.ps1 new file mode 100644 index 0000000..a0e6ffc --- /dev/null +++ b/tests/WinTuner.Cmdlets.Tests/Unprotect-IntuneWinPackage.ps1 @@ -0,0 +1,6 @@ +Describe 'Unprotect-IntuneWinPackage' { + It 'Should be available' { + $cmdlet = Get-Command -Name 'Unprotect-IntuneWinPackage' + $cmdlet.CommandType | Should -Be 'Cmdlet' + } +} \ No newline at end of file diff --git a/tests/WinTuner.Cmdlets.Tests/Update-WtIntuneApp.ps1 b/tests/WinTuner.Cmdlets.Tests/Update-WtIntuneApp.ps1 new file mode 100644 index 0000000..1ae2abb --- /dev/null +++ b/tests/WinTuner.Cmdlets.Tests/Update-WtIntuneApp.ps1 @@ -0,0 +1,6 @@ +Describe 'Update-WtIntuneApp' { + It 'Should be available' { + $cmdlet = Get-Command -Name 'Update-WtIntuneApp' + $cmdlet.CommandType | Should -Be 'Cmdlet' + } +} \ No newline at end of file diff --git a/tests/WinTuner.Cmdlets.Tests/run.ps1 b/tests/WinTuner.Cmdlets.Tests/run.ps1 new file mode 100644 index 0000000..164b978 --- /dev/null +++ b/tests/WinTuner.Cmdlets.Tests/run.ps1 @@ -0,0 +1,20 @@ +$pesterConfig = [PesterConfiguration]@{ + Output = @{ + Verbosity = "Normal" + } + OutputFormat = "NUnitXML" + TestResult = @{ + Enabled = $true + Path = "TestResults.xml" + Format = "NUnitXML" + } + Run = @{ + Path = "./tests/WinTuner.Cmdlets.Tests" + Exit = $true + } + Should = @{ + ErrorAction = "Continue" + } +} + +Invoke-Pester -Configuration $pesterConfig \ No newline at end of file