Skip to content

Commit

Permalink
🩹 [Patch]: Improve workflow logging by changing Write-Verbose to `W…
Browse files Browse the repository at this point in the history
…rite-Host` (#91)

## Description

This pull request focuses on changing the logging method from
`Write-Verbose` to `Write-Host` in various PowerShell scripts. As most
of these log lines anyway would be under a log group, it didn't make
sense anymore to require additional input to get to the logs.

Logging method changes:

*
[`scripts/helpers/Build-PSModule.ps1`](diffhunk://#diff-c688e346ad60fbe881bd05b6a5dbc1cd712fdca0bf8b8527965db583af825fd9L35-R47):
Replaced `Write-Verbose` with `Write-Host` for logging source paths,
module source folder, module output folder, and docs output folder.
*
[`scripts/helpers/Build/Build-PSModuleBase.ps1`](diffhunk://#diff-1ab7417b36702be4629b208ad7dd9ec76f94998bb625c4810edda2f9b5dbddb8L35-R35):
Replaced `Write-Verbose` with `Write-Host` for logging the copying of
files.
*
[`scripts/helpers/Build/Build-PSModuleDocumentation.ps1`](diffhunk://#diff-dc95bfbd255c5bb79df192179e9cc5141ef230a8d82e80bc12fc6fefe6186fffL37-R37):
Replaced `Write-Verbose` with `Write-Host` for logging module import,
processing files, and finding script paths.
[[1]](diffhunk://#diff-dc95bfbd255c5bb79df192179e9cc5141ef230a8d82e80bc12fc6fefe6186fffL37-R37)
[[2]](diffhunk://#diff-dc95bfbd255c5bb79df192179e9cc5141ef230a8d82e80bc12fc6fefe6186fffL78-R94)
*
[`scripts/helpers/Build/Build-PSModuleManifest.ps1`](diffhunk://#diff-50cfb011f5c8aeef8145003927ec3e5edfdf26e5d417bcee6e441517c07454f9L36-R93):
Replaced `Write-Verbose` with `Write-Host` for logging various steps in
building the module manifest, such as loading the manifest, setting
module properties, and processing required modules.
[[1]](diffhunk://#diff-50cfb011f5c8aeef8145003927ec3e5edfdf26e5d417bcee6e441517c07454f9L36-R93)
[[2]](diffhunk://#diff-50cfb011f5c8aeef8145003927ec3e5edfdf26e5d417bcee6e441517c07454f9L108-R181)
[[3]](diffhunk://#diff-50cfb011f5c8aeef8145003927ec3e5edfdf26e5d417bcee6e441517c07454f9L194-R208)
[[4]](diffhunk://#diff-50cfb011f5c8aeef8145003927ec3e5edfdf26e5d417bcee6e441517c07454f9L226-R226)
[[5]](diffhunk://#diff-50cfb011f5c8aeef8145003927ec3e5edfdf26e5d417bcee6e441517c07454f9L245-R251)
[[6]](diffhunk://#diff-50cfb011f5c8aeef8145003927ec3e5edfdf26e5d417bcee6e441517c07454f9L277-R283)

## Type of change

<!-- Use the check-boxes [x] on the options that are relevant. -->

- [ ] 📖 [Docs]
- [ ] 🪲 [Fix]
- [x] 🩹 [Patch]
- [ ] ⚠️ [Security fix]
- [ ] 🚀 [Feature]
- [ ] 🌟 [Breaking change]

## Checklist

<!-- Use the check-boxes [x] on the options that are relevant. -->

- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
  • Loading branch information
MariusStorhaug authored Jan 29, 2025
1 parent ae49488 commit 0969771
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 131 deletions.
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'
}
16 changes: 8 additions & 8 deletions scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1
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

0 comments on commit 0969771

Please sign in to comment.