gaelcolas / Sampler

Module template with build pipeline and examples, including DSC elements.
MIT License
172 stars 42 forks source link

Enabling `WithYAML` results in `powershell-yaml\0.4.4' is denied` #411

Closed raandree closed 1 year ago

raandree commented 1 year ago

Problem description

WithYAML is enabled in CommonTasks since long time. For some reason, the build does no longer work and throwing this error:

Starting bootstrap process.                                                                                                                     WARNING: Access to the path 'D:\Git\CommonTasks\output\RequiredModules\powershell-yaml\0.4.4' is denied.                                                    PackageManagement\Save-Package : Unable to save the module 'datum'.                                                                                         At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.5\PSModule.psm1:11794 char:21                                                               
+             $null = PackageManagement\Save-Package @PSBoundParameters
+                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Microsoft.Power...ets.SavePackage:SavePackage) [Save-Package], Exception
    + FullyQualifiedErrorId : ProviderFailToDownloadFile,Microsoft.PowerShell.PackageManagement.Cmdlets.SavePackage

When disabling WithYAML in Resolve-Dependency.psd1, the build works again.

Verbose logs

NA

How to reproduce

Build CommonTasks.

Expected behavior

No error.

Current behavior

see above.

Suggested solution

NA

Operating system the target node is running

Windows 11

PowerShell version and build the target node is running

5.1

Module version used

0.116.1
johlju commented 1 year ago

When option WithYAML is set to $true the module powershell-yaml is installed. The module exports two commands where one (ConvertFrom-Yaml) is used in build.ps1 to parse the default YAML or JSON build configuration file (or one passed thru the parameter BuildConfig). The parsed configuration file will be used as the $BuildInfo for tasks.

So if if I understamds the code correctly if leaving out WithYAML so that powershell-yaml is not installed, and it is not installed in any PSModulePath the build should fail on missing the command ConvertFrom-Yaml.

johlju commented 1 year ago

Then a workaround is to use a psd1 file as the configuration file instead. But that has probably never been tested. 🙂 So the root cause why it can't save the module should probably be found as it probably will have other consequences when Save-Module fails.

raandree commented 1 year ago

No way I want to go back to psd1. But I don't even have to. Even when disabling WithYAML the build works and I found the reason. I have created a new Sampler project and as you said, the build did not work:

ERROR: The specified module 'powershell-yaml' was not loaded because no valid module file was found in any module directory.
Build ABORTED D:\Git\T1\build.ps1. 0 tasks, 1 errors, 0 warnings 00:00:28.5413373

But when adding Datum to the required modules which depends on powershell-yaml, also powershell-yaml is downloaded during the bootstrap process and things for.

So, @johlju, in this case, I guess I can disable WithYAML, right?

johlju commented 1 year ago

Yes. Since powershell-yaml is downloaded with Datum and that happens prior to the build configuration file is read it should be safe to disable WithYML. 🙂