Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e5b5e43
Fix escape single quoted text in manifest
MariusStorhaug Jan 28, 2025
da18c11
🩹 [Refactor]: Replace Invoke-RecurseEscapeFix with ConvertTo-EscapedH…
MariusStorhaug Jan 28, 2025
1dfe9a4
🩹 [Enhancement]: Add verbose logging to ConvertTo-EscapedHashtableStr…
MariusStorhaug Jan 28, 2025
f1ffce3
🩹 [Enhancement]: Add verbose flag to ConvertTo-EscapedHashtableString…
MariusStorhaug Jan 28, 2025
d8c8674
🩹 [Enhancement]: Add null and empty string handling to Invoke-Recurse…
MariusStorhaug Jan 28, 2025
edf629d
🩹 [Fix]: Correctly assign output of ConvertTo-EscapedHashtableString …
MariusStorhaug Jan 28, 2025
3e58fb0
🩹 [Fix]: Escape single quotes in module manifest description to preve…
MariusStorhaug Jan 28, 2025
257e5af
🩹 [Fix]: Remove redundant single quote escaping in module manifest de…
MariusStorhaug Jan 28, 2025
0500cf1
🩹 [Enhancement]: Add verbose flag to Set-ModuleManifest for improved …
MariusStorhaug Jan 28, 2025
d98cbb9
🩹 [Feature]: Add multiple PowerShell utility functions for module man…
MariusStorhaug Jan 28, 2025
b64a89b
🩹 [Refactor]: Replace Write-Verbose with Write-Host for improved outp…
MariusStorhaug Jan 28, 2025
a2be9de
🩹 [Fix]: Escape single quotes in module manifest description assignme…
MariusStorhaug Jan 28, 2025
a637a3b
🩹 [Fix]: Correctly escape single quotes in module manifest descriptio…
MariusStorhaug Jan 28, 2025
3bd0cf7
🩹 [Fix]: Escape single quotes in module manifest description and add …
MariusStorhaug Jan 28, 2025
bcbf475
🩹 [Fix]: Correctly escape single quotes in hashtable string conversio…
MariusStorhaug Jan 28, 2025
38a9fae
🩹 [Fix]: Correctly escape single quotes in hashtable string conversio…
MariusStorhaug Jan 28, 2025
30220be
🩹 [Fix]: Correctly escape single quotes in hashtable string conversio…
MariusStorhaug Jan 28, 2025
3baa5d7
🩹 [Fix]: Comment out the Format-ModuleManifest call in Export-PowerSh…
MariusStorhaug Jan 28, 2025
249ae18
🩹 [Fix]: Re-enable Format-ModuleManifest call in Export-PowerShellDat…
MariusStorhaug Jan 28, 2025
d93b4cb
🩹 [Fix]: Add verbose logging to Set-ModuleManifest in Update-PSModule…
MariusStorhaug Jan 28, 2025
33627f7
🩹 [Fix]: Add verbose logging for escaped values in Convert-HashtableT…
MariusStorhaug Jan 28, 2025
0f94041
🩹 [Fix]: Improve escaping of single quotes in Convert-HashtableToStri…
MariusStorhaug Jan 28, 2025
8a7799d
🩹 [Fix]: Update module requirements in Get-PSModuleTest.ps1 to use 'S…
MariusStorhaug Jan 28, 2025
c5bdb96
🩹 [Cleanup]: Remove obsolete PowerShell module functions to streamlin…
MariusStorhaug Jan 28, 2025
53bce57
🩹 [Refactor]: Replace Write-Verbose with Write-Host for improved outp…
MariusStorhaug Jan 28, 2025
e38812a
Merge branch 'main' of https://github.com/PSModule/Build-PSModule int…
MariusStorhaug Jan 29, 2025
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
8 changes: 4 additions & 4 deletions scripts/helpers/Build-PSModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ function Build-PSModule {
)

LogGroup "Building module [$ModuleName]" {
Write-Verbose "Source path: [$ModuleSourceFolderPath]"
Write-Host "Source path: [$ModuleSourceFolderPath]"
if (-not (Test-Path -Path $ModuleSourceFolderPath)) {
Write-Error "Source folder not found at [$ModuleSourceFolderPath]"
exit 1
}
$moduleSourceFolder = Get-Item -Path $ModuleSourceFolderPath
Write-Verbose "Module source folder: [$moduleSourceFolder]"
Write-Host "Module source folder: [$moduleSourceFolder]"

$moduleOutputFolder = New-Item -Path $ModulesOutputFolderPath -Name $ModuleName -ItemType Directory -Force
Write-Verbose "Module output folder: [$moduleOutputFolder]"
Write-Host "Module output folder: [$moduleOutputFolder]"

$docsOutputFolder = New-Item -Path $DocsOutputFolderPath -ItemType Directory -Force
Write-Verbose "Docs output folder: [$docsOutputFolder]"
Write-Host "Docs output folder: [$docsOutputFolder]"
}

Build-PSModuleBase -ModuleName $ModuleName -ModuleSourceFolder $moduleSourceFolder -ModuleOutputFolder $moduleOutputFolder
Expand Down
2 changes: 1 addition & 1 deletion scripts/helpers/Build/Build-PSModuleBase.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function Build-PSModuleBase {
)

LogGroup 'Build base' {
Write-Verbose "Copying files from [$ModuleSourceFolder] to [$ModuleOutputFolder]"
Write-Host "Copying files from [$ModuleSourceFolder] to [$ModuleOutputFolder]"
Copy-Item -Path "$ModuleSourceFolder\*" -Destination $ModuleOutputFolder -Recurse -Force -Verbose -Exclude "$ModuleName.psm1"
New-Item -Path $ModuleOutputFolder -Name "$ModuleName.psm1" -ItemType File -Force -Verbose
}
Expand Down
12 changes: 6 additions & 6 deletions scripts/helpers/Build/Build-PSModuleDocumentation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function Build-PSModuleDocumentation {
LogGroup 'Build docs - Generate markdown help' {
$ModuleName | Remove-Module -Force
Import-Module -Name $ModuleName -Force -RequiredVersion '999.0.0'
Write-Verbose ($ModuleName | Get-Module)
Write-Host ($ModuleName | Get-Module)
$null = New-MarkdownHelp -Module $ModuleName -OutputFolder $DocsOutputFolder -Force -Verbose
}

Expand Down Expand Up @@ -75,23 +75,23 @@ function Build-PSModuleDocumentation {
$PublicFunctionsFolder = Join-Path $ModuleSourceFolder.FullName 'functions\public' | Get-Item
Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
$file = $_
Write-Verbose "Processing: $file"
Write-Host "Processing: $file"

# find the source code file that matches the markdown file
$scriptPath = Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force | Where-Object { $_.Name -eq ($file.BaseName + '.ps1') }
Write-Verbose "Found script path: $scriptPath"
Write-Host "Found script path: $scriptPath"
$docsFilePath = ($scriptPath.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName).Replace('.ps1', '.md')
Write-Verbose "Doc file path: $docsFilePath"
Write-Host "Doc file path: $docsFilePath"
$docsFolderPath = Split-Path -Path $docsFilePath -Parent
New-Item -Path $docsFolderPath -ItemType Directory -Force
Move-Item -Path $file.FullName -Destination $docsFilePath -Force
}
# Get the MD files that are in the public functions folder and move them to the same place in the docs folder
Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force -Include '*.md' | ForEach-Object {
$file = $_
Write-Verbose "Processing: $file"
Write-Host "Processing: $file"
$docsFilePath = ($file.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName)
Write-Verbose "Doc file path: $docsFilePath"
Write-Host "Doc file path: $docsFilePath"
$docsFolderPath = Split-Path -Path $docsFilePath -Parent
New-Item -Path $docsFolderPath -ItemType Directory -Force
Move-Item -Path $file.FullName -Destination $docsFilePath -Force
Expand Down
162 changes: 81 additions & 81 deletions scripts/helpers/Build/Build-PSModuleManifest.ps1

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions scripts/helpers/Build/Build-PSModuleRootModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ $MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = {
$exports.Add('Function', (Get-PSModuleFunctionsToExport -SourceFolderPath $ModuleOutputFolder))
$exports.Add('Variable', (Get-PSModuleVariablesToExport -SourceFolderPath $ModuleOutputFolder))

Write-Verbose ($exports | Out-String)
Write-Host ($exports | Out-String)
#endregion - Analyze source files

#region - Module header
Expand Down Expand Up @@ -223,7 +223,7 @@ Write-Debug "[`$scriptName] - $relativePath - Done"

$exportsString = Convert-HashtableToString -Hashtable $exports

Write-Verbose ($exportsString | Out-String)
Write-Host ($exportsString | Out-String)

$params = @{
Path = $rootModuleFile
Expand Down
4 changes: 2 additions & 2 deletions scripts/helpers/Build/Get-PSModuleAliasesToExport.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

$manifest = Get-ModuleManifest -Path $manifestFilePath -Verbose:$false

Write-Verbose "[$manifestPropertyName]"
Write-Host "[$manifestPropertyName]"
$aliasesToExport = (($manifest.AliasesToExport).count -eq 0) -or ($manifest.AliasesToExport | IsNullOrEmpty) ? '*' : $manifest.AliasesToExport
$aliasesToExport | ForEach-Object {
Write-Verbose "[$manifestPropertyName] - [$_]"
Write-Host "[$manifestPropertyName] - [$_]"
}

$aliasesToExport
Expand Down
4 changes: 2 additions & 2 deletions scripts/helpers/Build/Get-PSModuleCmdletsToExport.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

$manifest = Get-ModuleManifest -Path $manifestFilePath -Verbose:$false

Write-Verbose "[$manifestPropertyName]"
Write-Host "[$manifestPropertyName]"
$cmdletsToExport = (($manifest.CmdletsToExport).count -eq 0) -or ($manifest.CmdletsToExport | IsNullOrEmpty) ? '' : $manifest.CmdletsToExport
$cmdletsToExport | ForEach-Object {
Write-Verbose "[$manifestPropertyName] - [$_]"
Write-Host "[$manifestPropertyName] - [$_]"
}

$cmdletsToExport
Expand Down
12 changes: 6 additions & 6 deletions scripts/helpers/Build/Get-PSModuleFunctionsToExport.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@

$manifestPropertyName = 'FunctionsToExport'

Write-Verbose "[$manifestPropertyName]"
Write-Verbose "[$manifestPropertyName] - Checking path for functions and filters"
Write-Host "[$manifestPropertyName]"
Write-Host "[$manifestPropertyName] - Checking path for functions and filters"

$publicFolderPath = Join-Path -Path $SourceFolderPath -ChildPath 'functions/public'
if (-not (Test-Path -Path $publicFolderPath -PathType Container)) {
Write-Verbose "[$manifestPropertyName] - [Folder not found] - [$publicFolderPath]"
Write-Host "[$manifestPropertyName] - [Folder not found] - [$publicFolderPath]"
return $functionsToExport
}
Write-Verbose "[$manifestPropertyName] - [$publicFolderPath]"
Write-Host "[$manifestPropertyName] - [$publicFolderPath]"
$functionsToExport = [Collections.Generic.List[string]]::new()
$scriptFiles = Get-ChildItem -Path $publicFolderPath -Recurse -File -ErrorAction SilentlyContinue -Include '*.ps1'
Write-Verbose "[$manifestPropertyName] - [$($scriptFiles.Count)]"
Write-Host "[$manifestPropertyName] - [$($scriptFiles.Count)]"
foreach ($file in $scriptFiles) {
$fileContent = Get-Content -Path $file.FullName -Raw
$containsFunction = ($fileContent -match 'function ') -or ($fileContent -match 'filter ')
Write-Verbose "[$manifestPropertyName] - [$($file.BaseName)] - [$containsFunction]"
Write-Host "[$manifestPropertyName] - [$($file.BaseName)] - [$containsFunction]"
if ($containsFunction) {
$functionsToExport.Add($file.BaseName)
}
Expand Down
6 changes: 3 additions & 3 deletions scripts/helpers/Build/Get-PSModuleVariablesToExport.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

$manifestPropertyName = 'VariablesToExport'

Write-Verbose "[$manifestPropertyName]"
Write-Host "[$manifestPropertyName]"

$variableFolderPath = Join-Path -Path $SourceFolderPath -ChildPath 'variables/public'
if (-not (Test-Path -Path $variableFolderPath -PathType Container)) {
Write-Verbose "[$manifestPropertyName] - [Folder not found] - [$variableFolderPath]"
Write-Host "[$manifestPropertyName] - [Folder not found] - [$variableFolderPath]"
return $variablesToExport
}
$scriptFilePaths = Get-ChildItem -Path $variableFolderPath -Recurse -File -Filter *.ps1 | Select-Object -ExpandProperty FullName
Expand All @@ -38,7 +38,7 @@
}

$variablesToExport | ForEach-Object {
Write-Verbose "[$manifestPropertyName] - [$_]"
Write-Host "[$manifestPropertyName] - [$_]"
}

$variablesToExport
Expand Down
8 changes: 4 additions & 4 deletions scripts/helpers/Build/Import-PSModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
$manifestFilePath = Join-Path -Path $Path $manifestFileName
$manifestFile = Get-ModuleManifest -Path $manifestFilePath -As FileInfo -Verbose

Write-Verbose "Manifest file path: [$($manifestFile.FullName)]" -Verbose
Write-Host "Manifest file path: [$($manifestFile.FullName)]" -Verbose
$existingModule = Get-Module -Name $ModuleName -ListAvailable
$existingModule | Remove-Module -Force -Verbose
$existingModule.RequiredModules | ForEach-Object { $_ | Remove-Module -Force -Verbose -ErrorAction SilentlyContinue }
Expand All @@ -36,11 +36,11 @@
Resolve-PSModuleDependencies -ManifestFilePath $manifestFile
Import-Module -Name $ModuleName -RequiredVersion '999.0.0'

Write-Verbose 'List loaded modules'
Write-Host 'List loaded modules'
$availableModules = Get-Module -ListAvailable -Refresh -Verbose:$false
$availableModules | Select-Object Name, Version, Path | Sort-Object Name | Format-Table -AutoSize
Write-Verbose 'List commands'
Write-Verbose (Get-Command -Module $moduleName | Format-Table -AutoSize | Out-String)
Write-Host 'List commands'
Write-Host (Get-Command -Module $moduleName | Format-Table -AutoSize | Out-String)

if ($ModuleName -notin $availableModules.Name) {
throw 'Module not found'
Expand Down
14 changes: 7 additions & 7 deletions scripts/helpers/Build/Resolve-PSModuleDependency.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ function Resolve-PSModuleDependency {
[string] $ManifestFilePath
)

Write-Verbose 'Resolving dependencies'
Write-Host 'Resolving dependencies'

$manifest = Import-PowerShellDataFile -Path $ManifestFilePath
Write-Verbose "Reading [$ManifestFilePath]"
Write-Verbose "Found [$($manifest.RequiredModules.Count)] modules to install"
Write-Host "Reading [$ManifestFilePath]"
Write-Host "Found [$($manifest.RequiredModules.Count)] modules to install"

foreach ($requiredModule in $manifest.RequiredModules) {
$installParams = @{}
Expand All @@ -46,19 +46,19 @@ function Resolve-PSModuleDependency {
$installParams.Force = $true
$installParams.Verbose = $false

Write-Verbose "[$($installParams.Name)] - Installing module"
Write-Host "[$($installParams.Name)] - Installing module"
$VerbosePreferenceOriginal = $VerbosePreference
$VerbosePreference = 'SilentlyContinue'
Retry -Count 5 -Delay 10 {
Install-Module @installParams -AllowPrerelease:$false
}
$VerbosePreference = $VerbosePreferenceOriginal
Write-Verbose "[$($installParams.Name)] - Importing module"
Write-Host "[$($installParams.Name)] - Importing module"
$VerbosePreferenceOriginal = $VerbosePreference
$VerbosePreference = 'SilentlyContinue'
Import-Module @installParams
$VerbosePreference = $VerbosePreferenceOriginal
Write-Verbose "[$($installParams.Name)] - Done"
Write-Host "[$($installParams.Name)] - Done"
}
Write-Verbose 'Resolving dependencies - Done'
Write-Host 'Resolving dependencies - Done'
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ function Update-PSModuleManifestAliasesToExport {
[Parameter(Mandatory)]
[System.IO.DirectoryInfo] $ModuleOutputFolder
)
LogGroup "Updating aliases to export in module manifest" {
Write-Verbose "Module name: [$ModuleName]"
Write-Verbose "Module output folder: [$ModuleOutputFolder]"
LogGroup 'Updating aliases to export in module manifest' {
Write-Host "Module name: [$ModuleName]"
Write-Host "Module output folder: [$ModuleOutputFolder]"
$aliases = Get-Command -Module $ModuleName -CommandType Alias
Write-Verbose "Found aliases: [$($aliases.Count)]"
Write-Host "Found aliases: [$($aliases.Count)]"
foreach ($alias in $aliases) {
Write-Verbose "Alias: [$($alias.Name)]"
Write-Host "Alias: [$($alias.Name)]"
}
$outputManifestPath = Join-Path -Path $ModuleOutputFolder -ChildPath "$ModuleName.psd1"
Write-Verbose "Output manifest path: [$outputManifestPath]"
Write-Verbose "Setting module manifest with AliasesToExport"
Set-ModuleManifest -Path $outputManifestPath -AliasesToExport $aliases.Name
Write-Host "Output manifest path: [$outputManifestPath]"
Write-Host 'Setting module manifest with AliasesToExport'
Set-ModuleManifest -Path $outputManifestPath -AliasesToExport $aliases.Name -Verbose
}
}
10 changes: 5 additions & 5 deletions scripts/main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@ param()
$path = (Join-Path -Path $PSScriptRoot -ChildPath 'helpers')
LogGroup "Loading helper scripts from [$path]" {
Get-ChildItem -Path $path -Filter '*.ps1' -Recurse | ForEach-Object {
Write-Verbose "[$($_.FullName)]"
Write-Host "[$($_.FullName)]"
. $_.FullName
}
}

LogGroup 'Loading inputs' {
$moduleName = ($env:GITHUB_ACTION_INPUT_Name | IsNullOrEmpty) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_Name
Write-Verbose "Module name: [$moduleName]"
Write-Host "Module name: [$moduleName]"

$moduleSourceFolderPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath $env:GITHUB_ACTION_INPUT_Path $moduleName
if (-not (Test-Path -Path $moduleSourceFolderPath)) {
$moduleSourceFolderPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath $env:GITHUB_ACTION_INPUT_Path
}
Write-Verbose "Source module path: [$moduleSourceFolderPath]"
Write-Host "Source module path: [$moduleSourceFolderPath]"
if (-not (Test-Path -Path $moduleSourceFolderPath)) {
throw "Module path [$moduleSourceFolderPath] does not exist."
}

$modulesOutputFolderPath = Join-Path $env:GITHUB_WORKSPACE $env:GITHUB_ACTION_INPUT_ModulesOutputPath
Write-Verbose "Modules output path: [$modulesOutputFolderPath]"
Write-Host "Modules output path: [$modulesOutputFolderPath]"
$docsOutputFolderPath = Join-Path $env:GITHUB_WORKSPACE $env:GITHUB_ACTION_INPUT_DocsOutputPath
Write-Verbose "Docs output path: [$docsOutputFolderPath]"
Write-Host "Docs output path: [$docsOutputFolderPath]"
}

$params = @{
Expand Down