Skip to content

Commit 1fa824a

Browse files
committed
Merge branch 'master' of https://github.com/PowerShell/PSResourceGet into update-dep
2 parents 482737f + 08d5b7a commit 1fa824a

File tree

5 files changed

+72
-7
lines changed

5 files changed

+72
-7
lines changed

src/code/CompressPSResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using Microsoft.PowerShell.PSResourceGet.UtilClasses;
55
using System.IO;
6-
using System.Linq;
76
using System.Management.Automation;
87

98
namespace Microsoft.PowerShell.PSResourceGet.Cmdlets
@@ -15,6 +14,7 @@ namespace Microsoft.PowerShell.PSResourceGet.Cmdlets
1514
"PSResource",
1615
SupportsShouldProcess = true)]
1716
[Alias("cmres")]
17+
[OutputType(typeof(FileInfo))]
1818
public sealed class CompressPSResource : PSCmdlet
1919
{
2020
#region Parameters

src/code/PublishHelper.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,11 @@ out string[] _
296296
}
297297
}
298298

299+
if (_callerCmdlet == CallerCmdlet.CompressPSResource)
300+
{
301+
outputNupkgDir = DestinationPath;
302+
}
303+
299304
// pack into .nupkg
300305
if (!PackNupkg(outputDir, outputNupkgDir, nuspec, out ErrorRecord packNupkgError))
301306
{
@@ -566,7 +571,8 @@ private bool PackNupkg(string outputDir, string outputNupkgDir, string nuspecFil
566571
{
567572
if (PassThru)
568573
{
569-
_cmdletPassedIn.WriteObject(System.IO.Path.Combine(outputNupkgDir, _pkgName + "." + _pkgVersion.ToNormalizedString() + ".nupkg"));
574+
var nupkgPath = System.IO.Path.Combine(outputNupkgDir, _pkgName + "." + _pkgVersion.ToNormalizedString() + ".nupkg");
575+
_cmdletPassedIn.WriteObject(new FileInfo(nupkgPath));
570576
}
571577
_cmdletPassedIn.WriteVerbose("Successfully packed the resource into a .nupkg");
572578
}

src/code/V2ServerAPICalls.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ private string FindAllFromTypeEndPoint(bool includePrerelease, bool isSearchingM
901901
} else {
902902
filterBuilder.AddCriterion("IsLatestVersion");
903903
}
904-
var requestUrlV2 = $"{Repository.Uri}{typeEndpoint}/Search()?$filter={queryBuilder.BuildQueryString()}";
904+
var requestUrlV2 = $"{Repository.Uri}{typeEndpoint}/Search()?{queryBuilder.BuildQueryString()}";
905905
return HttpRequestCall(requestUrlV2, out errRecord);
906906
}
907907

test/FindPSResourceTests/FindPSResourceV2Server.Tests.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ $modPath = "$psscriptroot/../PSGetTestUtils.psm1"
55
Import-Module $modPath -Force -Verbose
66

77
$psmodulePaths = $env:PSModulePath -split ';'
8-
Write-Verbose -Verbose "Current module search paths: $psmodulePaths"
8+
Write-Verbose -Verbose -Message "Current module search paths: $psmodulePaths"
99

1010
Describe 'Test HTTP Find-PSResource for V2 Server Protocol' -tags 'CI' {
1111

@@ -56,6 +56,11 @@ Describe 'Test HTTP Find-PSResource for V2 Server Protocol' -tags 'CI' {
5656
$foundScript | Should -BeTrue
5757
}
5858

59+
It "find all resources when wildcard only for Name" {
60+
$res = Find-PSResource -Name '*' -Repository $PSGalleryName
61+
$res.Count | Should -BeGreaterThan 0
62+
}
63+
5964
$testCases2 = @{Version="[5.0.0.0]"; ExpectedVersions=@("5.0.0.0"); Reason="validate version, exact match"},
6065
@{Version="5.0.0.0"; ExpectedVersions=@("5.0.0.0"); Reason="validate version, exact match without bracket syntax"},
6166
@{Version="[1.0.0.0, 5.0.0.0]"; ExpectedVersions=@("1.0.0.0", "3.0.0.0", "5.0.0.0"); Reason="validate version, exact range inclusive"},

test/PublishPSResourceTests/CompressPSResource.Tests.ps1

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,68 @@ Describe "Test Compress-PSResource" -tags 'CI' {
154154
Test-Path -Path (Join-Path -Path $unzippedPath -ChildPath $testFile) | Should -Be $True
155155
}
156156

157-
It "Compress-PSResource -PassThru returns the path to the nupkg" {
157+
It "Compresses a script" {
158+
$scriptName = "PSGetTestScript"
159+
$scriptVersion = "1.0.0"
160+
161+
$params = @{
162+
Version = $scriptVersion
163+
GUID = [guid]::NewGuid()
164+
Author = 'Jane'
165+
CompanyName = 'Microsoft Corporation'
166+
Copyright = '(c) 2020 Microsoft Corporation. All rights reserved.'
167+
Description = "Description for the $scriptName script"
168+
LicenseUri = "https://$scriptName.com/license"
169+
IconUri = "https://$scriptName.com/icon"
170+
ProjectUri = "https://$scriptName.com"
171+
Tags = @('Tag1','Tag2', "Tag-$scriptName-$scriptVersion")
172+
ReleaseNotes = "$scriptName release notes"
173+
}
174+
175+
$scriptPath = (Join-Path -Path $script:tmpScriptsFolderPath -ChildPath "$scriptName.ps1")
176+
New-PSScriptFileInfo @params -Path $scriptPath
177+
178+
Compress-PSResource -Path $scriptPath -DestinationPath $script:repositoryPath
179+
180+
$expectedPath = Join-Path -Path $script:repositoryPath -ChildPath "$scriptName.$scriptVersion.nupkg"
181+
(Get-ChildItem $script:repositoryPath).FullName | Should -Be $expectedPath
182+
}
183+
184+
It "Compress-PSResource -DestinationPath works for relative paths" {
185+
$version = "1.0.0"
186+
$relativePath = ".\RelativeTestModule"
187+
$relativeDestination = ".\RelativeDestination"
188+
189+
# Create relative paths
190+
New-Item -Path $relativePath -ItemType Directory -Force
191+
New-Item -Path $relativeDestination -ItemType Directory -Force
192+
193+
# Create module manifest in the relative path
194+
New-ModuleManifest -Path (Join-Path -Path $relativePath -ChildPath "$script:PublishModuleName.psd1") -ModuleVersion $version -Description "$script:PublishModuleName module"
195+
196+
# Compress using relative paths
197+
Compress-PSResource -Path $relativePath -DestinationPath $relativeDestination
198+
199+
$expectedPath = Join-Path -Path $relativeDestination -ChildPath "$script:PublishModuleName.$version.nupkg"
200+
$fileExists = Test-Path -Path $expectedPath
201+
$fileExists | Should -Be $True
202+
203+
# Cleanup
204+
Remove-Item -Path $relativePath -Recurse -Force
205+
Remove-Item -Path $relativeDestination -Recurse -Force
206+
}
207+
208+
It "Compress-PSResource -PassThru returns a FileInfo object with the correct path" {
158209
$version = "1.0.0"
159210
New-ModuleManifest -Path (Join-Path -Path $script:PublishModuleBase -ChildPath "$script:PublishModuleName.psd1") -ModuleVersion $version -Description "$script:PublishModuleName module"
160211

161-
$nupkgPath = Compress-PSResource -Path $script:PublishModuleBase -DestinationPath $script:repositoryPath -PassThru
212+
$fileInfoObject = Compress-PSResource -Path $script:PublishModuleBase -DestinationPath $script:repositoryPath -PassThru
162213

163214
$expectedPath = Join-Path -Path $script:repositoryPath -ChildPath "$script:PublishModuleName.$version.nupkg"
164-
$nupkgPath | Should -Be $expectedPath
215+
$fileInfoObject | Should -BeOfType 'System.IO.FileSystemInfo'
216+
$fileInfoObject.FullName | Should -Be $expectedPath
217+
$fileInfoObject.Extension | Should -Be '.nupkg'
218+
$fileInfoObject.Name | Should -Be "$script:PublishModuleName.$version.nupkg"
165219
}
166220

167221
<# Test for Signing the nupkg. Signing doesn't work

0 commit comments

Comments
 (0)