From 2cab84f72ef2f04113a787f1569a8995143c0ca3 Mon Sep 17 00:00:00 2001 From: Joel Bennett Date: Sat, 8 Feb 2025 17:31:21 -0500 Subject: [PATCH 1/3] Try again to fix path problems so we test the right module --- .github/workflows/build.yml | 50 +++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3eb5114..d41e5b4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -32,10 +32,13 @@ jobs: NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} PSGALLERY_API_KEY: ${{ secrets.PSGALLERY_API_KEY }} - - uses: actions/upload-artifact@v4 + - name: Upload Built Modules + uses: actions/upload-artifact@v4 with: - name: ModuleBuilder - path: Modules/ModuleBuilder + name: Modules + path: | + Modules/* + !Modules/*-TestResults - uses: actions/upload-artifact@v4 with: @@ -62,33 +65,42 @@ jobs: matrix: os: [windows-latest, ubuntu-latest, macos-latest] steps: - - name: Download Build Output + - name: Download build.requires.psd1 uses: actions/download-artifact@v4 with: - name: ModuleBuilder - path: Modules/ModuleBuilder # /home/runner/work/ModuleBuilder/ModuleBuilder/Modules/ModuleBuilder + name: build.requires.psd1 - name: Download Pester Tests uses: actions/download-artifact@v4 with: name: PesterTests path: PesterTests - - name: Download build.requires.psd1 + - name: Download Build Output uses: actions/download-artifact@v4 with: - name: build.requires.psd1 - - name: ⚡ Install PowerShell Modules - uses: JustinGrote/ModuleFast-action@v0.0.1 - - name: Put Build output in PATH - shell: pwsh - run: | # PowerShell - Convert-Path Modules -OutVariable BuiltModules - Add-Content -Path $env:GITHUB_PATH -Value $BuiltModules -Encoding utf8 - # Uninstall the "installed" copy of ModuleBuilder - Get-Module -Name ModuleBuilder -List | Where ModuleBase -notmatch ([regex]::escape($pwd)) | Split-Path | Remove-Item -Recurse -Force - - name: Put Build output in PATH + name: Modules + path: Modules # /home/runner/work/ModuleBuilder/ModuleBuilder/Modules + - name: Install Output Modules shell: pwsh run: | # PowerShell - $Env:PATH -split ([IO.Path]::PathSeparator) | Out-Host + $ModuleDestination = if ($IsWindows) { + Join-Path ([Environment]::GetFolderPath('MyDocuments')) 'PowerShell/Modules' + } else { + Join-Path $HOME '.local/share/powershell/Modules' + } + + Get-ChildItem -Directory Modules -OutVariable Modules + | Move-Item -Destination { Join-Path $ModuleDestination $_.Name } -Force + + Write-Host "Installing $($Modules -join ', ') to $ModuleDestination" + Get-ChildItem -Directory $ModuleDestination + Write-Host "PSModulePath:" + $Env:PSModulePath -split ([IO.Path]::PathSeparator) | Out-Host + + @(Get-Content build.requires.psd1) + | Where { $_ -notmatch "ModuleBuilder"} + | Set-Content build.requires.psd1 + - name: ⚡ Install Required Modules + uses: JustinGrote/ModuleFast-action@v0.0.1 - name: Invoke Pester Tests id: pester uses: zyborg/pester-tests-report@v1 From 329c4d599a0994018d87c89dacbd75461735d490 Mon Sep 17 00:00:00 2001 From: Joel Bennett Date: Sat, 8 Feb 2025 18:16:29 -0500 Subject: [PATCH 2/3] Fail on failure --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d41e5b4..e1ad9fe 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -82,6 +82,7 @@ jobs: - name: Install Output Modules shell: pwsh run: | # PowerShell + # https://docs.github.com/en/actions/use-cases-and-examples/building-and-testing/building-and-testing-powershell#powershell-module-locations $ModuleDestination = if ($IsWindows) { Join-Path ([Environment]::GetFolderPath('MyDocuments')) 'PowerShell/Modules' } else { @@ -111,6 +112,7 @@ jobs: report_name: module_tests report_title: My Module Tests github_token: ${{ secrets.GITHUB_TOKEN }} + tests_fail_step: true - name: dump test results shell: pwsh run: | # PowerShell From ae6689f09904498bba0c65e28ec71522fa961184 Mon Sep 17 00:00:00 2001 From: Joel Bennett Date: Sat, 8 Feb 2025 18:20:44 -0500 Subject: [PATCH 3/3] Summarize the Pester results (no report) --- .github/workflows/build.yml | 16 ++++++++++------ Install-RequiredModule.ps1 | 15 --------------- build.requires.psd1 | 4 +++- 3 files changed, 13 insertions(+), 22 deletions(-) delete mode 100644 Install-RequiredModule.ps1 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e1ad9fe..496d620 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -109,14 +109,18 @@ jobs: # include_paths: tests # exclude_paths: tests/powershell1,tests/powershell2 # exclude_tags: skip_ci - report_name: module_tests + report_name: ${{ matrix.os }}_validation report_title: My Module Tests github_token: ${{ secrets.GITHUB_TOKEN }} tests_fail_step: true - - name: dump test results + skip_check_run: true # Our test results are too large + - name: Summarize test results shell: pwsh run: | # PowerShell - Write-Host 'Total Tests Executed...: ${{ steps.pester.outputs.total_count }}' - Write-Host 'Total Tests PASSED.....: ${{ steps.pester.outputs.passed_count }}' - Write-Host 'Total Tests FAILED.....: ${{ steps.pester.outputs.failed_count }}' - + Write-ActionInfo 'Total Tests Executed...: ${{ steps.pester.outputs.total_count }}' + Write-ActionInfo 'Total Tests Passed.....: ${{ steps.pester.outputs.passed_count }}' + if (${{ steps.pester.outputs.failed_count }} -gt 0) { + Set-ActionFailed 'Total Tests Failed.....: ${{ steps.pester.outputs.failed_count }}' + } else { + Write-ActionInfo 'Total Tests Failed.....: ${{ steps.pester.outputs.failed_count }}' + } diff --git a/Install-RequiredModule.ps1 b/Install-RequiredModule.ps1 deleted file mode 100644 index a9b61c9..0000000 --- a/Install-RequiredModule.ps1 +++ /dev/null @@ -1,15 +0,0 @@ -Push-Location $PSScriptRoot - -# Some people only have a really old version of PowerShellGet that doesn't support pre-release modules -if (!(Get-Command Install-Module -ParameterName 'AllowPrerelease' -ErrorAction 'SilentlyContinue')) { - $Module = Install-Module 'PowerShellGet' -Repository 'PSGallery' -MaximumVersion 2.99 -MinimumVersion 2.2.5 -Force -Scope CurrentUser -PassThru - Remove-Module PowerShellGet - Import-Module PowerShellGet -MinimumVersion $Module.Version -Force -} - -try { - $Script = Install-Script Install-RequiredModule -PassThru -Force - & (Join-Path $Script.InstalledLocation Install-RequiredModule.ps1) -} finally { - Pop-Location -} diff --git a/build.requires.psd1 b/build.requires.psd1 index a5d3175..dde4cd0 100644 --- a/build.requires.psd1 +++ b/build.requires.psd1 @@ -1,4 +1,5 @@ -# https://github.com/marketplace/actions/modulefast +# Run Install-ModuleFast to install the latest version of the required modules +# https://github.com/JustinGrote/ModuleFast @{ Configuration = ":[1.5.0, 2.0)" Metadata = ":[1.5.1, 2.0)" @@ -6,4 +7,5 @@ ModuleBuilder = ":[3.0.0, 4.0)" PSScriptAnalyzer = ":[1.21.0, 2.0)" InvokeBuild = ":[5.10.4, 6.0)" + GitHubActions = ":[1.1.0, 2.0)" }