From e4683a26f5d27339c14dd6fabc0946fc263c7866 Mon Sep 17 00:00:00 2001 From: mdaneri Date: Thu, 1 Aug 2024 14:42:12 -0700 Subject: [PATCH 1/4] Test task improvement - Pode.psm1 dll load improvement --- pode.build.ps1 | 42 +++++++++++++++++++++++++++++++++++++++--- src/Pode.psm1 | 22 ++++++++++++++++------ 2 files changed, 55 insertions(+), 9 deletions(-) diff --git a/pode.build.ps1 b/pode.build.ps1 index 8cdb9b0c3..aadbe9f62 100644 --- a/pode.build.ps1 +++ b/pode.build.ps1 @@ -501,15 +501,51 @@ Task TestNoBuild TestDeps, { else { $Script:TestStatus = Invoke-Pester -Configuration $configuration } - if ($originalUICulture){ + if ($originalUICulture) { Write-Output "Restore UICulture to $originalUICulture" # restore original UICulture [System.Threading.Thread]::CurrentThread.CurrentUICulture = $originalUICulture } }, PushCodeCoverage, CheckFailedTests -# Synopsis: Run tests after a build -Task Test Build, TestNoBuild +# Synopsis: Run tests after a build if needed +Task Test { + + # Get the .NET framework description to determine the runtime version + $frameworkDescription = [System.Runtime.InteropServices.RuntimeInformation]::FrameworkDescription + $found = $false + + # Match and extract the major version number from the framework description + if ($frameworkDescription -match '(\d+)\.(\d+)\.(\d+)') { + $majorVersion = [int]$matches[1] + + # Loop through the major versions from the detected version down to 6 + for ($version = $majorVersion; $version -ge 6; $version--) { + # Check if the corresponding Pode.dll file exists for the version + if (Test-Path "./src/Libs/net$version.0/Pode.dll") { + $found = $true + break + } + } + } + + # If no specific versioned Pode.dll was found, check for the netstandard2.0 version + if (-not $found) { + $found = Test-Path "./src/Libs/netstandard2.0/Pode.dll" + } + + # If any Pode.dll was found, skip the build task + if ($found) { + Write-Output 'Build Task not needed' + } + else { + # If no Pode.dll was found, invoke the build task + Invoke-Build Build + } + + # Always run the test task, assuming that the build task has already been run if needed + Invoke-Build TestNoBuild +} # Synopsis: Check if any of the tests failed diff --git a/src/Pode.psm1 b/src/Pode.psm1 index 700a06a14..992f76a8f 100644 --- a/src/Pode.psm1 +++ b/src/Pode.psm1 @@ -90,15 +90,25 @@ try { } } else { - if ($PSVersionTable.PSVersion -ge [version]'7.4.0') { - Add-Type -LiteralPath "$($root)/Libs/net8.0/Pode.dll" -ErrorAction Stop - } - elseif ($PSVersionTable.PSVersion -ge [version]'7.2.0') { - Add-Type -LiteralPath "$($root)/Libs/net6.0/Pode.dll" -ErrorAction Stop + $frameworkDescription = [System.Runtime.InteropServices.RuntimeInformation]::FrameworkDescription + $loaded = $false + if ($frameworkDescription -match '(\d+)\.(\d+)\.(\d+)') { + $majorVersion = [int]$matches[1] + + for ($version = $majorVersion; $version -ge 6; $version--) { + $dllPath = "$($root)/Libs/net$version.0/Pode.dll" + if (Test-Path $dllPath) { + Add-Type -LiteralPath $dllPath -ErrorAction Stop + $loaded = $true + break + } + } } - else { + + if (-not $loaded) { Add-Type -LiteralPath "$($root)/Libs/netstandard2.0/Pode.dll" -ErrorAction Stop } + } # load private functions From e25d7d419e30fa339b5a693d1e8a4094065f97ac Mon Sep 17 00:00:00 2001 From: mdaneri Date: Fri, 2 Aug 2024 06:29:20 -0700 Subject: [PATCH 2/4] added $ProgressPreference = 'SilentlyContinue' --- .github/workflows/ci-pwsh_preview.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci-pwsh_preview.yml b/.github/workflows/ci-pwsh_preview.yml index 81bb80c3d..4e82924ac 100644 --- a/.github/workflows/ci-pwsh_preview.yml +++ b/.github/workflows/ci-pwsh_preview.yml @@ -66,6 +66,7 @@ jobs: - name: Install Invoke-Build shell: pwsh run: | + $ProgressPreference = 'SilentlyContinue' Install-Module -Name InvokeBuild -RequiredVersion $env:INVOKE_BUILD_VERSION -Force - name: Run Pester Tests From 2489cee349686923e1b9844fcccafac5d59ad9f0 Mon Sep 17 00:00:00 2001 From: mdaneri Date: Fri, 30 Aug 2024 17:35:15 -0700 Subject: [PATCH 3/4] Update ci-pwsh_preview.yml --- .github/workflows/ci-pwsh_preview.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci-pwsh_preview.yml b/.github/workflows/ci-pwsh_preview.yml index 4e82924ac..81bb80c3d 100644 --- a/.github/workflows/ci-pwsh_preview.yml +++ b/.github/workflows/ci-pwsh_preview.yml @@ -66,7 +66,6 @@ jobs: - name: Install Invoke-Build shell: pwsh run: | - $ProgressPreference = 'SilentlyContinue' Install-Module -Name InvokeBuild -RequiredVersion $env:INVOKE_BUILD_VERSION -Force - name: Run Pester Tests From 056572b6bfd620c5e7c65e59bf180ee75f17ecb8 Mon Sep 17 00:00:00 2001 From: mdaneri Date: Mon, 2 Sep 2024 14:31:36 -0700 Subject: [PATCH 4/4] review --- pode.build.ps1 | 43 +++---------------------------------------- src/Pode.psm1 | 30 +++++++++++++++--------------- 2 files changed, 18 insertions(+), 55 deletions(-) diff --git a/pode.build.ps1 b/pode.build.ps1 index 88676a067..4cd21aee6 100644 --- a/pode.build.ps1 +++ b/pode.build.ps1 @@ -545,45 +545,8 @@ Task TestNoBuild TestDeps, { } }, PushCodeCoverage, CheckFailedTests -# Synopsis: Run tests after a build if needed -Task Test { - - # Get the .NET framework description to determine the runtime version - $frameworkDescription = [System.Runtime.InteropServices.RuntimeInformation]::FrameworkDescription - $found = $false - - # Match and extract the major version number from the framework description - if ($frameworkDescription -match '(\d+)\.(\d+)\.(\d+)') { - $majorVersion = [int]$matches[1] - - # Loop through the major versions from the detected version down to 6 - for ($version = $majorVersion; $version -ge 6; $version--) { - # Check if the corresponding Pode.dll file exists for the version - if (Test-Path "./src/Libs/net$version.0/Pode.dll") { - $found = $true - break - } - } - } - - # If no specific versioned Pode.dll was found, check for the netstandard2.0 version - if (-not $found) { - $found = Test-Path "./src/Libs/netstandard2.0/Pode.dll" - } - - # If any Pode.dll was found, skip the build task - if ($found) { - Write-Output 'Build Task not needed' - } - else { - # If no Pode.dll was found, invoke the build task - Invoke-Build Build - } - - # Always run the test task, assuming that the build task has already been run if needed - Invoke-Build TestNoBuild -} - +# Synopsis: Run tests after a build +Task Test Build, TestNoBuild # Synopsis: Check if any of the tests failed Task CheckFailedTests { @@ -1023,4 +986,4 @@ task ReleaseNotes { $categories[$category] | Sort-Object | ForEach-Object { Write-Host $_ } Write-Host '' } -} +} \ No newline at end of file diff --git a/src/Pode.psm1 b/src/Pode.psm1 index 992f76a8f..3e2d95553 100644 --- a/src/Pode.psm1 +++ b/src/Pode.psm1 @@ -90,25 +90,25 @@ try { } } else { - $frameworkDescription = [System.Runtime.InteropServices.RuntimeInformation]::FrameworkDescription - $loaded = $false - if ($frameworkDescription -match '(\d+)\.(\d+)\.(\d+)') { - $majorVersion = [int]$matches[1] - - for ($version = $majorVersion; $version -ge 6; $version--) { - $dllPath = "$($root)/Libs/net$version.0/Pode.dll" - if (Test-Path $dllPath) { - Add-Type -LiteralPath $dllPath -ErrorAction Stop - $loaded = $true - break - } - } + # fetch the .net version and the libs path + $version = [System.Environment]::Version.Major + $libsPath = "$($root)/Libs" + + # filter .net dll folders based on version above, and get path for latest version found + if (![string]::IsNullOrWhiteSpace($version)) { + $netFolder = Get-ChildItem -Path $libsPath -Directory -Force | + Where-Object { $_.Name -imatch "net[1-$($version)]" } | + Sort-Object -Property Name -Descending | + Select-Object -First 1 -ExpandProperty FullName } - if (-not $loaded) { - Add-Type -LiteralPath "$($root)/Libs/netstandard2.0/Pode.dll" -ErrorAction Stop + # use netstandard if no folder found + if ([string]::IsNullOrWhiteSpace($netFolder)) { + $netFolder = "$($libsPath)/netstandard2.0" } + # append Pode.dll and mount + Add-Type -LiteralPath "$($netFolder)/Pode.dll" -ErrorAction Stop } # load private functions