Skip to content

Commit 397a082

Browse files
committed
Merge branch 'master' of https://github.com/powershell/PSResourceGet into updateFindErrMsgs
2 parents f7a2216 + 1af0251 commit 397a082

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

doBuild.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ function DoBuild
1717
$BuildSrcPath = "bin/${BuildConfiguration}/${BuildFramework}/publish"
1818
Write-Verbose -Verbose -Message "Module build source path: '$BuildSrcPath'"
1919

20-
# Copy module script files
20+
# Copy module .psd1 file
2121
Write-Verbose -Verbose "Copy-Item ${SrcPath}/${ModuleName}.psd1 to $BuildOutPath"
2222
Copy-Item -Path "${SrcPath}/${ModuleName}.psd1" -Dest "$BuildOutPath" -Force
2323

24+
# Copy module .psm1 file
25+
Write-Verbose -Verbose "Copy-Item ${SrcPath}/${ModuleName}.psm1 to $BuildOutPath"
26+
Copy-Item -Path "${SrcPath}/${ModuleName}.psm1" -Dest "$BuildOutPath" -Force
27+
2428
#Copy module format ps1xml file
2529
Write-Verbose -Verbose -Message "Copy-Item ${SrcPath}/${FormatFileName}.ps1xml to $BuildOutPath"
2630
Copy-Item -Path "${SrcPath}/${FormatFileName}.ps1xml" -Dest "$BuildOutPath" -Force

src/code/PublishPSResource.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ protected override void BeginProcessing()
167167
ThrowTerminatingError(
168168
new ErrorRecord(
169169
new ArgumentException(
170-
"The path to the resource to publish is not in the correct format, point to a path or file of the module or script to publish."),
171-
"InvalidSourcePath",
170+
"The path to the resource to publish is not in the correct format or does not exist. Please provide the path of the root module (i.e. './<ModuleToPublish>/') or the path to the .psd1 (i.e. './<ModuleToPublish>/<ModuleToPublish>.psd1')."),
171+
"InvalidPublishPath",
172172
ErrorCategory.InvalidArgument,
173173
this));
174174
}
@@ -187,6 +187,15 @@ protected override void BeginProcessing()
187187
pathToScriptFileToPublish = resolvedPath;
188188
resourceType = ResourceType.Script;
189189
}
190+
else {
191+
ThrowTerminatingError(
192+
new ErrorRecord(
193+
new ArgumentException(
194+
$"The publish path provided, '{resolvedPath}', is not a valid. Please provide a path to the root module (i.e. './<ModuleToPublish>/') or path to the .psd1 (i.e. './<ModuleToPublish>/<ModuleToPublish>.psd1')."),
195+
"InvalidPublishPath",
196+
ErrorCategory.InvalidArgument,
197+
this));
198+
}
190199

191200
if (!String.IsNullOrEmpty(DestinationPath))
192201
{
@@ -578,7 +587,9 @@ private string CreateNuspec(
578587
}
579588

580589
// defaults to false
581-
string requireLicenseAcceptance = psData.ContainsKey("requirelicenseacceptance") ? psData["requirelicenseacceptance"].ToString() : "false";
590+
// Value for requireAcceptLicense key needs to be a lowercase string representation of the boolean for it to be correctly parsed from psData file.
591+
592+
string requireLicenseAcceptance = psData.ContainsKey("requirelicenseacceptance") ? psData["requirelicenseacceptance"].ToString().ToLower() : "false";
582593

583594
metadataElementsDictionary.Add("requireLicenseAcceptance", requireLicenseAcceptance);
584595

test/PublishPSResourceTests/PublishPSResource.Tests.ps1

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,4 +546,12 @@ Describe "Test Publish-PSResource" -tags 'CI' {
546546

547547
{Publish-PSResource -Path $incorrectdepmoduleversion -ErrorAction Stop} | Should -Throw -ErrorId "InvalidModuleManifest,Microsoft.PowerShell.PSResourceGet.Cmdlets.PublishPSResource"
548548
}
549-
}
549+
550+
It "Publish a module with using an invalid file path (path to .psm1), should throw" {
551+
$fileName = "$script:PublishModuleName.psm1"
552+
$psm1Path = Join-Path -Path $script:PublishModuleBase -ChildPath $fileName
553+
$null = New-Item -Path $psm1Path -ItemType File -Force
554+
555+
{Publish-PSResource -Path $psm1Path -Repository $testRepository2 -ErrorAction Stop} | Should -Throw -ErrorId "InvalidPublishPath,Microsoft.PowerShell.PSResourceGet.Cmdlets.PublishPSResource"
556+
}
557+
}

0 commit comments

Comments
 (0)