poshbotio / PoshBot

Powershell-based bot framework
MIT License
538 stars 108 forks source link

Psake CreateMarkdownHelp Fails Because the Module Isn't Loaded #21

Closed michaeltlombardi closed 7 years ago

michaeltlombardi commented 7 years ago

When running psake as administrator to create markdown help files, the build script errors out because it never imports the PoshBot module.

Expected Behavior

When running the CreateMarkdownHelp task via the build script, it should automatically import the version of PoshBot available in the project root and export the function comment-based help.

Current Behavior

The build script errors out.

Possible Solution

Ensure that the module is properly loaded in a prior step or load and unload in this task itself.

Steps to Reproduce (for bugs)

  1. In a PowerShell prompt with Administrator rights, clone the project and CD to root
  2. .\build.ps1 -Task CreateMarkdownHelp

Screenshot

image

Context

Users should be able to run the build tasks without errors, even if only performing one task.

Your Environment

Module Version
BuildHelpers 0.0.29
Psake 4.6.0
PlatyPS 0.7.6
Pester 4.0.3
PSScriptAnalyzer 1.11.0
michaeltlombardi commented 7 years ago

It looks like this might actually be related to PowerShell/PlatyPS#218

I am able to execute manually in the commandline without issues, but getting it to work in the build seems tricky. Investigating.

michaeltlombardi commented 7 years ago

It looks like it's necessary to import the module into the global scope; doing so fixes the build for reasons I don't (yet) understand.

Doesn't Work

task CreateMarkdownHelp -Depends Init {
    Import-Module -Name $sut -Force -Verbose:$false
    New-MarkdownHelp -Module $env:BHProjectName -OutputFolder "$projectRoot\docs\reference\functions" -WithModulePage -Force
} -description 'Create initial markdown help files'

Works

task CreateMarkdownHelp -Depends Init {
    Import-Module -Name $sut -Force -Verbose:$false -Global
    New-MarkdownHelp -Module $env:BHProjectName -OutputFolder "$projectRoot\docs\reference\functions" -WithModulePage -Force
    Remove-Module $env:BHProjectName
} -description 'Create initial markdown help files'