From 610bb08161b4dcbec84da56b83e507c2acc3aff6 Mon Sep 17 00:00:00 2001 From: Justin Chung Date: Tue, 8 Oct 2024 17:15:06 -0500 Subject: [PATCH 1/3] PassThru with FileIno instead of string --- src/code/CompressPSResource.cs | 2 +- src/code/PublishHelper.cs | 4 +- .../CompressPSResource.Tests.ps1 | 47 +++++++++++++++++-- 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/code/CompressPSResource.cs b/src/code/CompressPSResource.cs index 95b95a4e3..b306e7d88 100644 --- a/src/code/CompressPSResource.cs +++ b/src/code/CompressPSResource.cs @@ -3,7 +3,6 @@ using Microsoft.PowerShell.PSResourceGet.UtilClasses; using System.IO; -using System.Linq; using System.Management.Automation; namespace Microsoft.PowerShell.PSResourceGet.Cmdlets @@ -15,6 +14,7 @@ namespace Microsoft.PowerShell.PSResourceGet.Cmdlets "PSResource", SupportsShouldProcess = true)] [Alias("cmres")] + [OutputType(typeof(FileInfo))] public sealed class CompressPSResource : PSCmdlet { #region Parameters diff --git a/src/code/PublishHelper.cs b/src/code/PublishHelper.cs index 861bbfab3..731ad4ca6 100644 --- a/src/code/PublishHelper.cs +++ b/src/code/PublishHelper.cs @@ -566,8 +566,10 @@ private bool PackNupkg(string outputDir, string outputNupkgDir, string nuspecFil { if (PassThru) { - _cmdletPassedIn.WriteObject(System.IO.Path.Combine(outputNupkgDir, _pkgName + "." + _pkgVersion.ToNormalizedString() + ".nupkg")); + var nupkgPath = System.IO.Path.Combine(outputNupkgDir, _pkgName + "." + _pkgVersion.ToNormalizedString() + ".nupkg"); + _cmdletPassedIn.WriteObject(new FileInfo(nupkgPath)); } + _cmdletPassedIn.WriteVerbose("Successfully packed the resource into a .nupkg"); } else diff --git a/test/PublishPSResourceTests/CompressPSResource.Tests.ps1 b/test/PublishPSResourceTests/CompressPSResource.Tests.ps1 index 778c225bb..363d34f3c 100644 --- a/test/PublishPSResourceTests/CompressPSResource.Tests.ps1 +++ b/test/PublishPSResourceTests/CompressPSResource.Tests.ps1 @@ -46,6 +46,44 @@ Describe "Test Compress-PSResource" -tags 'CI' { BeforeAll { Get-NewPSResourceRepositoryFile + $testDir = (get-item $psscriptroot).parent.FullName + +function CreateTestModule +{ + param ( + [string] $Path = "$TestDrive", + [string] $ModuleName = 'TestModule' + ) + + $modulePath = Join-Path -Path $Path -ChildPath $ModuleName + $moduleMan = Join-Path $modulePath -ChildPath ($ModuleName + '.psd1') + $moduleSrc = Join-Path $modulePath -ChildPath ($ModuleName + '.psm1') + + if ( Test-Path -Path $modulePath) { + Remove-Item -Path $modulePath -Recurse -Force + } + + $null = New-Item -Path $modulePath -ItemType Directory -Force + + @' + @{{ + RootModule = "{0}.psm1" + ModuleVersion = '1.0.0' + Author = 'None' + Description = 'None' + GUID = '0c2829fc-b165-4d72-9038-ae3a71a755c1' + FunctionsToExport = @('Test1') + RequiredModules = @('NonExistentModule') + }} +'@ -f $ModuleName | Out-File -FilePath $moduleMan + + @' + function Test1 { + Write-Output 'Hello from Test1' + } +'@ | Out-File -FilePath $moduleSrc +} + # Register temporary repositories $tmpRepoPath = Join-Path -Path $TestDrive -ChildPath "tmpRepoPath" New-Item $tmpRepoPath -Itemtype directory -Force @@ -154,14 +192,17 @@ Describe "Test Compress-PSResource" -tags 'CI' { Test-Path -Path (Join-Path -Path $unzippedPath -ChildPath $testFile) | Should -Be $True } - It "Compress-PSResource -PassThru returns the path to the nupkg" { + It "Compress-PSResource -PassThru returns a FileInfo object with the correct path" { $version = "1.0.0" New-ModuleManifest -Path (Join-Path -Path $script:PublishModuleBase -ChildPath "$script:PublishModuleName.psd1") -ModuleVersion $version -Description "$script:PublishModuleName module" - $nupkgPath = Compress-PSResource -Path $script:PublishModuleBase -DestinationPath $script:repositoryPath -PassThru + $fileInfoObject = Compress-PSResource -Path $script:PublishModuleBase -DestinationPath $script:repositoryPath -PassThru $expectedPath = Join-Path -Path $script:repositoryPath -ChildPath "$script:PublishModuleName.$version.nupkg" - $nupkgPath | Should -Be $expectedPath + $fileInfoObject | Should -BeOfType 'System.IO.FileSystemInfo' + $fileInfoObject.FullName | Should -Be $expectedPath + $fileInfoObject.Extension | Should -Be '.nupkg' + $fileInfoObject.Name | Should -Be "$script:PublishModuleName.$version.nupkg" } <# Test for Signing the nupkg. Signing doesn't work From c1395f2e500274875550c9b5a4dfc52c29c854dc Mon Sep 17 00:00:00 2001 From: Justin Chung Date: Tue, 8 Oct 2024 17:19:12 -0500 Subject: [PATCH 2/3] undid testing modification --- .../CompressPSResource.Tests.ps1 | 38 ------------------- 1 file changed, 38 deletions(-) diff --git a/test/PublishPSResourceTests/CompressPSResource.Tests.ps1 b/test/PublishPSResourceTests/CompressPSResource.Tests.ps1 index 363d34f3c..7a54d72d6 100644 --- a/test/PublishPSResourceTests/CompressPSResource.Tests.ps1 +++ b/test/PublishPSResourceTests/CompressPSResource.Tests.ps1 @@ -46,44 +46,6 @@ Describe "Test Compress-PSResource" -tags 'CI' { BeforeAll { Get-NewPSResourceRepositoryFile - $testDir = (get-item $psscriptroot).parent.FullName - -function CreateTestModule -{ - param ( - [string] $Path = "$TestDrive", - [string] $ModuleName = 'TestModule' - ) - - $modulePath = Join-Path -Path $Path -ChildPath $ModuleName - $moduleMan = Join-Path $modulePath -ChildPath ($ModuleName + '.psd1') - $moduleSrc = Join-Path $modulePath -ChildPath ($ModuleName + '.psm1') - - if ( Test-Path -Path $modulePath) { - Remove-Item -Path $modulePath -Recurse -Force - } - - $null = New-Item -Path $modulePath -ItemType Directory -Force - - @' - @{{ - RootModule = "{0}.psm1" - ModuleVersion = '1.0.0' - Author = 'None' - Description = 'None' - GUID = '0c2829fc-b165-4d72-9038-ae3a71a755c1' - FunctionsToExport = @('Test1') - RequiredModules = @('NonExistentModule') - }} -'@ -f $ModuleName | Out-File -FilePath $moduleMan - - @' - function Test1 { - Write-Output 'Hello from Test1' - } -'@ | Out-File -FilePath $moduleSrc -} - # Register temporary repositories $tmpRepoPath = Join-Path -Path $TestDrive -ChildPath "tmpRepoPath" New-Item $tmpRepoPath -Itemtype directory -Force From 8a3669b08ef520218036edacaf742dbaeb15c08a Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Tue, 8 Oct 2024 21:28:28 -0700 Subject: [PATCH 3/3] Update src/code/PublishHelper.cs --- src/code/PublishHelper.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/code/PublishHelper.cs b/src/code/PublishHelper.cs index 731ad4ca6..f7ef9248b 100644 --- a/src/code/PublishHelper.cs +++ b/src/code/PublishHelper.cs @@ -569,7 +569,6 @@ private bool PackNupkg(string outputDir, string outputNupkgDir, string nuspecFil var nupkgPath = System.IO.Path.Combine(outputNupkgDir, _pkgName + "." + _pkgVersion.ToNormalizedString() + ".nupkg"); _cmdletPassedIn.WriteObject(new FileInfo(nupkgPath)); } - _cmdletPassedIn.WriteVerbose("Successfully packed the resource into a .nupkg"); } else