Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions src/code/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,7 @@ private static bool TryReadPSDataFile(
public static bool ValidateModuleManifest(string moduleManifestPath, out string errorMsg)
{
errorMsg = string.Empty;
using (System.Management.Automation.PowerShell pwsh = System.Management.Automation.PowerShell.Create())
using (System.Management.Automation.PowerShell pwsh = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace))
{
// use PowerShell cmdlet Test-ModuleManifest
// TODO: Test-ModuleManifest will throw an error if RequiredModules specifies a module that does not exist
Expand All @@ -1400,32 +1400,32 @@ public static bool ValidateModuleManifest(string moduleManifestPath, out string
}
}

if (pwsh.HadErrors)
// Validate the result object directly
if (results.Any())
{
if (results.Any())
PSModuleInfo psModuleInfoObj = results[0].BaseObject as PSModuleInfo;
if (string.IsNullOrWhiteSpace(psModuleInfoObj.Author))
{
PSModuleInfo psModuleInfoObj = results[0].BaseObject as PSModuleInfo;
if (string.IsNullOrWhiteSpace(psModuleInfoObj.Author))
{
errorMsg = "No author was provided in the module manifest. The module manifest must specify a version, author and description. Run 'Test-ModuleManifest' to validate the file.";
}
else if (string.IsNullOrWhiteSpace(psModuleInfoObj.Description))
{
errorMsg = "No description was provided in the module manifest. The module manifest must specify a version, author and description. Run 'Test-ModuleManifest' to validate the file.";
}
else if (psModuleInfoObj.Version == null)
{
errorMsg = "No version or an incorrectly formatted version was provided in the module manifest. The module manifest must specify a version, author and description. Run 'Test-ModuleManifest' to validate the file.";
}
errorMsg = "No author was provided in the module manifest. The module manifest must specify a version, author and description. Run 'Test-ModuleManifest' to validate the file.";
return false;
}

if (string.IsNullOrEmpty(errorMsg))
else if (string.IsNullOrWhiteSpace(psModuleInfoObj.Description))
{
// Surface any inner error messages
var innerErrorMsg = (pwsh.Streams.Error.Count > 0) ? pwsh.Streams.Error[0].ToString() : string.Empty;
errorMsg = $"Module manifest file validation failed with error: {innerErrorMsg}. Run 'Test-ModuleManifest' to validate the module manifest.";
errorMsg = "No description was provided in the module manifest. The module manifest must specify a version, author and description. Run 'Test-ModuleManifest' to validate the file.";
return false;
}

else if (psModuleInfoObj.Version == null)
{
errorMsg = "No version or an incorrectly formatted version was provided in the module manifest. The module manifest must specify a version, author and description. Run 'Test-ModuleManifest' to validate the file.";
return false;
}
}

// Check for any errors from Test-ModuleManifest
if (pwsh.HadErrors)
{
var innerErrorMsg = (pwsh.Streams.Error.Count > 0) ? pwsh.Streams.Error[0].ToString() : string.Empty;
errorMsg = $"Module manifest file validation failed with error: {innerErrorMsg}. Run 'Test-ModuleManifest' to validate the module manifest.";
return false;
}
}
Expand Down
15 changes: 15 additions & 0 deletions test/PublishPSResourceTests/PublishPSResource.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,21 @@ Describe "Test Publish-PSResource" -tags 'CI' {
}
}

It "Publish a module with valid Author field without -SkipModuleManifestValidate" {
# This test verifies that the fix for runspace deserialization issue works correctly.
# Previously, PSModuleInfo.Author would return empty string when called via PowerShell.Create(),
# causing false positive "No author was provided" errors.
$version = "1.0.0"
$author = "TestAuthor"
New-ModuleManifest -Path (Join-Path -Path $script:PublishModuleBase -ChildPath "$script:PublishModuleName.psd1") -ModuleVersion $version -Description "$script:PublishModuleName module" -Author $author

# This should succeed without needing -SkipModuleManifestValidate
Publish-PSResource -Path $script:PublishModuleBase -Repository $testRepository2

$expectedPath = Join-Path -Path $script:repositoryPath2 -ChildPath "$script:PublishModuleName.$version.nupkg"
(Get-ChildItem $script:repositoryPath2).FullName | Should -Be $expectedPath
}

It "Publish a module with -Path to the highest priority repo" {
$version = "1.0.0"
New-ModuleManifest -Path (Join-Path -Path $script:PublishModuleBase -ChildPath "$script:PublishModuleName.psd1") -ModuleVersion $version -Description "$script:PublishModuleName module"
Expand Down
Loading