From 1e3d61264e04e3f0afe5f153dbe092e8d970f52e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 01:51:42 +0100 Subject: [PATCH 1/8] =?UTF-8?q?=F0=9F=AA=B2=20[Fix]:=20Fix=20`Variables`?= =?UTF-8?q?=20being=20`$null`=20(#110)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description This pull request includes a minor change to the `Get-PSModuleVariablesToExport.ps1` script. The change involves moving the initialization of the `$variablesToExport` variable to an earlier point in the script to ensure it is defined before any potential early returns. * [`scripts/helpers/Build/Get-PSModuleVariablesToExport.ps1`](diffhunk://#diff-e2148fcf63283d70b3d432f67fc98191e2cc712dc3f4d30914c8c0810d11a6deR28-L35): Moved the initialization of `$variablesToExport` to before the folder existence check to ensure it is always defined. ## Type of change - [ ] 📖 [Docs] - [x] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas --- .github/workflows/Action-Test.yml | 18 ++++++++++++++++++ .../Build/Get-PSModuleVariablesToExport.ps1 | 7 ++++--- .../functions/public/Test-PSModuleTest.ps1 | 18 ++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 tests/srcMinimal/functions/public/Test-PSModuleTest.ps1 diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 38a09542..9b4c038b 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -35,6 +35,24 @@ jobs: Path: tests/src ModulesOutputPath: tests/outputs/modules + ActionTestMinimal: + name: Action-Test - [Minimal] + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Initialize environment + uses: PSModule/Initialize-PSModule@main + + - name: Action-Test + uses: ./ + with: + Name: PSModuleTest + Path: tests/srcMinimal + ModulesOutputPath: tests/outputs/modules + ModuleArtifactName: moduleMinimal + ActionTestWithManifest: name: Action-Test - [DefaultWithManifest] runs-on: ubuntu-24.04 diff --git a/scripts/helpers/Build/Get-PSModuleVariablesToExport.ps1 b/scripts/helpers/Build/Get-PSModuleVariablesToExport.ps1 index e2810ba8..6649d91b 100644 --- a/scripts/helpers/Build/Get-PSModuleVariablesToExport.ps1 +++ b/scripts/helpers/Build/Get-PSModuleVariablesToExport.ps1 @@ -9,11 +9,12 @@ .EXAMPLE Get-PSModuleVariablesToExport -SourceFolderPath 'C:\MyModule\src\MyModule' #> - [OutputType([Collections.Generic.List[string]])] [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSAvoidUsingWriteHost', '', Scope = 'Function', Justification = 'Want to just write to the console, not the pipeline.' )] + [OutputType([string])] + [OutputType([Collections.Generic.List[string]])] [CmdletBinding()] param( # Path to the folder where the module source code is located. @@ -25,14 +26,14 @@ Write-Host "[$manifestPropertyName]" + $variablesToExport = [Collections.Generic.List[string]]::new() $variableFolderPath = Join-Path -Path $SourceFolderPath -ChildPath 'variables/public' if (-not (Test-Path -Path $variableFolderPath -PathType Container)) { Write-Host "[$manifestPropertyName] - [Folder not found] - [$variableFolderPath]" - return $variablesToExport + return '' } $scriptFilePaths = Get-ChildItem -Path $variableFolderPath -Recurse -File -Filter *.ps1 | Select-Object -ExpandProperty FullName - $variablesToExport = [Collections.Generic.List[string]]::new() $scriptFilePaths | ForEach-Object { $ast = [System.Management.Automation.Language.Parser]::ParseFile($_, [ref]$null, [ref]$null) $variables = Get-RootLevelVariable -Ast $ast diff --git a/tests/srcMinimal/functions/public/Test-PSModuleTest.ps1 b/tests/srcMinimal/functions/public/Test-PSModuleTest.ps1 new file mode 100644 index 00000000..26be2b9b --- /dev/null +++ b/tests/srcMinimal/functions/public/Test-PSModuleTest.ps1 @@ -0,0 +1,18 @@ +function Test-PSModuleTest { + <# + .SYNOPSIS + Performs tests on a module. + + .EXAMPLE + Test-PSModule -Name 'World' + + "Hello, World!" + #> + [CmdletBinding()] + param ( + # Name of the person to greet. + [Parameter(Mandatory)] + [string] $Name + ) + Write-Output "Hello, $Name!" +} From d778e56899f3f3125b957a3da65698818e78ae7f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 7 Mar 2025 23:40:07 +0100 Subject: [PATCH 2/8] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20dependen?= =?UTF-8?q?cy=20on=20`Utilities`=20(#111)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description This pull request includes several changes to improve the handling of null or empty string checks in various PowerShell scripts. The updates primarily involve replacing custom `IsNullOrEmpty` function calls with the built-in `[string]::IsNullOrEmpty` method to enhance readability and maintainability. Improvements to null or empty string checks: * [`scripts/helpers/Build/Build-PSModuleManifest.ps1`](diffhunk://#diff-50cfb011f5c8aeef8145003927ec3e5edfdf26e5d417bcee6e441517c07454f9L63-R66): Replaced custom `IsNotNullOrEmpty` checks with `[string]::IsNullOrEmpty` for the `Author`, `CompanyName`, and `Description` properties in the module manifest. [[1]](diffhunk://#diff-50cfb011f5c8aeef8145003927ec3e5edfdf26e5d417bcee6e441517c07454f9L63-R66) [[2]](diffhunk://#diff-50cfb011f5c8aeef8145003927ec3e5edfdf26e5d417bcee6e441517c07454f9L76-R76) * [`scripts/helpers/Build/Get-PSModuleAliasesToExport.ps1`](diffhunk://#diff-ae18191466ffa02c1a8429365cf96d8768f5eae03331c4a35199f8cd961e76a7L33-R34): Updated the check for `AliasesToExport` to use `[string]::IsNullOrEmpty`. * [`scripts/helpers/Build/Get-PSModuleCmdletsToExport.ps1`](diffhunk://#diff-f542f4a75d778df60fee6e176c795e133be2ed109d8212c05aa545383bd26c46L33-R34): Updated the check for `CmdletsToExport` to use `[string]::IsNullOrEmpty`. * [`scripts/main.ps1`](diffhunk://#diff-dc2e5a659836b1b73abb03421c567f5018c2755677c4a0aa764cb26117b68011L8-L9): Removed unused module requirement and updated the check for `GITHUB_ACTION_INPUT_Name` to use `[string]::IsNullOrEmpty`. [[1]](diffhunk://#diff-dc2e5a659836b1b73abb03421c567f5018c2755677c4a0aa764cb26117b68011L8-L9) [[2]](diffhunk://#diff-dc2e5a659836b1b73abb03421c567f5018c2755677c4a0aa764cb26117b68011L19-R17) ## Type of change - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas --- .github/workflows/Action-Test.yml | 6 +- scripts/helpers/Build-PSModule.ps1 | 1 - .../helpers/Build/Add-ModuleManifestData.ps1 | 164 +++++++++ scripts/helpers/Build/Add-PSModulePath.ps1 | 29 ++ .../helpers/Build/Build-PSModuleManifest.ps1 | 7 +- .../Build/Export-PowerShellDataFile.ps1 | 30 ++ .../helpers/Build/Format-ModuleManifest.ps1 | 32 ++ scripts/helpers/Build/Get-ModuleManifest.ps1 | 121 +++++++ .../Build/Get-PSModuleAliasesToExport.ps1 | 4 +- .../Build/Get-PSModuleCmdletsToExport.ps1 | 4 +- scripts/helpers/Build/Import-PSModule.ps1 | 1 - scripts/helpers/Build/Set-ModuleManifest.ps1 | 325 ++++++++++++++++++ scripts/helpers/Build/Show-FileContent.ps1 | 32 ++ ...Update-PSModuleManifestAliasesToExport.ps1 | 1 - scripts/main.ps1 | 4 +- 15 files changed, 744 insertions(+), 17 deletions(-) create mode 100644 scripts/helpers/Build/Add-ModuleManifestData.ps1 create mode 100644 scripts/helpers/Build/Add-PSModulePath.ps1 create mode 100644 scripts/helpers/Build/Export-PowerShellDataFile.ps1 create mode 100644 scripts/helpers/Build/Format-ModuleManifest.ps1 create mode 100644 scripts/helpers/Build/Get-ModuleManifest.ps1 create mode 100644 scripts/helpers/Build/Set-ModuleManifest.ps1 create mode 100644 scripts/helpers/Build/Show-FileContent.ps1 diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 9b4c038b..cba9f20d 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -26,7 +26,7 @@ jobs: uses: actions/checkout@v4 - name: Initialize environment - uses: PSModule/Initialize-PSModule@main + uses: PSModule/Initialize-PSModule@v1 - name: Action-Test uses: ./ @@ -43,7 +43,7 @@ jobs: uses: actions/checkout@v4 - name: Initialize environment - uses: PSModule/Initialize-PSModule@main + uses: PSModule/Initialize-PSModule@v1 - name: Action-Test uses: ./ @@ -61,7 +61,7 @@ jobs: uses: actions/checkout@v4 - name: Initialize environment - uses: PSModule/Initialize-PSModule@main + uses: PSModule/Initialize-PSModule@v1 - name: Action-Test uses: ./ diff --git a/scripts/helpers/Build-PSModule.ps1 b/scripts/helpers/Build-PSModule.ps1 index ef5c67cb..348a4d35 100644 --- a/scripts/helpers/Build-PSModule.ps1 +++ b/scripts/helpers/Build-PSModule.ps1 @@ -8,7 +8,6 @@ #> [CmdletBinding()] #Requires -Modules @{ ModuleName = 'GitHub'; ModuleVersion = '0.13.2' } - #Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' } [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSReviewUnusedParameter', '', Scope = 'Function', Justification = 'LogGroup - Scoping affects the variables line of sight.' diff --git a/scripts/helpers/Build/Add-ModuleManifestData.ps1 b/scripts/helpers/Build/Add-ModuleManifestData.ps1 new file mode 100644 index 00000000..3a491a52 --- /dev/null +++ b/scripts/helpers/Build/Add-ModuleManifestData.ps1 @@ -0,0 +1,164 @@ +function Add-ModuleManifestData { + <# + .SYNOPSIS + Add data to a module manifest file property + + .DESCRIPTION + This function adds data to a module manifest file property. + If the property doesn't exist, it will be created. + If it does exist, the new data will be appended to the existing data. + + .EXAMPLE + Add-ModuleManifestData -Path 'MyModule.psd1' -RequiredModules 'pester', 'platyPS' + + Adds the modules 'pester' and 'platyPS' to the RequiredModules property of the module manifest file 'MyModule.psd1'. + #> + [CmdletBinding()] + param( + [Parameter(Mandatory)] + [ValidateScript({ Test-Path -Path $_ -PathType Leaf })] + [string]$Path, + + # Modules that must be imported into the global environment prior to importing this module. + [Parameter()] + [Object[]] $RequiredModules, + + # Compatible editions of PowerShell. + [Parameter()] + [string[]] $CompatiblePSEditions, + + # Assemblies that must be loaded prior to importing this module. + [Parameter()] + [string[]] $RequiredAssemblies, + + # Script files (.ps1) that are run in the caller's environment prior to importing this module. + [Parameter()] + [string[]] $ScriptsToProcess, + + # Type files (.ps1xml) to be loaded when importing this module. + [Parameter()] + [string[]] $TypesToProcess, + + # Format files (.ps1xml) to be loaded when importing this module. + [Parameter()] + [string[]] $FormatsToProcess, + + # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess. + [Parameter()] + [Object[]] $NestedModules, + + # Functions to export from this module, for best performance, do not use wildcards and do not + # delete the entry, use an empty array if there are no functions to export. + [Parameter()] + [string[]] $FunctionsToExport, + + # Cmdlets to export from this module, for best performance, do not use wildcards and do not + # delete the entry, use an empty array if there are no cmdlets to export. + [Parameter()] + [string[]] $CmdletsToExport, + + # Variables to export from this module. + [Parameter()] + [string[]] $VariablesToExport, + + # Aliases to export from this module, for best performance, do not use wildcards and do not + # delete the entry, use an empty array if there are no aliases to export. + [Parameter()] + [string[]] $AliasesToExport, + + # DSC resources to export from this module. + [Parameter()] + [string[]] $DscResourcesToExport, + + # List of all modules packaged with this module. + [Parameter()] + [Object[]] $ModuleList, + + # List of all files packaged with this module. + [Parameter()] + [string[]] $FileList, + + # Tags applied to this module. These help with module discovery in online galleries. + [Parameter()] + [string[]] $Tags, + + # External dependent modules of this module. + [Parameter()] + [string[]] $ExternalModuleDependencies + ) + + $moduleManifest = Get-ModuleManifest -Path $Path + $changes = @{} + + if ($RequiredModules) { + $RequiredModules += $moduleManifest.RequiredModules + $changes.RequiredModules = $RequiredModules + } + if ($RequiredAssemblies) { + $RequiredAssemblies += $moduleManifest.RequiredAssemblies + $changes.RequiredAssemblies = $RequiredAssemblies + } + if ($CompatiblePSEditions) { + $CompatiblePSEditions += $moduleManifest.CompatiblePSEditions + $changes.CompatiblePSEditions = $CompatiblePSEditions + } + if ($ScriptsToProcess) { + $ScriptsToProcess += $moduleManifest.ScriptsToProcess + $changes.ScriptsToProcess = $ScriptsToProcess + } + if ($TypesToProcess) { + $TypesToProcess += $moduleManifest.TypesToProcess + $changes.TypesToProcess = $TypesToProcess + } + if ($FormatsToProcess) { + $FormatsToProcess += $moduleManifest.FormatsToProcess + $changes.FormatsToProcess = $FormatsToProcess + } + if ($NestedModules) { + $NestedModules += $moduleManifest.NestedModules + $changes.NestedModules = $NestedModules + } + if ($FunctionsToExport) { + $FunctionsToExport += $moduleManifest.FunctionsToExport + $changes.FunctionsToExport = $FunctionsToExport + } + if ($CmdletsToExport) { + $CmdletsToExport += $moduleManifest.CmdletsToExport + $changes.CmdletsToExport = $CmdletsToExport + } + if ($VariablesToExport) { + $VariablesToExport += $moduleManifest.VariablesToExport + $changes.VariablesToExport = $VariablesToExport + } + if ($AliasesToExport) { + $AliasesToExport += $moduleManifest.AliasesToExport + $changes.AliasesToExport = $AliasesToExport + } + if ($DscResourcesToExport) { + $DscResourcesToExport += $moduleManifest.DscResourcesToExport + $changes.DscResourcesToExport = $DscResourcesToExport + } + if ($ModuleList) { + $ModuleList += $moduleManifest.ModuleList + $changes.ModuleList = $ModuleList + } + if ($FileList) { + $FileList += $moduleManifest.FileList + $changes.FileList = $FileList + } + if ($Tags) { + $Tags += $moduleManifest.PrivateData.PSData.Tags + $changes.Tags = $Tags + } + if ($ExternalModuleDependencies) { + $ExternalModuleDependencies += $moduleManifest.PrivateData.PSData.ExternalModuleDependencies + $changes.ExternalModuleDependencies = $ExternalModuleDependencies + } + + foreach ($key in $changes.GetEnumerator().Name) { + $changes[$key] = $changes[$key] | Sort-Object -Unique | Where-Object { -not [string]::IsNullOrEmpty($_) } + } + + Set-ModuleManifest -Path $Path @changes + +} diff --git a/scripts/helpers/Build/Add-PSModulePath.ps1 b/scripts/helpers/Build/Add-PSModulePath.ps1 new file mode 100644 index 00000000..f5abf042 --- /dev/null +++ b/scripts/helpers/Build/Add-PSModulePath.ps1 @@ -0,0 +1,29 @@ +function Add-PSModulePath { + <# + .SYNOPSIS + Adds a path to the PSModulePath environment variable. + + .DESCRIPTION + Adds a path to the PSModulePath environment variable. + For Linux and macOS, the path delimiter is ':' and for Windows it is ';'. + + .EXAMPLE + Add-PSModulePath -Path 'C:\Users\user\Documents\WindowsPowerShell\Modules' + + Adds the path 'C:\Users\user\Documents\WindowsPowerShell\Modules' to the PSModulePath environment variable. + #> + [CmdletBinding()] + param( + # Path to the folder where the module source code is located. + [Parameter(Mandatory)] + [string] $Path + ) + $PSModulePathSeparator = [System.IO.Path]::PathSeparator + + $env:PSModulePath += "$PSModulePathSeparator$Path" + + Write-Verbose 'PSModulePath:' + $env:PSModulePath.Split($PSModulePathSeparator) | ForEach-Object { + Write-Verbose " - [$_]" + } +} diff --git a/scripts/helpers/Build/Build-PSModuleManifest.ps1 b/scripts/helpers/Build/Build-PSModuleManifest.ps1 index 2a611f0d..4cda1732 100644 --- a/scripts/helpers/Build/Build-PSModuleManifest.ps1 +++ b/scripts/helpers/Build/Build-PSModuleManifest.ps1 @@ -12,7 +12,6 @@ #> [CmdletBinding()] #Requires -Modules @{ ModuleName = 'GitHub'; ModuleVersion = '0.13.2' } - #Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' } [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSAvoidLongLines', '', Scope = 'Function', Justification = 'Easier to read the multi ternery operators in a single line.' @@ -60,10 +59,10 @@ $manifest.ModuleVersion = '999.0.0' Write-Host "[ModuleVersion] - [$($manifest.ModuleVersion)]" - $manifest.Author = $manifest.Keys -contains 'Author' ? ($manifest.Author | IsNotNullOrEmpty) ? $manifest.Author : $env:GITHUB_REPOSITORY_OWNER : $env:GITHUB_REPOSITORY_OWNER + $manifest.Author = $manifest.Keys -contains 'Author' ? -not [string]::IsNullOrEmpty($manifest.Author) ? $manifest.Author : $env:GITHUB_REPOSITORY_OWNER : $env:GITHUB_REPOSITORY_OWNER Write-Host "[Author] - [$($manifest.Author)]" - $manifest.CompanyName = $manifest.Keys -contains 'CompanyName' ? ($manifest.CompanyName | IsNotNullOrEmpty) ? $manifest.CompanyName : $env:GITHUB_REPOSITORY_OWNER : $env:GITHUB_REPOSITORY_OWNER + $manifest.CompanyName = $manifest.Keys -contains 'CompanyName' ? -not [string]::IsNullOrEmpty($manifest.CompanyName) ? $manifest.CompanyName : $env:GITHUB_REPOSITORY_OWNER : $env:GITHUB_REPOSITORY_OWNER Write-Host "[CompanyName] - [$($manifest.CompanyName)]" $year = Get-Date -Format 'yyyy' @@ -73,7 +72,7 @@ Write-Host "[Copyright] - [$($manifest.Copyright)]" $repoDescription = gh repo view --json description | ConvertFrom-Json | Select-Object -ExpandProperty description - $manifest.Description = $manifest.Keys -contains 'Description' ? ($manifest.Description | IsNotNullOrEmpty) ? $manifest.Description : $repoDescription : $repoDescription + $manifest.Description = $manifest.Keys -contains 'Description' ? -not [string]::IsNullOrEmpty($manifest.Description) ? $manifest.Description : $repoDescription : $repoDescription Write-Host "[Description] - [$($manifest.Description)]" $manifest.PowerShellHostName = $manifest.Keys -contains 'PowerShellHostName' ? -not [string]::IsNullOrEmpty($manifest.PowerShellHostName) ? $manifest.PowerShellHostName : $null : $null diff --git a/scripts/helpers/Build/Export-PowerShellDataFile.ps1 b/scripts/helpers/Build/Export-PowerShellDataFile.ps1 new file mode 100644 index 00000000..5c5daf84 --- /dev/null +++ b/scripts/helpers/Build/Export-PowerShellDataFile.ps1 @@ -0,0 +1,30 @@ +function Export-PowerShellDataFile { + <# + .SYNOPSIS + Export a hashtable to a .psd1 file. + + .DESCRIPTION + This function exports a hashtable to a .psd1 file. It also formats the .psd1 file using the Format-ModuleManifest cmdlet. + + .EXAMPLE + Export-PowerShellDataFile -Hashtable @{ Name = 'MyModule'; ModuleVersion = '1.0.0' } -Path 'MyModule.psd1' + #> + [CmdletBinding()] + param ( + # The hashtable to export to a .psd1 file. + [Parameter(Mandatory)] + [object] $Hashtable, + + # The path of the .psd1 file to export. + [Parameter(Mandatory)] + [string] $Path, + + # Force the export, even if the file already exists. + [Parameter()] + [switch] $Force + ) + + $content = Format-Hashtable -Hashtable $Hashtable + $content | Out-File -FilePath $Path -Force:$Force + Format-ModuleManifest -Path $Path +} diff --git a/scripts/helpers/Build/Format-ModuleManifest.ps1 b/scripts/helpers/Build/Format-ModuleManifest.ps1 new file mode 100644 index 00000000..45e6c222 --- /dev/null +++ b/scripts/helpers/Build/Format-ModuleManifest.ps1 @@ -0,0 +1,32 @@ +function Format-ModuleManifest { + <# + .SYNOPSIS + Formats a module manifest file. + + .DESCRIPTION + This function formats a module manifest file, by removing comments and empty lines, + and then formatting the file using the `Invoke-Formatter` function. + + .EXAMPLE + Format-ModuleManifest -Path 'C:\MyModule\MyModule.psd1' + #> + [CmdletBinding()] + param( + # Path to the module manifest file. + [Parameter(Mandatory)] + [string] $Path + ) + + $Utf8BomEncoding = New-Object System.Text.UTF8Encoding $true + + $manifestContent = Get-Content -Path $Path + $manifestContent = $manifestContent | ForEach-Object { $_ -replace '#.*' } + $manifestContent = $manifestContent | ForEach-Object { $_.TrimEnd() } + $manifestContent = $manifestContent | Where-Object { -not [string]::IsNullOrEmpty($_) } + [System.IO.File]::WriteAllLines($Path, $manifestContent, $Utf8BomEncoding) + $manifestContent = Get-Content -Path $Path -Raw + + $content = Invoke-Formatter -ScriptDefinition $manifestContent + [System.IO.File]::WriteAllLines($Path, $content, $Utf8BomEncoding) + +} diff --git a/scripts/helpers/Build/Get-ModuleManifest.ps1 b/scripts/helpers/Build/Get-ModuleManifest.ps1 new file mode 100644 index 00000000..a3afd35b --- /dev/null +++ b/scripts/helpers/Build/Get-ModuleManifest.ps1 @@ -0,0 +1,121 @@ +function Get-ModuleManifest { + <# + .SYNOPSIS + Get the module manifest. + + .DESCRIPTION + Get the module manifest as a path, file info, content, or hashtable. + + .EXAMPLE + Get-PSModuleManifest -Path 'src/PSModule/PSModule.psd1' -As Hashtable + #> + [OutputType([string], [System.IO.FileInfo], [System.Collections.Hashtable], [System.Collections.Specialized.OrderedDictionary])] + [CmdletBinding()] + param( + # Path to the module manifest file. + [Parameter(Mandatory)] + [string] $Path, + + # The format of the output. + [Parameter()] + [ValidateSet('FileInfo', 'Content', 'Hashtable')] + [string] $As = 'Hashtable' + ) + + if (-not (Test-Path -Path $Path)) { + Write-Warning 'No manifest file found.' + return $null + } + Write-Verbose "Found manifest file [$Path]" + + switch ($As) { + 'FileInfo' { + return Get-Item -Path $Path + } + 'Content' { + return Get-Content -Path $Path + } + 'Hashtable' { + $manifest = [System.Collections.Specialized.OrderedDictionary]@{} + $psData = [System.Collections.Specialized.OrderedDictionary]@{} + $privateData = [System.Collections.Specialized.OrderedDictionary]@{} + $tempManifest = Import-PowerShellDataFile -Path $Path + if ($tempManifest.ContainsKey('PrivateData')) { + $tempPrivateData = $tempManifest.PrivateData + if ($tempPrivateData.ContainsKey('PSData')) { + $tempPSData = $tempPrivateData.PSData + $tempPrivateData.Remove('PSData') + } + } + + $psdataOrder = @( + 'Tags' + 'LicenseUri' + 'ProjectUri' + 'IconUri' + 'ReleaseNotes' + 'Prerelease' + 'RequireLicenseAcceptance' + 'ExternalModuleDependencies' + ) + foreach ($key in $psdataOrder) { + if (($null -ne $tempPSData) -and ($tempPSData.ContainsKey($key))) { + $psData.$key = $tempPSData.$key + } + } + if ($psData.Count -gt 0) { + $privateData.PSData = $psData + } else { + $privateData.Remove('PSData') + } + foreach ($key in $tempPrivateData.Keys) { + $privateData.$key = $tempPrivateData.$key + } + + $manifestOrder = @( + 'RootModule' + 'ModuleVersion' + 'CompatiblePSEditions' + 'GUID' + 'Author' + 'CompanyName' + 'Copyright' + 'Description' + 'PowerShellVersion' + 'PowerShellHostName' + 'PowerShellHostVersion' + 'DotNetFrameworkVersion' + 'ClrVersion' + 'ProcessorArchitecture' + 'RequiredModules' + 'RequiredAssemblies' + 'ScriptsToProcess' + 'TypesToProcess' + 'FormatsToProcess' + 'NestedModules' + 'FunctionsToExport' + 'CmdletsToExport' + 'VariablesToExport' + 'AliasesToExport' + 'DscResourcesToExport' + 'ModuleList' + 'FileList' + 'HelpInfoURI' + 'DefaultCommandPrefix' + 'PrivateData' + ) + foreach ($key in $manifestOrder) { + if ($tempManifest.ContainsKey($key)) { + $manifest.$key = $tempManifest.$key + } + } + if ($privateData.Count -gt 0) { + $manifest.PrivateData = $privateData + } else { + $manifest.Remove('PrivateData') + } + + return $manifest + } + } +} diff --git a/scripts/helpers/Build/Get-PSModuleAliasesToExport.ps1 b/scripts/helpers/Build/Get-PSModuleAliasesToExport.ps1 index 5c8a990e..d2a24d43 100644 --- a/scripts/helpers/Build/Get-PSModuleAliasesToExport.ps1 +++ b/scripts/helpers/Build/Get-PSModuleAliasesToExport.ps1 @@ -10,7 +10,6 @@ Get-PSModuleAliasesToExport -SourceFolderPath 'C:\MyModule\src\MyModule' #> [CmdletBinding()] - #Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' } [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSAvoidUsingWriteHost', '', Scope = 'Function', Justification = 'Want to just write to the console, not the pipeline.' @@ -30,7 +29,8 @@ $manifest = Get-ModuleManifest -Path $manifestFilePath -Verbose:$false Write-Host "[$manifestPropertyName]" - $aliasesToExport = (($manifest.AliasesToExport).count -eq 0) -or ($manifest.AliasesToExport | IsNullOrEmpty) ? '*' : $manifest.AliasesToExport + $aliasesToExport = (($manifest.AliasesToExport).count -eq 0) -or [string]::IsNullOrEmpty($manifest.AliasesToExport) ? + '*' : $manifest.AliasesToExport $aliasesToExport | ForEach-Object { Write-Host "[$manifestPropertyName] - [$_]" } diff --git a/scripts/helpers/Build/Get-PSModuleCmdletsToExport.ps1 b/scripts/helpers/Build/Get-PSModuleCmdletsToExport.ps1 index 2e07f8c3..a7968581 100644 --- a/scripts/helpers/Build/Get-PSModuleCmdletsToExport.ps1 +++ b/scripts/helpers/Build/Get-PSModuleCmdletsToExport.ps1 @@ -10,7 +10,6 @@ Get-PSModuleCmdletsToExport -SourceFolderPath 'C:\MyModule\src\MyModule' #> [CmdletBinding()] - #Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' } [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSAvoidUsingWriteHost', '', Scope = 'Function', Justification = 'Want to just write to the console, not the pipeline.' @@ -30,7 +29,8 @@ $manifest = Get-ModuleManifest -Path $manifestFilePath -Verbose:$false Write-Host "[$manifestPropertyName]" - $cmdletsToExport = (($manifest.CmdletsToExport).count -eq 0) -or ($manifest.CmdletsToExport | IsNullOrEmpty) ? '' : $manifest.CmdletsToExport + $cmdletsToExport = (($manifest.CmdletsToExport).count -eq 0) -or [string]::IsNullOrEmpty($manifest.CmdletsToExport) ? + '' : $manifest.CmdletsToExport $cmdletsToExport | ForEach-Object { Write-Host "[$manifestPropertyName] - [$_]" } diff --git a/scripts/helpers/Build/Import-PSModule.ps1 b/scripts/helpers/Build/Import-PSModule.ps1 index 79fa949a..7db7ca93 100644 --- a/scripts/helpers/Build/Import-PSModule.ps1 +++ b/scripts/helpers/Build/Import-PSModule.ps1 @@ -16,7 +16,6 @@ 'PSAvoidUsingWriteHost', '', Scope = 'Function', Justification = 'Want to just write to the console, not the pipeline.' )] - #Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' } param( # Path to the folder where the module source code is located. [Parameter(Mandatory)] diff --git a/scripts/helpers/Build/Set-ModuleManifest.ps1 b/scripts/helpers/Build/Set-ModuleManifest.ps1 new file mode 100644 index 00000000..558857af --- /dev/null +++ b/scripts/helpers/Build/Set-ModuleManifest.ps1 @@ -0,0 +1,325 @@ +filter Set-ModuleManifest { + <# + .SYNOPSIS + Sets the values of a module manifest file. + + .DESCRIPTION + This function sets the values of a module manifest file. + Very much like the Update-ModuleManifest function, but allows values to be missing. + + .EXAMPLE + Set-ModuleManifest -Path 'C:\MyModule\MyModule.psd1' -ModuleVersion '1.0.0' + #> + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseShouldProcessForStateChangingFunctions', '', + Justification = 'Function does not change state.' + )] + [CmdletBinding()] + param( + # Path to the module manifest file. + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName + )] + [string] $Path, + + #Script module or binary module file associated with this manifest. + [Parameter()] + [AllowNull()] + [string] $RootModule, + + #Version number of this module. + [Parameter()] + [AllowNull()] + [Version] $ModuleVersion, + + # Supported PSEditions. + [Parameter()] + [AllowNull()] + [string[]] $CompatiblePSEditions, + + # ID used to uniquely identify this module. + [Parameter()] + [AllowNull()] + [guid] $GUID, + + # Author of this module. + [Parameter()] + [AllowNull()] + [string] $Author, + + # Company or vendor of this module. + [Parameter()] + [AllowNull()] + [string] $CompanyName, + + # Copyright statement for this module. + [Parameter()] + [AllowNull()] + [string] $Copyright, + + # Description of the functionality provided by this module. + [Parameter()] + [AllowNull()] + [string] $Description, + + # Minimum version of the PowerShell engine required by this module. + [Parameter()] + [AllowNull()] + [Version] $PowerShellVersion, + + # Name of the PowerShell host required by this module. + [Parameter()] + [AllowNull()] + [string] $PowerShellHostName, + + # Minimum version of the PowerShell host required by this module. + [Parameter()] + [AllowNull()] + [version] $PowerShellHostVersion, + + # Minimum version of Microsoft .NET Framework required by this module. + # This prerequisite is valid for the PowerShell Desktop edition only. + [Parameter()] + [AllowNull()] + [Version] $DotNetFrameworkVersion, + + # Minimum version of the common language runtime (CLR) required by this module. + # This prerequisite is valid for the PowerShell Desktop edition only. + [Parameter()] + [AllowNull()] + [Version] $ClrVersion, + + # Processor architecture (None,X86, Amd64) required by this module + [Parameter()] + [AllowNull()] + [System.Reflection.ProcessorArchitecture] $ProcessorArchitecture, + + # Modules that must be imported into the global environment prior to importing this module. + [Parameter()] + [AllowNull()] + [Object[]] $RequiredModules, + + # Assemblies that must be loaded prior to importing this module. + [Parameter()] + [AllowNull()] + [string[]] $RequiredAssemblies, + + # Script files (.ps1) that are run in the caller's environment prior to importing this module. + [Parameter()] + [AllowNull()] + [string[]] $ScriptsToProcess, + + # Type files (.ps1xml) to be loaded when importing this module. + [Parameter()] + [AllowNull()] + [string[]] $TypesToProcess, + + # Format files (.ps1xml) to be loaded when importing this module. + [Parameter()] + [AllowNull()] + [string[]] $FormatsToProcess, + + # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess. + [Parameter()] + [AllowNull()] + [Object[]] $NestedModules, + + # Functions to export from this module, for best performance, do not use wildcards and do not + # delete the entry, use an empty array if there are no functions to export. + [Parameter()] + [AllowNull()] + [string[]] $FunctionsToExport, + + # Cmdlets to export from this module, for best performance, do not use wildcards and do not + # delete the entry, use an empty array if there are no cmdlets to export. + [Parameter()] + [AllowNull()] + [string[]] $CmdletsToExport, + + # Variables to export from this module. + [Parameter()] + [AllowNull()] + [string[]] $VariablesToExport, + + # Aliases to export from this module, for best performance, do not use wildcards and do not + # delete the entry, use an empty array if there are no aliases to export. + [Parameter()] + [AllowNull()] + [string[]] $AliasesToExport, + + # DSC resources to export from this module. + [Parameter()] + [AllowNull()] + [string[]] $DscResourcesToExport, + + # List of all modules packaged with this module. + [Parameter()] + [AllowNull()] + [Object[]] $ModuleList, + + # List of all files packaged with this module. + [Parameter()] + [AllowNull()] + [string[]] $FileList, + + # Tags applied to this module. These help with module discovery in online galleries. + [Parameter()] + [AllowNull()] + [string[]] $Tags, + + # A URL to the license for this module. + [Parameter()] + [AllowNull()] + [uri] $LicenseUri, + + # A URL to the main site for this project. + [Parameter()] + [AllowNull()] + [uri] $ProjectUri, + + # A URL to an icon representing this module. + [Parameter()] + [AllowNull()] + [uri] $IconUri, + + # ReleaseNotes of this module. + [Parameter()] + [AllowNull()] + [string] $ReleaseNotes, + + # Prerelease string of this module. + [Parameter()] + [AllowNull()] + [string] $Prerelease, + + # Flag to indicate whether the module requires explicit user acceptance for install/update/save. + [Parameter()] + [AllowNull()] + [bool] $RequireLicenseAcceptance, + + # External dependent modules of this module. + [Parameter()] + [AllowNull()] + [string[]] $ExternalModuleDependencies, + + # HelpInfo URI of this module. + [Parameter()] + [AllowNull()] + [String] $HelpInfoURI, + + # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. + [Parameter()] + [AllowNull()] + [string] $DefaultCommandPrefix, + + # Private data to pass to the module specified in RootModule/ModuleToProcess. + # This may also contain a PSData hashtable with additional module metadata used by PowerShell. + [Parameter()] + [AllowNull()] + [object] $PrivateData + ) + + $outManifest = [ordered]@{} + $outPSData = [ordered]@{} + $outPrivateData = [ordered]@{} + + $tempManifest = Get-ModuleManifest -Path $Path + if ($tempManifest.Keys.Contains('PrivateData')) { + $tempPrivateData = $tempManifest.PrivateData + if ($tempPrivateData.Keys.Contains('PSData')) { + $tempPSData = $tempPrivateData.PSData + $tempPrivateData.Remove('PSData') + } + } + + $psdataOrder = @( + 'Tags' + 'LicenseUri' + 'ProjectUri' + 'IconUri' + 'ReleaseNotes' + 'Prerelease' + 'RequireLicenseAcceptance' + 'ExternalModuleDependencies' + ) + foreach ($key in $psdataOrder) { + if (($null -ne $tempPSData) -and $tempPSData.Keys.Contains($key)) { + $outPSData[$key] = $tempPSData[$key] + } + if ($PSBoundParameters.Keys.Contains($key)) { + if ($null -eq $PSBoundParameters[$key]) { + $outPSData.Remove($key) + } else { + $outPSData[$key] = $PSBoundParameters[$key] + } + } + } + + if ($outPSData.Count -gt 0) { + $outPrivateData.PSData = $outPSData + } else { + $outPrivateData.Remove('PSData') + } + foreach ($key in $tempPrivateData.Keys) { + $outPrivateData[$key] = $tempPrivateData[$key] + } + foreach ($key in $PrivateData.Keys) { + $outPrivateData[$key] = $PrivateData[$key] + } + + $manifestOrder = @( + 'RootModule' + 'ModuleVersion' + 'CompatiblePSEditions' + 'GUID' + 'Author' + 'CompanyName' + 'Copyright' + 'Description' + 'PowerShellVersion' + 'PowerShellHostName' + 'PowerShellHostVersion' + 'DotNetFrameworkVersion' + 'ClrVersion' + 'ProcessorArchitecture' + 'RequiredModules' + 'RequiredAssemblies' + 'ScriptsToProcess' + 'TypesToProcess' + 'FormatsToProcess' + 'NestedModules' + 'FunctionsToExport' + 'CmdletsToExport' + 'VariablesToExport' + 'AliasesToExport' + 'DscResourcesToExport' + 'ModuleList' + 'FileList' + 'HelpInfoURI' + 'DefaultCommandPrefix' + 'PrivateData' + ) + foreach ($key in $manifestOrder) { + if ($tempManifest.Keys.Contains($key)) { + $outManifest[$key] = $tempManifest[$key] + } + if ($PSBoundParameters.Keys.Contains($key)) { + if ($null -eq $PSBoundParameters[$key]) { + $outManifest.Remove($key) + } else { + $outManifest[$key] = $PSBoundParameters[$key] + } + } + } + if ($outPrivateData.Count -gt 0) { + $outManifest['PrivateData'] = $outPrivateData + } else { + $outManifest.Remove('PrivateData') + } + + Remove-Item -Path $Path -Force + Export-PowerShellDataFile -Hashtable $outManifest -Path $Path + +} diff --git a/scripts/helpers/Build/Show-FileContent.ps1 b/scripts/helpers/Build/Show-FileContent.ps1 new file mode 100644 index 00000000..6ad62955 --- /dev/null +++ b/scripts/helpers/Build/Show-FileContent.ps1 @@ -0,0 +1,32 @@ +function Show-FileContent { + <# + .SYNOPSIS + Prints the content of a file with line numbers in front of each line. + + .DESCRIPTION + Prints the content of a file with line numbers in front of each line. + + .EXAMPLE + $Path = 'C:\Utilities\Show-FileContent.ps1' + Show-FileContent -Path $Path + + Shows the content of the file with line numbers in front of each line. + #> + [CmdletBinding()] + param ( + # The path to the file to show the content of. + [Parameter(Mandatory)] + [string] $Path + ) + + $content = Get-Content -Path $Path + $lineNumber = 1 + $columnSize = $content.Count.ToString().Length + # Foreach line print the line number in front of the line with [ ] around it. + # The linenumber should dynamically adjust to the number of digits with the length of the file. + foreach ($line in $content) { + $lineNumberFormatted = $lineNumber.ToString().PadLeft($columnSize) + Write-Host "[$lineNumberFormatted] $line" + $lineNumber++ + } +} diff --git a/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 b/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 index 47d64e45..1fc6d973 100644 --- a/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 +++ b/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 @@ -16,7 +16,6 @@ Justification = 'Want to just write to the console, not the pipeline.' )] #Requires -Modules @{ ModuleName = 'GitHub'; ModuleVersion = '0.13.2' } - #Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' } [CmdletBinding()] param( # Name of the module. diff --git a/scripts/main.ps1 b/scripts/main.ps1 index d831ebef..a1bb616a 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -5,8 +5,6 @@ [CmdletBinding()] param() -#Requires -Modules Utilities - $path = (Join-Path -Path $PSScriptRoot -ChildPath 'helpers') | Get-Item | Resolve-Path -Relative LogGroup "Loading helper scripts from [$path]" { Get-ChildItem -Path $path -Filter '*.ps1' -Recurse | Resolve-Path -Relative | ForEach-Object { @@ -16,7 +14,7 @@ LogGroup "Loading helper scripts from [$path]" { } LogGroup 'Loading inputs' { - $moduleName = ($env:GITHUB_ACTION_INPUT_Name | IsNullOrEmpty) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_Name + $moduleName = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Name) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_Name Write-Host "Module name: [$moduleName]" $moduleSourceFolderPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath $env:GITHUB_ACTION_INPUT_Path/$moduleName From 7f3f350d22a3657784b94f071b7a7d84c9f0d0fb Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 8 Mar 2025 00:29:05 +0100 Subject: [PATCH 3/8] =?UTF-8?q?Revert=20"=F0=9F=A9=B9=20[Patch]:=20Remove?= =?UTF-8?q?=20dependency=20on=20`Utilities`=20(#111)"=20(#112)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description This reverts commit d778e56899f3f3125b957a3da65698818e78ae7f. ## Type of change - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas --- scripts/helpers/Build-PSModule.ps1 | 1 + .../helpers/Build/Add-ModuleManifestData.ps1 | 164 --------- scripts/helpers/Build/Add-PSModulePath.ps1 | 29 -- .../helpers/Build/Build-PSModuleManifest.ps1 | 7 +- .../Build/Export-PowerShellDataFile.ps1 | 30 -- .../helpers/Build/Format-ModuleManifest.ps1 | 32 -- scripts/helpers/Build/Get-ModuleManifest.ps1 | 121 ------- .../Build/Get-PSModuleAliasesToExport.ps1 | 4 +- .../Build/Get-PSModuleCmdletsToExport.ps1 | 4 +- scripts/helpers/Build/Import-PSModule.ps1 | 1 + scripts/helpers/Build/Set-ModuleManifest.ps1 | 325 ------------------ scripts/helpers/Build/Show-FileContent.ps1 | 32 -- ...Update-PSModuleManifestAliasesToExport.ps1 | 1 + scripts/main.ps1 | 4 +- 14 files changed, 14 insertions(+), 741 deletions(-) delete mode 100644 scripts/helpers/Build/Add-ModuleManifestData.ps1 delete mode 100644 scripts/helpers/Build/Add-PSModulePath.ps1 delete mode 100644 scripts/helpers/Build/Export-PowerShellDataFile.ps1 delete mode 100644 scripts/helpers/Build/Format-ModuleManifest.ps1 delete mode 100644 scripts/helpers/Build/Get-ModuleManifest.ps1 delete mode 100644 scripts/helpers/Build/Set-ModuleManifest.ps1 delete mode 100644 scripts/helpers/Build/Show-FileContent.ps1 diff --git a/scripts/helpers/Build-PSModule.ps1 b/scripts/helpers/Build-PSModule.ps1 index 348a4d35..ef5c67cb 100644 --- a/scripts/helpers/Build-PSModule.ps1 +++ b/scripts/helpers/Build-PSModule.ps1 @@ -8,6 +8,7 @@ #> [CmdletBinding()] #Requires -Modules @{ ModuleName = 'GitHub'; ModuleVersion = '0.13.2' } + #Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' } [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSReviewUnusedParameter', '', Scope = 'Function', Justification = 'LogGroup - Scoping affects the variables line of sight.' diff --git a/scripts/helpers/Build/Add-ModuleManifestData.ps1 b/scripts/helpers/Build/Add-ModuleManifestData.ps1 deleted file mode 100644 index 3a491a52..00000000 --- a/scripts/helpers/Build/Add-ModuleManifestData.ps1 +++ /dev/null @@ -1,164 +0,0 @@ -function Add-ModuleManifestData { - <# - .SYNOPSIS - Add data to a module manifest file property - - .DESCRIPTION - This function adds data to a module manifest file property. - If the property doesn't exist, it will be created. - If it does exist, the new data will be appended to the existing data. - - .EXAMPLE - Add-ModuleManifestData -Path 'MyModule.psd1' -RequiredModules 'pester', 'platyPS' - - Adds the modules 'pester' and 'platyPS' to the RequiredModules property of the module manifest file 'MyModule.psd1'. - #> - [CmdletBinding()] - param( - [Parameter(Mandatory)] - [ValidateScript({ Test-Path -Path $_ -PathType Leaf })] - [string]$Path, - - # Modules that must be imported into the global environment prior to importing this module. - [Parameter()] - [Object[]] $RequiredModules, - - # Compatible editions of PowerShell. - [Parameter()] - [string[]] $CompatiblePSEditions, - - # Assemblies that must be loaded prior to importing this module. - [Parameter()] - [string[]] $RequiredAssemblies, - - # Script files (.ps1) that are run in the caller's environment prior to importing this module. - [Parameter()] - [string[]] $ScriptsToProcess, - - # Type files (.ps1xml) to be loaded when importing this module. - [Parameter()] - [string[]] $TypesToProcess, - - # Format files (.ps1xml) to be loaded when importing this module. - [Parameter()] - [string[]] $FormatsToProcess, - - # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess. - [Parameter()] - [Object[]] $NestedModules, - - # Functions to export from this module, for best performance, do not use wildcards and do not - # delete the entry, use an empty array if there are no functions to export. - [Parameter()] - [string[]] $FunctionsToExport, - - # Cmdlets to export from this module, for best performance, do not use wildcards and do not - # delete the entry, use an empty array if there are no cmdlets to export. - [Parameter()] - [string[]] $CmdletsToExport, - - # Variables to export from this module. - [Parameter()] - [string[]] $VariablesToExport, - - # Aliases to export from this module, for best performance, do not use wildcards and do not - # delete the entry, use an empty array if there are no aliases to export. - [Parameter()] - [string[]] $AliasesToExport, - - # DSC resources to export from this module. - [Parameter()] - [string[]] $DscResourcesToExport, - - # List of all modules packaged with this module. - [Parameter()] - [Object[]] $ModuleList, - - # List of all files packaged with this module. - [Parameter()] - [string[]] $FileList, - - # Tags applied to this module. These help with module discovery in online galleries. - [Parameter()] - [string[]] $Tags, - - # External dependent modules of this module. - [Parameter()] - [string[]] $ExternalModuleDependencies - ) - - $moduleManifest = Get-ModuleManifest -Path $Path - $changes = @{} - - if ($RequiredModules) { - $RequiredModules += $moduleManifest.RequiredModules - $changes.RequiredModules = $RequiredModules - } - if ($RequiredAssemblies) { - $RequiredAssemblies += $moduleManifest.RequiredAssemblies - $changes.RequiredAssemblies = $RequiredAssemblies - } - if ($CompatiblePSEditions) { - $CompatiblePSEditions += $moduleManifest.CompatiblePSEditions - $changes.CompatiblePSEditions = $CompatiblePSEditions - } - if ($ScriptsToProcess) { - $ScriptsToProcess += $moduleManifest.ScriptsToProcess - $changes.ScriptsToProcess = $ScriptsToProcess - } - if ($TypesToProcess) { - $TypesToProcess += $moduleManifest.TypesToProcess - $changes.TypesToProcess = $TypesToProcess - } - if ($FormatsToProcess) { - $FormatsToProcess += $moduleManifest.FormatsToProcess - $changes.FormatsToProcess = $FormatsToProcess - } - if ($NestedModules) { - $NestedModules += $moduleManifest.NestedModules - $changes.NestedModules = $NestedModules - } - if ($FunctionsToExport) { - $FunctionsToExport += $moduleManifest.FunctionsToExport - $changes.FunctionsToExport = $FunctionsToExport - } - if ($CmdletsToExport) { - $CmdletsToExport += $moduleManifest.CmdletsToExport - $changes.CmdletsToExport = $CmdletsToExport - } - if ($VariablesToExport) { - $VariablesToExport += $moduleManifest.VariablesToExport - $changes.VariablesToExport = $VariablesToExport - } - if ($AliasesToExport) { - $AliasesToExport += $moduleManifest.AliasesToExport - $changes.AliasesToExport = $AliasesToExport - } - if ($DscResourcesToExport) { - $DscResourcesToExport += $moduleManifest.DscResourcesToExport - $changes.DscResourcesToExport = $DscResourcesToExport - } - if ($ModuleList) { - $ModuleList += $moduleManifest.ModuleList - $changes.ModuleList = $ModuleList - } - if ($FileList) { - $FileList += $moduleManifest.FileList - $changes.FileList = $FileList - } - if ($Tags) { - $Tags += $moduleManifest.PrivateData.PSData.Tags - $changes.Tags = $Tags - } - if ($ExternalModuleDependencies) { - $ExternalModuleDependencies += $moduleManifest.PrivateData.PSData.ExternalModuleDependencies - $changes.ExternalModuleDependencies = $ExternalModuleDependencies - } - - foreach ($key in $changes.GetEnumerator().Name) { - $changes[$key] = $changes[$key] | Sort-Object -Unique | Where-Object { -not [string]::IsNullOrEmpty($_) } - } - - Set-ModuleManifest -Path $Path @changes - -} diff --git a/scripts/helpers/Build/Add-PSModulePath.ps1 b/scripts/helpers/Build/Add-PSModulePath.ps1 deleted file mode 100644 index f5abf042..00000000 --- a/scripts/helpers/Build/Add-PSModulePath.ps1 +++ /dev/null @@ -1,29 +0,0 @@ -function Add-PSModulePath { - <# - .SYNOPSIS - Adds a path to the PSModulePath environment variable. - - .DESCRIPTION - Adds a path to the PSModulePath environment variable. - For Linux and macOS, the path delimiter is ':' and for Windows it is ';'. - - .EXAMPLE - Add-PSModulePath -Path 'C:\Users\user\Documents\WindowsPowerShell\Modules' - - Adds the path 'C:\Users\user\Documents\WindowsPowerShell\Modules' to the PSModulePath environment variable. - #> - [CmdletBinding()] - param( - # Path to the folder where the module source code is located. - [Parameter(Mandatory)] - [string] $Path - ) - $PSModulePathSeparator = [System.IO.Path]::PathSeparator - - $env:PSModulePath += "$PSModulePathSeparator$Path" - - Write-Verbose 'PSModulePath:' - $env:PSModulePath.Split($PSModulePathSeparator) | ForEach-Object { - Write-Verbose " - [$_]" - } -} diff --git a/scripts/helpers/Build/Build-PSModuleManifest.ps1 b/scripts/helpers/Build/Build-PSModuleManifest.ps1 index 4cda1732..2a611f0d 100644 --- a/scripts/helpers/Build/Build-PSModuleManifest.ps1 +++ b/scripts/helpers/Build/Build-PSModuleManifest.ps1 @@ -12,6 +12,7 @@ #> [CmdletBinding()] #Requires -Modules @{ ModuleName = 'GitHub'; ModuleVersion = '0.13.2' } + #Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' } [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSAvoidLongLines', '', Scope = 'Function', Justification = 'Easier to read the multi ternery operators in a single line.' @@ -59,10 +60,10 @@ $manifest.ModuleVersion = '999.0.0' Write-Host "[ModuleVersion] - [$($manifest.ModuleVersion)]" - $manifest.Author = $manifest.Keys -contains 'Author' ? -not [string]::IsNullOrEmpty($manifest.Author) ? $manifest.Author : $env:GITHUB_REPOSITORY_OWNER : $env:GITHUB_REPOSITORY_OWNER + $manifest.Author = $manifest.Keys -contains 'Author' ? ($manifest.Author | IsNotNullOrEmpty) ? $manifest.Author : $env:GITHUB_REPOSITORY_OWNER : $env:GITHUB_REPOSITORY_OWNER Write-Host "[Author] - [$($manifest.Author)]" - $manifest.CompanyName = $manifest.Keys -contains 'CompanyName' ? -not [string]::IsNullOrEmpty($manifest.CompanyName) ? $manifest.CompanyName : $env:GITHUB_REPOSITORY_OWNER : $env:GITHUB_REPOSITORY_OWNER + $manifest.CompanyName = $manifest.Keys -contains 'CompanyName' ? ($manifest.CompanyName | IsNotNullOrEmpty) ? $manifest.CompanyName : $env:GITHUB_REPOSITORY_OWNER : $env:GITHUB_REPOSITORY_OWNER Write-Host "[CompanyName] - [$($manifest.CompanyName)]" $year = Get-Date -Format 'yyyy' @@ -72,7 +73,7 @@ Write-Host "[Copyright] - [$($manifest.Copyright)]" $repoDescription = gh repo view --json description | ConvertFrom-Json | Select-Object -ExpandProperty description - $manifest.Description = $manifest.Keys -contains 'Description' ? -not [string]::IsNullOrEmpty($manifest.Description) ? $manifest.Description : $repoDescription : $repoDescription + $manifest.Description = $manifest.Keys -contains 'Description' ? ($manifest.Description | IsNotNullOrEmpty) ? $manifest.Description : $repoDescription : $repoDescription Write-Host "[Description] - [$($manifest.Description)]" $manifest.PowerShellHostName = $manifest.Keys -contains 'PowerShellHostName' ? -not [string]::IsNullOrEmpty($manifest.PowerShellHostName) ? $manifest.PowerShellHostName : $null : $null diff --git a/scripts/helpers/Build/Export-PowerShellDataFile.ps1 b/scripts/helpers/Build/Export-PowerShellDataFile.ps1 deleted file mode 100644 index 5c5daf84..00000000 --- a/scripts/helpers/Build/Export-PowerShellDataFile.ps1 +++ /dev/null @@ -1,30 +0,0 @@ -function Export-PowerShellDataFile { - <# - .SYNOPSIS - Export a hashtable to a .psd1 file. - - .DESCRIPTION - This function exports a hashtable to a .psd1 file. It also formats the .psd1 file using the Format-ModuleManifest cmdlet. - - .EXAMPLE - Export-PowerShellDataFile -Hashtable @{ Name = 'MyModule'; ModuleVersion = '1.0.0' } -Path 'MyModule.psd1' - #> - [CmdletBinding()] - param ( - # The hashtable to export to a .psd1 file. - [Parameter(Mandatory)] - [object] $Hashtable, - - # The path of the .psd1 file to export. - [Parameter(Mandatory)] - [string] $Path, - - # Force the export, even if the file already exists. - [Parameter()] - [switch] $Force - ) - - $content = Format-Hashtable -Hashtable $Hashtable - $content | Out-File -FilePath $Path -Force:$Force - Format-ModuleManifest -Path $Path -} diff --git a/scripts/helpers/Build/Format-ModuleManifest.ps1 b/scripts/helpers/Build/Format-ModuleManifest.ps1 deleted file mode 100644 index 45e6c222..00000000 --- a/scripts/helpers/Build/Format-ModuleManifest.ps1 +++ /dev/null @@ -1,32 +0,0 @@ -function Format-ModuleManifest { - <# - .SYNOPSIS - Formats a module manifest file. - - .DESCRIPTION - This function formats a module manifest file, by removing comments and empty lines, - and then formatting the file using the `Invoke-Formatter` function. - - .EXAMPLE - Format-ModuleManifest -Path 'C:\MyModule\MyModule.psd1' - #> - [CmdletBinding()] - param( - # Path to the module manifest file. - [Parameter(Mandatory)] - [string] $Path - ) - - $Utf8BomEncoding = New-Object System.Text.UTF8Encoding $true - - $manifestContent = Get-Content -Path $Path - $manifestContent = $manifestContent | ForEach-Object { $_ -replace '#.*' } - $manifestContent = $manifestContent | ForEach-Object { $_.TrimEnd() } - $manifestContent = $manifestContent | Where-Object { -not [string]::IsNullOrEmpty($_) } - [System.IO.File]::WriteAllLines($Path, $manifestContent, $Utf8BomEncoding) - $manifestContent = Get-Content -Path $Path -Raw - - $content = Invoke-Formatter -ScriptDefinition $manifestContent - [System.IO.File]::WriteAllLines($Path, $content, $Utf8BomEncoding) - -} diff --git a/scripts/helpers/Build/Get-ModuleManifest.ps1 b/scripts/helpers/Build/Get-ModuleManifest.ps1 deleted file mode 100644 index a3afd35b..00000000 --- a/scripts/helpers/Build/Get-ModuleManifest.ps1 +++ /dev/null @@ -1,121 +0,0 @@ -function Get-ModuleManifest { - <# - .SYNOPSIS - Get the module manifest. - - .DESCRIPTION - Get the module manifest as a path, file info, content, or hashtable. - - .EXAMPLE - Get-PSModuleManifest -Path 'src/PSModule/PSModule.psd1' -As Hashtable - #> - [OutputType([string], [System.IO.FileInfo], [System.Collections.Hashtable], [System.Collections.Specialized.OrderedDictionary])] - [CmdletBinding()] - param( - # Path to the module manifest file. - [Parameter(Mandatory)] - [string] $Path, - - # The format of the output. - [Parameter()] - [ValidateSet('FileInfo', 'Content', 'Hashtable')] - [string] $As = 'Hashtable' - ) - - if (-not (Test-Path -Path $Path)) { - Write-Warning 'No manifest file found.' - return $null - } - Write-Verbose "Found manifest file [$Path]" - - switch ($As) { - 'FileInfo' { - return Get-Item -Path $Path - } - 'Content' { - return Get-Content -Path $Path - } - 'Hashtable' { - $manifest = [System.Collections.Specialized.OrderedDictionary]@{} - $psData = [System.Collections.Specialized.OrderedDictionary]@{} - $privateData = [System.Collections.Specialized.OrderedDictionary]@{} - $tempManifest = Import-PowerShellDataFile -Path $Path - if ($tempManifest.ContainsKey('PrivateData')) { - $tempPrivateData = $tempManifest.PrivateData - if ($tempPrivateData.ContainsKey('PSData')) { - $tempPSData = $tempPrivateData.PSData - $tempPrivateData.Remove('PSData') - } - } - - $psdataOrder = @( - 'Tags' - 'LicenseUri' - 'ProjectUri' - 'IconUri' - 'ReleaseNotes' - 'Prerelease' - 'RequireLicenseAcceptance' - 'ExternalModuleDependencies' - ) - foreach ($key in $psdataOrder) { - if (($null -ne $tempPSData) -and ($tempPSData.ContainsKey($key))) { - $psData.$key = $tempPSData.$key - } - } - if ($psData.Count -gt 0) { - $privateData.PSData = $psData - } else { - $privateData.Remove('PSData') - } - foreach ($key in $tempPrivateData.Keys) { - $privateData.$key = $tempPrivateData.$key - } - - $manifestOrder = @( - 'RootModule' - 'ModuleVersion' - 'CompatiblePSEditions' - 'GUID' - 'Author' - 'CompanyName' - 'Copyright' - 'Description' - 'PowerShellVersion' - 'PowerShellHostName' - 'PowerShellHostVersion' - 'DotNetFrameworkVersion' - 'ClrVersion' - 'ProcessorArchitecture' - 'RequiredModules' - 'RequiredAssemblies' - 'ScriptsToProcess' - 'TypesToProcess' - 'FormatsToProcess' - 'NestedModules' - 'FunctionsToExport' - 'CmdletsToExport' - 'VariablesToExport' - 'AliasesToExport' - 'DscResourcesToExport' - 'ModuleList' - 'FileList' - 'HelpInfoURI' - 'DefaultCommandPrefix' - 'PrivateData' - ) - foreach ($key in $manifestOrder) { - if ($tempManifest.ContainsKey($key)) { - $manifest.$key = $tempManifest.$key - } - } - if ($privateData.Count -gt 0) { - $manifest.PrivateData = $privateData - } else { - $manifest.Remove('PrivateData') - } - - return $manifest - } - } -} diff --git a/scripts/helpers/Build/Get-PSModuleAliasesToExport.ps1 b/scripts/helpers/Build/Get-PSModuleAliasesToExport.ps1 index d2a24d43..5c8a990e 100644 --- a/scripts/helpers/Build/Get-PSModuleAliasesToExport.ps1 +++ b/scripts/helpers/Build/Get-PSModuleAliasesToExport.ps1 @@ -10,6 +10,7 @@ Get-PSModuleAliasesToExport -SourceFolderPath 'C:\MyModule\src\MyModule' #> [CmdletBinding()] + #Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' } [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSAvoidUsingWriteHost', '', Scope = 'Function', Justification = 'Want to just write to the console, not the pipeline.' @@ -29,8 +30,7 @@ $manifest = Get-ModuleManifest -Path $manifestFilePath -Verbose:$false Write-Host "[$manifestPropertyName]" - $aliasesToExport = (($manifest.AliasesToExport).count -eq 0) -or [string]::IsNullOrEmpty($manifest.AliasesToExport) ? - '*' : $manifest.AliasesToExport + $aliasesToExport = (($manifest.AliasesToExport).count -eq 0) -or ($manifest.AliasesToExport | IsNullOrEmpty) ? '*' : $manifest.AliasesToExport $aliasesToExport | ForEach-Object { Write-Host "[$manifestPropertyName] - [$_]" } diff --git a/scripts/helpers/Build/Get-PSModuleCmdletsToExport.ps1 b/scripts/helpers/Build/Get-PSModuleCmdletsToExport.ps1 index a7968581..2e07f8c3 100644 --- a/scripts/helpers/Build/Get-PSModuleCmdletsToExport.ps1 +++ b/scripts/helpers/Build/Get-PSModuleCmdletsToExport.ps1 @@ -10,6 +10,7 @@ Get-PSModuleCmdletsToExport -SourceFolderPath 'C:\MyModule\src\MyModule' #> [CmdletBinding()] + #Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' } [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSAvoidUsingWriteHost', '', Scope = 'Function', Justification = 'Want to just write to the console, not the pipeline.' @@ -29,8 +30,7 @@ $manifest = Get-ModuleManifest -Path $manifestFilePath -Verbose:$false Write-Host "[$manifestPropertyName]" - $cmdletsToExport = (($manifest.CmdletsToExport).count -eq 0) -or [string]::IsNullOrEmpty($manifest.CmdletsToExport) ? - '' : $manifest.CmdletsToExport + $cmdletsToExport = (($manifest.CmdletsToExport).count -eq 0) -or ($manifest.CmdletsToExport | IsNullOrEmpty) ? '' : $manifest.CmdletsToExport $cmdletsToExport | ForEach-Object { Write-Host "[$manifestPropertyName] - [$_]" } diff --git a/scripts/helpers/Build/Import-PSModule.ps1 b/scripts/helpers/Build/Import-PSModule.ps1 index 7db7ca93..79fa949a 100644 --- a/scripts/helpers/Build/Import-PSModule.ps1 +++ b/scripts/helpers/Build/Import-PSModule.ps1 @@ -16,6 +16,7 @@ 'PSAvoidUsingWriteHost', '', Scope = 'Function', Justification = 'Want to just write to the console, not the pipeline.' )] + #Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' } param( # Path to the folder where the module source code is located. [Parameter(Mandatory)] diff --git a/scripts/helpers/Build/Set-ModuleManifest.ps1 b/scripts/helpers/Build/Set-ModuleManifest.ps1 deleted file mode 100644 index 558857af..00000000 --- a/scripts/helpers/Build/Set-ModuleManifest.ps1 +++ /dev/null @@ -1,325 +0,0 @@ -filter Set-ModuleManifest { - <# - .SYNOPSIS - Sets the values of a module manifest file. - - .DESCRIPTION - This function sets the values of a module manifest file. - Very much like the Update-ModuleManifest function, but allows values to be missing. - - .EXAMPLE - Set-ModuleManifest -Path 'C:\MyModule\MyModule.psd1' -ModuleVersion '1.0.0' - #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSUseShouldProcessForStateChangingFunctions', '', - Justification = 'Function does not change state.' - )] - [CmdletBinding()] - param( - # Path to the module manifest file. - [Parameter( - Mandatory, - ValueFromPipeline, - ValueFromPipelineByPropertyName - )] - [string] $Path, - - #Script module or binary module file associated with this manifest. - [Parameter()] - [AllowNull()] - [string] $RootModule, - - #Version number of this module. - [Parameter()] - [AllowNull()] - [Version] $ModuleVersion, - - # Supported PSEditions. - [Parameter()] - [AllowNull()] - [string[]] $CompatiblePSEditions, - - # ID used to uniquely identify this module. - [Parameter()] - [AllowNull()] - [guid] $GUID, - - # Author of this module. - [Parameter()] - [AllowNull()] - [string] $Author, - - # Company or vendor of this module. - [Parameter()] - [AllowNull()] - [string] $CompanyName, - - # Copyright statement for this module. - [Parameter()] - [AllowNull()] - [string] $Copyright, - - # Description of the functionality provided by this module. - [Parameter()] - [AllowNull()] - [string] $Description, - - # Minimum version of the PowerShell engine required by this module. - [Parameter()] - [AllowNull()] - [Version] $PowerShellVersion, - - # Name of the PowerShell host required by this module. - [Parameter()] - [AllowNull()] - [string] $PowerShellHostName, - - # Minimum version of the PowerShell host required by this module. - [Parameter()] - [AllowNull()] - [version] $PowerShellHostVersion, - - # Minimum version of Microsoft .NET Framework required by this module. - # This prerequisite is valid for the PowerShell Desktop edition only. - [Parameter()] - [AllowNull()] - [Version] $DotNetFrameworkVersion, - - # Minimum version of the common language runtime (CLR) required by this module. - # This prerequisite is valid for the PowerShell Desktop edition only. - [Parameter()] - [AllowNull()] - [Version] $ClrVersion, - - # Processor architecture (None,X86, Amd64) required by this module - [Parameter()] - [AllowNull()] - [System.Reflection.ProcessorArchitecture] $ProcessorArchitecture, - - # Modules that must be imported into the global environment prior to importing this module. - [Parameter()] - [AllowNull()] - [Object[]] $RequiredModules, - - # Assemblies that must be loaded prior to importing this module. - [Parameter()] - [AllowNull()] - [string[]] $RequiredAssemblies, - - # Script files (.ps1) that are run in the caller's environment prior to importing this module. - [Parameter()] - [AllowNull()] - [string[]] $ScriptsToProcess, - - # Type files (.ps1xml) to be loaded when importing this module. - [Parameter()] - [AllowNull()] - [string[]] $TypesToProcess, - - # Format files (.ps1xml) to be loaded when importing this module. - [Parameter()] - [AllowNull()] - [string[]] $FormatsToProcess, - - # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess. - [Parameter()] - [AllowNull()] - [Object[]] $NestedModules, - - # Functions to export from this module, for best performance, do not use wildcards and do not - # delete the entry, use an empty array if there are no functions to export. - [Parameter()] - [AllowNull()] - [string[]] $FunctionsToExport, - - # Cmdlets to export from this module, for best performance, do not use wildcards and do not - # delete the entry, use an empty array if there are no cmdlets to export. - [Parameter()] - [AllowNull()] - [string[]] $CmdletsToExport, - - # Variables to export from this module. - [Parameter()] - [AllowNull()] - [string[]] $VariablesToExport, - - # Aliases to export from this module, for best performance, do not use wildcards and do not - # delete the entry, use an empty array if there are no aliases to export. - [Parameter()] - [AllowNull()] - [string[]] $AliasesToExport, - - # DSC resources to export from this module. - [Parameter()] - [AllowNull()] - [string[]] $DscResourcesToExport, - - # List of all modules packaged with this module. - [Parameter()] - [AllowNull()] - [Object[]] $ModuleList, - - # List of all files packaged with this module. - [Parameter()] - [AllowNull()] - [string[]] $FileList, - - # Tags applied to this module. These help with module discovery in online galleries. - [Parameter()] - [AllowNull()] - [string[]] $Tags, - - # A URL to the license for this module. - [Parameter()] - [AllowNull()] - [uri] $LicenseUri, - - # A URL to the main site for this project. - [Parameter()] - [AllowNull()] - [uri] $ProjectUri, - - # A URL to an icon representing this module. - [Parameter()] - [AllowNull()] - [uri] $IconUri, - - # ReleaseNotes of this module. - [Parameter()] - [AllowNull()] - [string] $ReleaseNotes, - - # Prerelease string of this module. - [Parameter()] - [AllowNull()] - [string] $Prerelease, - - # Flag to indicate whether the module requires explicit user acceptance for install/update/save. - [Parameter()] - [AllowNull()] - [bool] $RequireLicenseAcceptance, - - # External dependent modules of this module. - [Parameter()] - [AllowNull()] - [string[]] $ExternalModuleDependencies, - - # HelpInfo URI of this module. - [Parameter()] - [AllowNull()] - [String] $HelpInfoURI, - - # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. - [Parameter()] - [AllowNull()] - [string] $DefaultCommandPrefix, - - # Private data to pass to the module specified in RootModule/ModuleToProcess. - # This may also contain a PSData hashtable with additional module metadata used by PowerShell. - [Parameter()] - [AllowNull()] - [object] $PrivateData - ) - - $outManifest = [ordered]@{} - $outPSData = [ordered]@{} - $outPrivateData = [ordered]@{} - - $tempManifest = Get-ModuleManifest -Path $Path - if ($tempManifest.Keys.Contains('PrivateData')) { - $tempPrivateData = $tempManifest.PrivateData - if ($tempPrivateData.Keys.Contains('PSData')) { - $tempPSData = $tempPrivateData.PSData - $tempPrivateData.Remove('PSData') - } - } - - $psdataOrder = @( - 'Tags' - 'LicenseUri' - 'ProjectUri' - 'IconUri' - 'ReleaseNotes' - 'Prerelease' - 'RequireLicenseAcceptance' - 'ExternalModuleDependencies' - ) - foreach ($key in $psdataOrder) { - if (($null -ne $tempPSData) -and $tempPSData.Keys.Contains($key)) { - $outPSData[$key] = $tempPSData[$key] - } - if ($PSBoundParameters.Keys.Contains($key)) { - if ($null -eq $PSBoundParameters[$key]) { - $outPSData.Remove($key) - } else { - $outPSData[$key] = $PSBoundParameters[$key] - } - } - } - - if ($outPSData.Count -gt 0) { - $outPrivateData.PSData = $outPSData - } else { - $outPrivateData.Remove('PSData') - } - foreach ($key in $tempPrivateData.Keys) { - $outPrivateData[$key] = $tempPrivateData[$key] - } - foreach ($key in $PrivateData.Keys) { - $outPrivateData[$key] = $PrivateData[$key] - } - - $manifestOrder = @( - 'RootModule' - 'ModuleVersion' - 'CompatiblePSEditions' - 'GUID' - 'Author' - 'CompanyName' - 'Copyright' - 'Description' - 'PowerShellVersion' - 'PowerShellHostName' - 'PowerShellHostVersion' - 'DotNetFrameworkVersion' - 'ClrVersion' - 'ProcessorArchitecture' - 'RequiredModules' - 'RequiredAssemblies' - 'ScriptsToProcess' - 'TypesToProcess' - 'FormatsToProcess' - 'NestedModules' - 'FunctionsToExport' - 'CmdletsToExport' - 'VariablesToExport' - 'AliasesToExport' - 'DscResourcesToExport' - 'ModuleList' - 'FileList' - 'HelpInfoURI' - 'DefaultCommandPrefix' - 'PrivateData' - ) - foreach ($key in $manifestOrder) { - if ($tempManifest.Keys.Contains($key)) { - $outManifest[$key] = $tempManifest[$key] - } - if ($PSBoundParameters.Keys.Contains($key)) { - if ($null -eq $PSBoundParameters[$key]) { - $outManifest.Remove($key) - } else { - $outManifest[$key] = $PSBoundParameters[$key] - } - } - } - if ($outPrivateData.Count -gt 0) { - $outManifest['PrivateData'] = $outPrivateData - } else { - $outManifest.Remove('PrivateData') - } - - Remove-Item -Path $Path -Force - Export-PowerShellDataFile -Hashtable $outManifest -Path $Path - -} diff --git a/scripts/helpers/Build/Show-FileContent.ps1 b/scripts/helpers/Build/Show-FileContent.ps1 deleted file mode 100644 index 6ad62955..00000000 --- a/scripts/helpers/Build/Show-FileContent.ps1 +++ /dev/null @@ -1,32 +0,0 @@ -function Show-FileContent { - <# - .SYNOPSIS - Prints the content of a file with line numbers in front of each line. - - .DESCRIPTION - Prints the content of a file with line numbers in front of each line. - - .EXAMPLE - $Path = 'C:\Utilities\Show-FileContent.ps1' - Show-FileContent -Path $Path - - Shows the content of the file with line numbers in front of each line. - #> - [CmdletBinding()] - param ( - # The path to the file to show the content of. - [Parameter(Mandatory)] - [string] $Path - ) - - $content = Get-Content -Path $Path - $lineNumber = 1 - $columnSize = $content.Count.ToString().Length - # Foreach line print the line number in front of the line with [ ] around it. - # The linenumber should dynamically adjust to the number of digits with the length of the file. - foreach ($line in $content) { - $lineNumberFormatted = $lineNumber.ToString().PadLeft($columnSize) - Write-Host "[$lineNumberFormatted] $line" - $lineNumber++ - } -} diff --git a/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 b/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 index 1fc6d973..47d64e45 100644 --- a/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 +++ b/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 @@ -16,6 +16,7 @@ Justification = 'Want to just write to the console, not the pipeline.' )] #Requires -Modules @{ ModuleName = 'GitHub'; ModuleVersion = '0.13.2' } + #Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' } [CmdletBinding()] param( # Name of the module. diff --git a/scripts/main.ps1 b/scripts/main.ps1 index a1bb616a..d831ebef 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -5,6 +5,8 @@ [CmdletBinding()] param() +#Requires -Modules Utilities + $path = (Join-Path -Path $PSScriptRoot -ChildPath 'helpers') | Get-Item | Resolve-Path -Relative LogGroup "Loading helper scripts from [$path]" { Get-ChildItem -Path $path -Filter '*.ps1' -Recurse | Resolve-Path -Relative | ForEach-Object { @@ -14,7 +16,7 @@ LogGroup "Loading helper scripts from [$path]" { } LogGroup 'Loading inputs' { - $moduleName = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Name) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_Name + $moduleName = ($env:GITHUB_ACTION_INPUT_Name | IsNullOrEmpty) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_Name Write-Host "Module name: [$moduleName]" $moduleSourceFolderPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath $env:GITHUB_ACTION_INPUT_Path/$moduleName From 8cccec4772c0a5074485cfea87149a156f23742f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 17 Apr 2025 15:43:22 +0200 Subject: [PATCH 4/8] =?UTF-8?q?=F0=9F=8C=9F=20[Major]:=20Standalone=20Modu?= =?UTF-8?q?le=20Builder=20with=20isolation=20(#108)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description This PR refactors **Build-PSModule** into a standalone, reusable action focused solely on building and packaging PowerShell modules. It simplifies inputs/outputs, improves script reliability, and removes deprecated logic. This aligns with recent changes in **Process-PSModule** (see [PR #150](https://github.com/PSModule/Process-PSModule/pull/150)) that shift orchestration responsibilities out of Build-PSModule. ## Why Previously, Build-PSModule handled some orchestration logic (e.g., naming, path assumptions), tightly coupling it to specific CI setups. This update makes it a pure builder, allowing workflows like Process-PSModule to fully own orchestration and testing. ## Key Changes - New inputs: - `ArtifactName` (custom name for upload) - `WorkingDirectory` (controls source/build path) - New output: - `moduleOutputFolderPath` (used for artifact upload and downstream steps) - Upload step: Now dynamically uses the output path instead of hardcoded ones. - Improved helper scripts: - Better error handling - Simpler, more robust logic - Removed legacy scripts and inputs ## Impact - Workflows now get a clean contract: provide source path → get built module path. - Build-PSModule no longer makes assumptions about structure or downstream steps. - Enables more modular, flexible workflows (like the new Process-PSModule pipeline). --- Let me know if you'd like an even more minimal or changelog-style version! ## Type of change - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [x] 🌟 [Breaking change] ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas --- .github/workflows/Action-Test.yml | 14 ++-- .github/workflows/Auto-Release.yml | 2 - README.md | 20 ++--- action.yml | 31 ++++---- scripts/helpers/Build-PSModule.ps1 | 19 ++--- scripts/helpers/Build/Build-PSModuleBase.ps1 | 10 ++- .../helpers/Build/Build-PSModuleManifest.ps1 | 5 +- .../Build/Build-PSModuleRootModule.ps1 | 37 ++++++--- scripts/helpers/Build/ConvertTo-Hashtable.ps1 | 32 -------- scripts/helpers/Build/Import-PSModule.ps1 | 53 ------------- .../Build/Resolve-PSModuleDependency.ps1 | 67 ----------------- ...Update-PSModuleManifestAliasesToExport.ps1 | 70 ++++++++++++++++-- scripts/main.ps1 | 37 ++++----- .../functions/public/Test-PSModuleTest.ps1 | 0 .../src/assemblies/LsonLib.dll | Bin .../src/classes/private/SecretWriter.ps1 | 0 .../src/classes/public/Book.ps1 | 0 tests/{ => srcTestRepo}/src/data/Config.psd1 | 0 .../{ => srcTestRepo}/src/data/Settings.psd1 | 0 tests/{ => srcTestRepo}/src/finally.ps1 | 0 .../src/formats/CultureInfo.Format.ps1xml | 0 .../src/formats/Mygciview.Format.ps1xml | 0 .../private/Get-InternalPSModule.ps1 | 0 .../private/Set-InternalPSModule.ps1 | 0 .../public/PSModule/Get-PSModuleTest.ps1 | 2 +- .../public/PSModule/New-PSModuleTest.ps1 | 0 .../src/functions/public/PSModule/PSModule.md | 0 .../public/SomethingElse/Set-PSModuleTest.ps1 | 0 .../public/SomethingElse/SomethingElse.md | 0 .../functions/public/Test-PSModuleTest.ps1 | 0 tests/{ => srcTestRepo}/src/header.ps1 | 0 .../src/init/initializer.ps1 | 0 .../src/modules/OtherPSModule.psm1 | 0 .../{ => srcTestRepo}/src/scripts/loader.ps1 | 0 .../src/types/DirectoryInfo.Types.ps1xml | 0 .../src/types/FileInfo.Types.ps1xml | 0 .../variables/private/PrivateVariables.ps1 | 0 .../src/variables/public/Moons.ps1 | 0 .../src/variables/public/Planets.ps1 | 0 .../src/variables/public/SolarSystems.ps1 | 0 .../src}/assemblies/LsonLib.dll | Bin .../src}/data/Config.psd1 | 0 .../src}/data/Settings.psd1 | 0 .../src}/finally.ps1 | 0 .../src}/formats/CultureInfo.Format.ps1xml | 0 .../src}/formats/Mygciview.Format.ps1xml | 0 .../private/Get-InternalPSModule.ps1 | 0 .../private/Set-InternalPSModule.ps1 | 0 .../public/PSModule/Get-PSModuleTest.ps1 | 2 +- .../public/PSModule/New-PSModuleTest.ps1 | 0 .../functions/public/PSModule/PSModule.md | 0 .../public/SomethingElse/Set-PSModuleTest.ps1 | 0 .../public/SomethingElse/SomethingElse.md | 0 .../functions/public/Test-PSModuleTest.ps1 | 0 .../src}/header.ps1 | 0 .../src}/init/initializer.ps1 | 0 .../src}/manifest.psd1 | 0 .../src}/modules/OtherPSModule.psm1 | 0 .../src}/scripts/loader.ps1 | 0 .../src}/types/DirectoryInfo.Types.ps1xml | 0 .../src}/types/FileInfo.Types.ps1xml | 0 .../variables/private/PrivateVariables.ps1 | 0 .../src}/variables/public/Moons.ps1 | 0 .../src}/variables/public/Planets.ps1 | 0 .../src}/variables/public/SolarSystems.ps1 | 0 65 files changed, 159 insertions(+), 242 deletions(-) delete mode 100644 scripts/helpers/Build/ConvertTo-Hashtable.ps1 delete mode 100644 scripts/helpers/Build/Import-PSModule.ps1 delete mode 100644 scripts/helpers/Build/Resolve-PSModuleDependency.ps1 rename tests/{ => srcMinimalTestRepo}/src/functions/public/Test-PSModuleTest.ps1 (100%) rename tests/{ => srcTestRepo}/src/assemblies/LsonLib.dll (100%) rename tests/{ => srcTestRepo}/src/classes/private/SecretWriter.ps1 (100%) rename tests/{ => srcTestRepo}/src/classes/public/Book.ps1 (100%) rename tests/{ => srcTestRepo}/src/data/Config.psd1 (100%) rename tests/{ => srcTestRepo}/src/data/Settings.psd1 (100%) rename tests/{ => srcTestRepo}/src/finally.ps1 (100%) rename tests/{ => srcTestRepo}/src/formats/CultureInfo.Format.ps1xml (100%) rename tests/{ => srcTestRepo}/src/formats/Mygciview.Format.ps1xml (100%) rename tests/{ => srcTestRepo}/src/functions/private/Get-InternalPSModule.ps1 (100%) rename tests/{ => srcTestRepo}/src/functions/private/Set-InternalPSModule.ps1 (100%) rename tests/{srcWithManifest => srcTestRepo/src}/functions/public/PSModule/Get-PSModuleTest.ps1 (97%) rename tests/{ => srcTestRepo}/src/functions/public/PSModule/New-PSModuleTest.ps1 (100%) rename tests/{ => srcTestRepo}/src/functions/public/PSModule/PSModule.md (100%) rename tests/{ => srcTestRepo}/src/functions/public/SomethingElse/Set-PSModuleTest.ps1 (100%) rename tests/{ => srcTestRepo}/src/functions/public/SomethingElse/SomethingElse.md (100%) rename tests/{srcMinimal => srcTestRepo/src}/functions/public/Test-PSModuleTest.ps1 (100%) rename tests/{ => srcTestRepo}/src/header.ps1 (100%) rename tests/{ => srcTestRepo}/src/init/initializer.ps1 (100%) rename tests/{ => srcTestRepo}/src/modules/OtherPSModule.psm1 (100%) rename tests/{ => srcTestRepo}/src/scripts/loader.ps1 (100%) rename tests/{ => srcTestRepo}/src/types/DirectoryInfo.Types.ps1xml (100%) rename tests/{ => srcTestRepo}/src/types/FileInfo.Types.ps1xml (100%) rename tests/{ => srcTestRepo}/src/variables/private/PrivateVariables.ps1 (100%) rename tests/{ => srcTestRepo}/src/variables/public/Moons.ps1 (100%) rename tests/{ => srcTestRepo}/src/variables/public/Planets.ps1 (100%) rename tests/{ => srcTestRepo}/src/variables/public/SolarSystems.ps1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/assemblies/LsonLib.dll (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/data/Config.psd1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/data/Settings.psd1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/finally.ps1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/formats/CultureInfo.Format.ps1xml (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/formats/Mygciview.Format.ps1xml (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/functions/private/Get-InternalPSModule.ps1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/functions/private/Set-InternalPSModule.ps1 (100%) rename tests/{ => srcWithManifestTestRepo}/src/functions/public/PSModule/Get-PSModuleTest.ps1 (85%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/functions/public/PSModule/New-PSModuleTest.ps1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/functions/public/PSModule/PSModule.md (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/functions/public/SomethingElse/Set-PSModuleTest.ps1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/functions/public/SomethingElse/SomethingElse.md (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/functions/public/Test-PSModuleTest.ps1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/header.ps1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/init/initializer.ps1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/manifest.psd1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/modules/OtherPSModule.psm1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/scripts/loader.ps1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/types/DirectoryInfo.Types.ps1xml (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/types/FileInfo.Types.ps1xml (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/variables/private/PrivateVariables.ps1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/variables/public/Moons.ps1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/variables/public/Planets.ps1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/variables/public/SolarSystems.ps1 (100%) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index cba9f20d..a334e868 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -32,8 +32,8 @@ jobs: uses: ./ with: Name: PSModuleTest - Path: tests/src - ModulesOutputPath: tests/outputs/modules + ArtifactName: PSModuleTestDefault + WorkingDirectory: tests/srcTestRepo ActionTestMinimal: name: Action-Test - [Minimal] @@ -49,9 +49,8 @@ jobs: uses: ./ with: Name: PSModuleTest - Path: tests/srcMinimal - ModulesOutputPath: tests/outputs/modules - ModuleArtifactName: moduleMinimal + ArtifactName: PSModuleTestMinimal + WorkingDirectory: tests/srcMinimalTestRepo ActionTestWithManifest: name: Action-Test - [DefaultWithManifest] @@ -67,6 +66,5 @@ jobs: uses: ./ with: Name: PSModuleTest - Path: tests/srcWithManifest - ModulesOutputPath: tests/outputs/modules - ModuleArtifactName: moduleWithManifest + ArtifactName: PSModuleTestWithManifest + WorkingDirectory: tests/srcWithManifestTestRepo diff --git a/.github/workflows/Auto-Release.yml b/.github/workflows/Auto-Release.yml index ec157c9d..680da5c0 100644 --- a/.github/workflows/Auto-Release.yml +++ b/.github/workflows/Auto-Release.yml @@ -30,7 +30,5 @@ jobs: - name: Auto-Release uses: PSModule/Auto-Release@v1 - env: - GITHUB_TOKEN: ${{ github.token }} # Used for GitHub CLI authentication with: IncrementalPrerelease: false diff --git a/README.md b/README.md index a5043243..a43ce3f1 100644 --- a/README.md +++ b/README.md @@ -25,16 +25,16 @@ This step lets you add custom build logic to process or modify the module conten ## Usage -| Name | Description | Required | Default | -| ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ----------------- | -| `Name` | Name of the module to process. | `false` | | -| `Path` | Path to the folder where the modules are located. | `false` | `src` | -| `ModulesOutputPath` | Path to the folder where the built modules are outputted. | `false` | `outputs/modules` | -| `ModuleArtifactName` | Name of the module artifact to upload. | `false` | `module` | -| `Debug` | Enable debug output. | `false` | `'false'` | -| `Verbose` | Enable verbose output. | `false` | `'false'` | -| `Version` | Specifies the version of the GitHub module to be installed. The value must be an exact version. | `false` | | -| `Prerelease` | Allow prerelease versions if available. | `false` | `'false'` | +| Name | Description | Required | Default | +| --------------------| ----------------------------------------------------------------------------------------------- | -------- | ----------------- | +| `Name` | Name of the module to process. | `false` | | +| `Path` | Path to the folder where the modules are located. | `false` | `src` | +| `ModulesOutputPath` | Path to the folder where the built modules are outputted. | `false` | `outputs/modules` | +| `Debug` | Enable debug output. | `false` | `'false'` | +| `Verbose` | Enable verbose output. | `false` | `'false'` | +| `Version` | Specifies the version of the GitHub module to be installed. The value must be an exact version. | `false` | | +| `Prerelease` | Allow prerelease versions if available. | `false` | `'false'` | +| `WorkingDirectory` | The working directory where the script runs. | `false` | `'.'` | ## Root module diff --git a/action.yml b/action.yml index cb7314ca..62ee0287 100644 --- a/action.yml +++ b/action.yml @@ -9,16 +9,8 @@ inputs: Name: description: Name of the module to process. required: false - Path: - description: Path to the folder where the modules are located. - required: false - default: src - ModulesOutputPath: - description: Path to the folder where the built modules are outputted. - required: false - default: outputs/modules - ModuleArtifactName: - description: Name of the module artifact to upload. + ArtifactName: + description: Name of the artifact to upload. required: false default: module Debug: @@ -36,29 +28,36 @@ inputs: description: Allow prerelease versions if available. required: false default: 'false' + WorkingDirectory: + description: The working directory where the script will run from. + required: false + default: '.' runs: using: composite steps: + - name: Install-PSModuleHelpers + uses: PSModule/Install-PSModuleHelpers@v1 + - name: Run Build-PSModule uses: PSModule/GitHub-Script@v1 + id: build env: - GITHUB_ACTION_INPUT_Name: ${{ inputs.Name }} - GITHUB_ACTION_INPUT_Path: ${{ inputs.Path }} - GITHUB_ACTION_INPUT_ModulesOutputPath: ${{ inputs.ModulesOutputPath }} + PSMODULE_BUILD_PSMODULE_INPUT_Name: ${{ inputs.Name }} with: Debug: ${{ inputs.Debug }} Prerelease: ${{ inputs.Prerelease }} Verbose: ${{ inputs.Verbose }} Version: ${{ inputs.Version }} + WorkingDirectory: ${{ inputs.WorkingDirectory }} Script: | # Build-PSModule - ${{ github.action_path }}\scripts\main.ps1 + ${{ github.action_path }}/scripts/main.ps1 - name: Upload module artifact uses: actions/upload-artifact@v4 with: - name: ${{ inputs.ModuleArtifactName }} - path: ${{ inputs.ModulesOutputPath }} + name: ${{ inputs.ArtifactName }} + path: ${{ fromJson(steps.build.outputs.result).moduleOutputFolderPath }} if-no-files-found: error retention-days: 1 diff --git a/scripts/helpers/Build-PSModule.ps1 b/scripts/helpers/Build-PSModule.ps1 index ef5c67cb..ea854597 100644 --- a/scripts/helpers/Build-PSModule.ps1 +++ b/scripts/helpers/Build-PSModule.ps1 @@ -6,6 +6,7 @@ .DESCRIPTION Builds a module. #> + [OutputType([void])] [CmdletBinding()] #Requires -Modules @{ ModuleName = 'GitHub'; ModuleVersion = '0.13.2' } #Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' } @@ -28,26 +29,22 @@ # Path to the folder where the built modules are outputted. [Parameter(Mandatory)] - [string] $ModulesOutputFolderPath + [string] $ModuleOutputFolderPath ) LogGroup "Building module [$ModuleName]" { - 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-Host "Module source folder: [$moduleSourceFolder]" - - $moduleOutputFolder = New-Item -Path $ModulesOutputFolderPath -Name $ModuleName -ItemType Directory -Force - Write-Host "Module output folder: [$moduleOutputFolder]" + $moduleOutputFolder = New-Item -Path $ModuleOutputFolderPath -Name $ModuleName -ItemType Directory -Force + [pscustomobject]@{ + ModuleSourceFolderPath = $moduleSourceFolder + ModuleOutputFolderPath = $moduleOutputFolder + } | Format-List | Out-String } Build-PSModuleBase -ModuleName $ModuleName -ModuleSourceFolder $moduleSourceFolder -ModuleOutputFolder $moduleOutputFolder Build-PSModuleManifest -ModuleName $ModuleName -ModuleOutputFolder $moduleOutputFolder Build-PSModuleRootModule -ModuleName $ModuleName -ModuleOutputFolder $moduleOutputFolder - Update-PSModuleManifestAliasesToExport -ModuleName $ModuleName -ModuleOutputFolder $moduleOutputFolder + Update-PSModuleManifestAliasesToExport -ModuleName $ModuleName -ModuleSourceFolder $moduleSourceFolder -ModuleOutputFolder $moduleOutputFolder LogGroup 'Build manifest file - Final Result' { $outputManifestPath = Join-Path -Path $ModuleOutputFolder -ChildPath "$ModuleName.psd1" diff --git a/scripts/helpers/Build/Build-PSModuleBase.ps1 b/scripts/helpers/Build/Build-PSModuleBase.ps1 index ffb664dd..a0b2c3db 100644 --- a/scripts/helpers/Build/Build-PSModuleBase.ps1 +++ b/scripts/helpers/Build/Build-PSModuleBase.ps1 @@ -35,12 +35,14 @@ ) LogGroup 'Build base' { - 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 + $relModuleSourceFolder = $ModuleSourceFolder | Resolve-Path -Relative + $relModuleOutputFolder = $ModuleOutputFolder | Resolve-Path -Relative + Write-Host "Copying files from [$relModuleSourceFolder] to [$relModuleOutputFolder]" + Copy-Item -Path "$ModuleSourceFolder\*" -Destination $ModuleOutputFolder -Recurse -Force -Exclude "$ModuleName.psm1" + $null = New-Item -Path $ModuleOutputFolder -Name "$ModuleName.psm1" -ItemType File -Force } LogGroup 'Build base - Result' { - (Get-ChildItem -Path $ModuleOutputFolder -Recurse -Force).FullName | Sort-Object + Get-ChildItem -Path $ModuleOutputFolder -Recurse -Force | Resolve-Path -Relative | Sort-Object } } diff --git a/scripts/helpers/Build/Build-PSModuleManifest.ps1 b/scripts/helpers/Build/Build-PSModuleManifest.ps1 index 2a611f0d..62260198 100644 --- a/scripts/helpers/Build/Build-PSModuleManifest.ps1 +++ b/scripts/helpers/Build/Build-PSModuleManifest.ps1 @@ -363,6 +363,7 @@ $manifestTags = [System.Collections.Generic.List[string]]::new() $tags = $PSData.Keys -contains 'Tags' ? ($PSData.Tags).Count -gt 0 ? $PSData.Tags : $repoLabels : $repoLabels $tags | ForEach-Object { $manifestTags.Add($_) } + 'Windows', 'Linux', 'MacOS' | ForEach-Object { $manifestTags.Add($_) } # Add tags for compatability mode. https://docs.microsoft.com/en-us/powershell/scripting/developer/module/how-to-write-a-powershell-module-manifest?view=powershell-7.1#compatibility-tags if ($manifest.CompatiblePSEditions -contains 'Desktop') { if ($manifestTags -notcontains 'PSEdition_Desktop') { @@ -448,7 +449,7 @@ } LogGroup 'Build manifest file - Format' { - Set-ModuleManifest -Path $outputManifestPath -Verbose + Set-ModuleManifest -Path $outputManifestPath } LogGroup 'Build manifest file - Result - After format' { @@ -460,6 +461,6 @@ } LogGroup 'Build manifest file - Validate - Test manifest file' { - Test-ModuleManifest -Path $outputManifestPath + Test-ModuleManifest -Path $outputManifestPath | Format-List | Out-String } } diff --git a/scripts/helpers/Build/Build-PSModuleRootModule.ps1 b/scripts/helpers/Build/Build-PSModuleRootModule.ps1 index a388e673..adef93a7 100644 --- a/scripts/helpers/Build/Build-PSModuleRootModule.ps1 +++ b/scripts/helpers/Build/Build-PSModuleRootModule.ps1 @@ -115,7 +115,7 @@ foreach ($Type in $ExportableClasses) { # Remove type accelerators when the module is removed. $MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = { foreach ($Type in ($ExportableEnums + $ExportableClasses)) { - $TypeAcceleratorsClass::Remove($Type.FullName) + $null = $TypeAcceleratorsClass::Remove($Type.FullName) } }.GetNewClosure() #endregion Class exporter @@ -130,10 +130,21 @@ $MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = { $exports.Add('Function', (Get-PSModuleFunctionsToExport -SourceFolderPath $ModuleOutputFolder)) $exports.Add('Variable', (Get-PSModuleVariablesToExport -SourceFolderPath $ModuleOutputFolder)) - Write-Host ($exports | Out-String) + [pscustomobject]$exports | Format-List | Out-String #endregion - Analyze source files #region - Module header + Add-Content -Path $rootModuleFile -Force -Value @' +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidAssignmentToAutomaticVariable', 'IsWindows', + Justification = 'IsWindows doesnt exist in PS5.1' +)] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', 'IsWindows', + Justification = 'IsWindows doesnt exist in PS5.1' +)] +'@ + $headerFilePath = Join-Path -Path $ModuleOutputFolder -ChildPath 'header.ps1' if (Test-Path -Path $headerFilePath) { Get-Content -Path $headerFilePath -Raw | Add-Content -Path $rootModuleFile -Force @@ -149,10 +160,15 @@ param() #region - Module post-header Add-Content -Path $rootModuleFile -Force -Value @' $baseName = [System.IO.Path]::GetFileNameWithoutExtension($PSCommandPath) -$script:PSModuleInfo = Test-ModuleManifest -Path "$PSScriptRoot\$baseName.psd1" +$script:PSModuleInfo = Import-PowerShellDataFile -Path "$PSScriptRoot\$baseName.psd1" $script:PSModuleInfo | Format-List | Out-String -Stream | ForEach-Object { Write-Debug $_ } $scriptName = $script:PSModuleInfo.Name Write-Debug "[$scriptName] - Importing module" + +if ($PSEdition -eq 'Desktop') { + $IsWindows = $true +} + '@ #endregion - Module post-header @@ -224,7 +240,7 @@ Write-Debug "[`$scriptName] - $relativePath - Done" $exportsString = $exports | Format-Hashtable - Write-Host ($exportsString | Out-String) + $exportsString | Out-String $params = @{ Path = $rootModuleFile @@ -256,12 +272,11 @@ Export-ModuleMember @exports Write-Host (Show-FileContent -Path $rootModuleFile) } - LogGroup 'Build root module - Validate - Import' { - Add-PSModulePath -Path (Split-Path -Path $ModuleOutputFolder -Parent) - Import-PSModule -Path $ModuleOutputFolder -ModuleName $ModuleName - } + # LogGroup 'Build root module - Validate - Import' { + # Install-PSModule -Path $ModuleOutputFolder + # } - LogGroup 'Build root module - Validate - File list' { - (Get-ChildItem -Path $ModuleOutputFolder -Recurse -Force).FullName | Sort-Object - } + # LogGroup 'Build root module - Validate - File list' { + # Get-ChildItem -Path $ModuleOutputFolder -Recurse -Force | Resolve-Path -Relative | Sort-Object + # } } diff --git a/scripts/helpers/Build/ConvertTo-Hashtable.ps1 b/scripts/helpers/Build/ConvertTo-Hashtable.ps1 deleted file mode 100644 index 33568902..00000000 --- a/scripts/helpers/Build/ConvertTo-Hashtable.ps1 +++ /dev/null @@ -1,32 +0,0 @@ -function ConvertTo-Hashtable { - <# - .SYNOPSIS - Converts a string to a hashtable. - - .DESCRIPTION - Converts a string to a hashtable. - - .EXAMPLE - ConvertTo-Hashtable -InputString "@{Key1 = 'Value1'; Key2 = 'Value2'}" - - Key Value - --- ----- - Key1 Value1 - Key2 Value2 - - Converts the string to a hashtable. - #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSAvoidUsingInvokeExpression', '', Scope = 'Function', - Justification = 'Converting a string based hashtable to a hashtable.' - )] - [CmdletBinding()] - param ( - # The string to convert to a hashtable. - [Parameter(Mandatory = $true)] - [string]$InputString - ) - - Invoke-Expression $InputString - -} diff --git a/scripts/helpers/Build/Import-PSModule.ps1 b/scripts/helpers/Build/Import-PSModule.ps1 deleted file mode 100644 index 79fa949a..00000000 --- a/scripts/helpers/Build/Import-PSModule.ps1 +++ /dev/null @@ -1,53 +0,0 @@ -function Import-PSModule { - <# - .SYNOPSIS - Imports a build PS module. - - .DESCRIPTION - Imports a build PS module. - - .EXAMPLE - Import-PSModule -SourceFolderPath $ModuleFolderPath -ModuleName $ModuleName - - Imports a module located at $ModuleFolderPath with the name $ModuleName. - #> - [CmdletBinding()] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSAvoidUsingWriteHost', '', Scope = 'Function', - Justification = 'Want to just write to the console, not the pipeline.' - )] - #Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' } - param( - # Path to the folder where the module source code is located. - [Parameter(Mandatory)] - [string] $Path, - - # Name of the module. - [Parameter(Mandatory)] - [string] $ModuleName - ) - - $moduleName = Split-Path -Path $Path -Leaf - $manifestFileName = "$moduleName.psd1" - $manifestFilePath = Join-Path -Path $Path $manifestFileName - $manifestFile = Get-ModuleManifest -Path $manifestFilePath -As FileInfo -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 } - $existingModule.NestedModules | ForEach-Object { $_ | Remove-Module -Force -Verbose -ErrorAction SilentlyContinue } - # Get-InstalledPSResource | Where-Object Name -EQ $ModuleName | Uninstall-PSResource -SkipDependencyCheck -Verbose:$false - Resolve-PSModuleDependency -ManifestFilePath $manifestFile - Import-Module -Name $ModuleName -RequiredVersion '999.0.0' - - 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-Host 'List commands' - Write-Host (Get-Command -Module $moduleName | Format-Table -AutoSize | Out-String) - - if ($ModuleName -notin $availableModules.Name) { - throw 'Module not found' - } -} diff --git a/scripts/helpers/Build/Resolve-PSModuleDependency.ps1 b/scripts/helpers/Build/Resolve-PSModuleDependency.ps1 deleted file mode 100644 index accf607c..00000000 --- a/scripts/helpers/Build/Resolve-PSModuleDependency.ps1 +++ /dev/null @@ -1,67 +0,0 @@ -function Resolve-PSModuleDependency { - <# - .SYNOPSIS - Resolve dependencies for a module based on the manifest file. - - .DESCRIPTION - Resolve dependencies for a module based on the manifest file, following PSModuleInfo structure - - .EXAMPLE - Resolve-PSModuleDependency -Path 'C:\MyModule\MyModule.psd1' - - Installs all modules defined in the manifest file, following PSModuleInfo structure. - - .NOTES - Should later be adapted to support both pre-reqs, and dependencies. - Should later be adapted to take 4 parameters sets: specific version ("requiredVersion" | "GUID"), latest version ModuleVersion, - and latest version within a range MinimumVersion - MaximumVersion. - #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSAvoidUsingWriteHost', '', Scope = 'Function', - Justification = 'Want to just write to the console, not the pipeline.' - )] - [Alias('Resolve-PSModuleDependencies')] - [CmdletBinding()] - #Requires -Modules @{ ModuleName = 'Retry'; ModuleVersion = '0.1.3' } - param( - # The path to the manifest file. - [Parameter(Mandatory)] - [string] $ManifestFilePath - ) - - Write-Host 'Resolving dependencies' - - $manifest = Import-PowerShellDataFile -Path $ManifestFilePath - Write-Host "Reading [$ManifestFilePath]" - Write-Host "Found [$($manifest.RequiredModules.Count)] modules to install" - - foreach ($requiredModule in $manifest.RequiredModules) { - $installParams = @{} - - if ($requiredModule -is [string]) { - $installParams.Name = $requiredModule - } else { - $installParams.Name = $requiredModule.ModuleName - $installParams.MinimumVersion = $requiredModule.ModuleVersion - $installParams.RequiredVersion = $requiredModule.RequiredVersion - $installParams.MaximumVersion = $requiredModule.MaximumVersion - } - $installParams.Force = $true - $installParams.Verbose = $false - - Write-Host "[$($installParams.Name)] - Installing module" - $VerbosePreferenceOriginal = $VerbosePreference - $VerbosePreference = 'SilentlyContinue' - Retry -Count 5 -Delay 10 { - Install-Module @installParams -AllowPrerelease:$false - } - $VerbosePreference = $VerbosePreferenceOriginal - Write-Host "[$($installParams.Name)] - Importing module" - $VerbosePreferenceOriginal = $VerbosePreference - $VerbosePreference = 'SilentlyContinue' - Import-Module @installParams - $VerbosePreference = $VerbosePreferenceOriginal - Write-Host "[$($installParams.Name)] - Done" - } - Write-Host 'Resolving dependencies - Done' -} diff --git a/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 b/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 index 47d64e45..887b73cf 100644 --- a/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 +++ b/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 @@ -23,21 +23,77 @@ [Parameter(Mandatory)] [string] $ModuleName, - # Folder where the module is outputted. + # Path to the folder where the module source code is located. + [Parameter(Mandatory)] + [System.IO.DirectoryInfo] $ModuleSourceFolder, + + # Path to the folder where the built modules are outputted. [Parameter(Mandatory)] [System.IO.DirectoryInfo] $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-Host "Found aliases: [$($aliases.Count)]" - foreach ($alias in $aliases) { - Write-Host "Alias: [$($alias.Name)]" + Write-Host "Module output folder: [$ModuleSourceFolder]" + + $publicFunctionsPath = Join-Path -Path $ModuleSourceFolder -ChildPath 'functions/public' + Write-Host "Public functions path: [$publicFunctionsPath]" + if (-not (Test-Path -Path $publicFunctionsPath)) { + Write-Host "Public functions path does not exist: [$publicFunctionsPath]" + return + } + + # Get all child items in the module source folder of a powershell file type + $files = Get-ChildItem -Path $publicFunctionsPath -Recurse -File -Include '*.ps1', '*.psm1' | Select-Object -ExpandProperty FullName + + # Initialize an array to store all found aliases + $allAliases = @() + + foreach ($file in $files) { + Write-Host "Parsing file: [$file]" + + # Parse the file using AST + $ast = [System.Management.Automation.Language.Parser]::ParseFile( + $file, + [ref]$null, + [ref]$null + ) + + # Get all function definitions + $functionAsts = $ast.FindAll( + { + param($node) + $node -is [System.Management.Automation.Language.FunctionDefinitionAst] + }, $false) + + Write-Host " Found functions: [$($functionAsts.Count)]" + foreach ($functionAst in $functionAsts) { + # Get the function name + $functionName = $functionAst.Name + Write-Host " Processing: [$functionName]" + + $functionAst | ForEach-Object { + $funcName = $_.Name + $funcAttributes = $_.Body.FindAll({ $args[0] -is [System.Management.Automation.Language.AttributeAst] }, $true) | Where-Object { + $_.Parent -is [System.Management.Automation.Language.ParamBlockAst] + } + $aliasAttr = $funcAttributes | Where-Object { $_.TypeName.Name -eq 'Alias' } + + if ($aliasAttr) { + $aliases = $aliasAttr.PositionalArguments | ForEach-Object { $_.ToString().Trim('"', "'") } + Write-Host " Found alias [$aliases] for function [$funcName]" + $allAliases += $aliases + } + } + } + } + + Write-Host "Found aliases: [$($allAliases.Count)]" + foreach ($alias in $allAliases) { + Write-Host " - [$alias]" } $outputManifestPath = Join-Path -Path $ModuleOutputFolder -ChildPath "$ModuleName.psd1" Write-Host "Output manifest path: [$outputManifestPath]" Write-Host 'Setting module manifest with AliasesToExport' - Set-ModuleManifest -Path $outputManifestPath -AliasesToExport $aliases.Name -Verbose + Set-ModuleManifest -Path $outputManifestPath -AliasesToExport $allAliases -Verbose } } diff --git a/scripts/main.ps1 b/scripts/main.ps1 index d831ebef..c760ab99 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -16,20 +16,20 @@ LogGroup "Loading helper scripts from [$path]" { } LogGroup 'Loading inputs' { - $moduleName = ($env:GITHUB_ACTION_INPUT_Name | IsNullOrEmpty) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_Name - 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-Host "Source module path: [$moduleSourceFolderPath]" - if (-not (Test-Path -Path $moduleSourceFolderPath)) { - throw "Module path [$moduleSourceFolderPath] does not exist." + $moduleName = if ([string]::IsNullOrEmpty($env:PSMODULE_BUILD_PSMODULE_INPUT_Name)) { + $env:GITHUB_REPOSITORY_NAME + } else { + $env:PSMODULE_BUILD_PSMODULE_INPUT_Name } - - $modulesOutputFolderPath = Join-Path $env:GITHUB_WORKSPACE $env:GITHUB_ACTION_INPUT_ModulesOutputPath - Write-Host "Modules output path: [$modulesOutputFolderPath]" + Set-GitHubOutput -Name ModuleName -Value $moduleName + + $sourceFolderPath = Resolve-Path -Path 'src' | Select-Object -ExpandProperty Path + $moduleOutputFolderPath = Join-Path $pwd -ChildPath 'outputs/module' + [pscustomobject]@{ + moduleName = $moduleName + sourceFolderPath = $sourceFolderPath + moduleOutputFolderPath = $moduleOutputFolderPath + } | Format-List | Out-String } LogGroup 'Build local scripts' { @@ -46,9 +46,12 @@ LogGroup 'Build local scripts' { } $params = @{ - ModuleName = $moduleName - ModuleSourceFolderPath = $moduleSourceFolderPath - ModulesOutputFolderPath = $modulesOutputFolderPath + ModuleName = $moduleName + ModuleSourceFolderPath = $sourceFolderPath + ModuleOutputFolderPath = $moduleOutputFolderPath } - Build-PSModule @params + +Set-GithubOutput -Name ModuleOutputFolderPath -Value $moduleOutputFolderPath + +exit 0 diff --git a/tests/src/functions/public/Test-PSModuleTest.ps1 b/tests/srcMinimalTestRepo/src/functions/public/Test-PSModuleTest.ps1 similarity index 100% rename from tests/src/functions/public/Test-PSModuleTest.ps1 rename to tests/srcMinimalTestRepo/src/functions/public/Test-PSModuleTest.ps1 diff --git a/tests/src/assemblies/LsonLib.dll b/tests/srcTestRepo/src/assemblies/LsonLib.dll similarity index 100% rename from tests/src/assemblies/LsonLib.dll rename to tests/srcTestRepo/src/assemblies/LsonLib.dll diff --git a/tests/src/classes/private/SecretWriter.ps1 b/tests/srcTestRepo/src/classes/private/SecretWriter.ps1 similarity index 100% rename from tests/src/classes/private/SecretWriter.ps1 rename to tests/srcTestRepo/src/classes/private/SecretWriter.ps1 diff --git a/tests/src/classes/public/Book.ps1 b/tests/srcTestRepo/src/classes/public/Book.ps1 similarity index 100% rename from tests/src/classes/public/Book.ps1 rename to tests/srcTestRepo/src/classes/public/Book.ps1 diff --git a/tests/src/data/Config.psd1 b/tests/srcTestRepo/src/data/Config.psd1 similarity index 100% rename from tests/src/data/Config.psd1 rename to tests/srcTestRepo/src/data/Config.psd1 diff --git a/tests/src/data/Settings.psd1 b/tests/srcTestRepo/src/data/Settings.psd1 similarity index 100% rename from tests/src/data/Settings.psd1 rename to tests/srcTestRepo/src/data/Settings.psd1 diff --git a/tests/src/finally.ps1 b/tests/srcTestRepo/src/finally.ps1 similarity index 100% rename from tests/src/finally.ps1 rename to tests/srcTestRepo/src/finally.ps1 diff --git a/tests/src/formats/CultureInfo.Format.ps1xml b/tests/srcTestRepo/src/formats/CultureInfo.Format.ps1xml similarity index 100% rename from tests/src/formats/CultureInfo.Format.ps1xml rename to tests/srcTestRepo/src/formats/CultureInfo.Format.ps1xml diff --git a/tests/src/formats/Mygciview.Format.ps1xml b/tests/srcTestRepo/src/formats/Mygciview.Format.ps1xml similarity index 100% rename from tests/src/formats/Mygciview.Format.ps1xml rename to tests/srcTestRepo/src/formats/Mygciview.Format.ps1xml diff --git a/tests/src/functions/private/Get-InternalPSModule.ps1 b/tests/srcTestRepo/src/functions/private/Get-InternalPSModule.ps1 similarity index 100% rename from tests/src/functions/private/Get-InternalPSModule.ps1 rename to tests/srcTestRepo/src/functions/private/Get-InternalPSModule.ps1 diff --git a/tests/src/functions/private/Set-InternalPSModule.ps1 b/tests/srcTestRepo/src/functions/private/Set-InternalPSModule.ps1 similarity index 100% rename from tests/src/functions/private/Set-InternalPSModule.ps1 rename to tests/srcTestRepo/src/functions/private/Set-InternalPSModule.ps1 diff --git a/tests/srcWithManifest/functions/public/PSModule/Get-PSModuleTest.ps1 b/tests/srcTestRepo/src/functions/public/PSModule/Get-PSModuleTest.ps1 similarity index 97% rename from tests/srcWithManifest/functions/public/PSModule/Get-PSModuleTest.ps1 rename to tests/srcTestRepo/src/functions/public/PSModule/Get-PSModuleTest.ps1 index 86beb12d..eae698a5 100644 --- a/tests/srcWithManifest/functions/public/PSModule/Get-PSModuleTest.ps1 +++ b/tests/srcTestRepo/src/functions/public/PSModule/Get-PSModuleTest.ps1 @@ -1,5 +1,5 @@ #Requires -Modules Store -#Requires -Modules @{ ModuleName = 'PSSemVer'; RequiredVersion = '1.0.0' } +#Requires -Modules @{ ModuleName = 'PSSemVer'; RequiredVersion = '1.1.5' } #Requires -Modules @{ ModuleName = 'DynamicParams'; ModuleVersion = '1.1.8' } function Get-PSModuleTest { diff --git a/tests/src/functions/public/PSModule/New-PSModuleTest.ps1 b/tests/srcTestRepo/src/functions/public/PSModule/New-PSModuleTest.ps1 similarity index 100% rename from tests/src/functions/public/PSModule/New-PSModuleTest.ps1 rename to tests/srcTestRepo/src/functions/public/PSModule/New-PSModuleTest.ps1 diff --git a/tests/src/functions/public/PSModule/PSModule.md b/tests/srcTestRepo/src/functions/public/PSModule/PSModule.md similarity index 100% rename from tests/src/functions/public/PSModule/PSModule.md rename to tests/srcTestRepo/src/functions/public/PSModule/PSModule.md diff --git a/tests/src/functions/public/SomethingElse/Set-PSModuleTest.ps1 b/tests/srcTestRepo/src/functions/public/SomethingElse/Set-PSModuleTest.ps1 similarity index 100% rename from tests/src/functions/public/SomethingElse/Set-PSModuleTest.ps1 rename to tests/srcTestRepo/src/functions/public/SomethingElse/Set-PSModuleTest.ps1 diff --git a/tests/src/functions/public/SomethingElse/SomethingElse.md b/tests/srcTestRepo/src/functions/public/SomethingElse/SomethingElse.md similarity index 100% rename from tests/src/functions/public/SomethingElse/SomethingElse.md rename to tests/srcTestRepo/src/functions/public/SomethingElse/SomethingElse.md diff --git a/tests/srcMinimal/functions/public/Test-PSModuleTest.ps1 b/tests/srcTestRepo/src/functions/public/Test-PSModuleTest.ps1 similarity index 100% rename from tests/srcMinimal/functions/public/Test-PSModuleTest.ps1 rename to tests/srcTestRepo/src/functions/public/Test-PSModuleTest.ps1 diff --git a/tests/src/header.ps1 b/tests/srcTestRepo/src/header.ps1 similarity index 100% rename from tests/src/header.ps1 rename to tests/srcTestRepo/src/header.ps1 diff --git a/tests/src/init/initializer.ps1 b/tests/srcTestRepo/src/init/initializer.ps1 similarity index 100% rename from tests/src/init/initializer.ps1 rename to tests/srcTestRepo/src/init/initializer.ps1 diff --git a/tests/src/modules/OtherPSModule.psm1 b/tests/srcTestRepo/src/modules/OtherPSModule.psm1 similarity index 100% rename from tests/src/modules/OtherPSModule.psm1 rename to tests/srcTestRepo/src/modules/OtherPSModule.psm1 diff --git a/tests/src/scripts/loader.ps1 b/tests/srcTestRepo/src/scripts/loader.ps1 similarity index 100% rename from tests/src/scripts/loader.ps1 rename to tests/srcTestRepo/src/scripts/loader.ps1 diff --git a/tests/src/types/DirectoryInfo.Types.ps1xml b/tests/srcTestRepo/src/types/DirectoryInfo.Types.ps1xml similarity index 100% rename from tests/src/types/DirectoryInfo.Types.ps1xml rename to tests/srcTestRepo/src/types/DirectoryInfo.Types.ps1xml diff --git a/tests/src/types/FileInfo.Types.ps1xml b/tests/srcTestRepo/src/types/FileInfo.Types.ps1xml similarity index 100% rename from tests/src/types/FileInfo.Types.ps1xml rename to tests/srcTestRepo/src/types/FileInfo.Types.ps1xml diff --git a/tests/src/variables/private/PrivateVariables.ps1 b/tests/srcTestRepo/src/variables/private/PrivateVariables.ps1 similarity index 100% rename from tests/src/variables/private/PrivateVariables.ps1 rename to tests/srcTestRepo/src/variables/private/PrivateVariables.ps1 diff --git a/tests/src/variables/public/Moons.ps1 b/tests/srcTestRepo/src/variables/public/Moons.ps1 similarity index 100% rename from tests/src/variables/public/Moons.ps1 rename to tests/srcTestRepo/src/variables/public/Moons.ps1 diff --git a/tests/src/variables/public/Planets.ps1 b/tests/srcTestRepo/src/variables/public/Planets.ps1 similarity index 100% rename from tests/src/variables/public/Planets.ps1 rename to tests/srcTestRepo/src/variables/public/Planets.ps1 diff --git a/tests/src/variables/public/SolarSystems.ps1 b/tests/srcTestRepo/src/variables/public/SolarSystems.ps1 similarity index 100% rename from tests/src/variables/public/SolarSystems.ps1 rename to tests/srcTestRepo/src/variables/public/SolarSystems.ps1 diff --git a/tests/srcWithManifest/assemblies/LsonLib.dll b/tests/srcWithManifestTestRepo/src/assemblies/LsonLib.dll similarity index 100% rename from tests/srcWithManifest/assemblies/LsonLib.dll rename to tests/srcWithManifestTestRepo/src/assemblies/LsonLib.dll diff --git a/tests/srcWithManifest/data/Config.psd1 b/tests/srcWithManifestTestRepo/src/data/Config.psd1 similarity index 100% rename from tests/srcWithManifest/data/Config.psd1 rename to tests/srcWithManifestTestRepo/src/data/Config.psd1 diff --git a/tests/srcWithManifest/data/Settings.psd1 b/tests/srcWithManifestTestRepo/src/data/Settings.psd1 similarity index 100% rename from tests/srcWithManifest/data/Settings.psd1 rename to tests/srcWithManifestTestRepo/src/data/Settings.psd1 diff --git a/tests/srcWithManifest/finally.ps1 b/tests/srcWithManifestTestRepo/src/finally.ps1 similarity index 100% rename from tests/srcWithManifest/finally.ps1 rename to tests/srcWithManifestTestRepo/src/finally.ps1 diff --git a/tests/srcWithManifest/formats/CultureInfo.Format.ps1xml b/tests/srcWithManifestTestRepo/src/formats/CultureInfo.Format.ps1xml similarity index 100% rename from tests/srcWithManifest/formats/CultureInfo.Format.ps1xml rename to tests/srcWithManifestTestRepo/src/formats/CultureInfo.Format.ps1xml diff --git a/tests/srcWithManifest/formats/Mygciview.Format.ps1xml b/tests/srcWithManifestTestRepo/src/formats/Mygciview.Format.ps1xml similarity index 100% rename from tests/srcWithManifest/formats/Mygciview.Format.ps1xml rename to tests/srcWithManifestTestRepo/src/formats/Mygciview.Format.ps1xml diff --git a/tests/srcWithManifest/functions/private/Get-InternalPSModule.ps1 b/tests/srcWithManifestTestRepo/src/functions/private/Get-InternalPSModule.ps1 similarity index 100% rename from tests/srcWithManifest/functions/private/Get-InternalPSModule.ps1 rename to tests/srcWithManifestTestRepo/src/functions/private/Get-InternalPSModule.ps1 diff --git a/tests/srcWithManifest/functions/private/Set-InternalPSModule.ps1 b/tests/srcWithManifestTestRepo/src/functions/private/Set-InternalPSModule.ps1 similarity index 100% rename from tests/srcWithManifest/functions/private/Set-InternalPSModule.ps1 rename to tests/srcWithManifestTestRepo/src/functions/private/Set-InternalPSModule.ps1 diff --git a/tests/src/functions/public/PSModule/Get-PSModuleTest.ps1 b/tests/srcWithManifestTestRepo/src/functions/public/PSModule/Get-PSModuleTest.ps1 similarity index 85% rename from tests/src/functions/public/PSModule/Get-PSModuleTest.ps1 rename to tests/srcWithManifestTestRepo/src/functions/public/PSModule/Get-PSModuleTest.ps1 index 86beb12d..f544230d 100644 --- a/tests/src/functions/public/PSModule/Get-PSModuleTest.ps1 +++ b/tests/srcWithManifestTestRepo/src/functions/public/PSModule/Get-PSModuleTest.ps1 @@ -1,5 +1,5 @@ #Requires -Modules Store -#Requires -Modules @{ ModuleName = 'PSSemVer'; RequiredVersion = '1.0.0' } +#Requires -Modules @{ ModuleName = 'PSSemVer'; ModuleVersion = '1.0.0' } #Requires -Modules @{ ModuleName = 'DynamicParams'; ModuleVersion = '1.1.8' } function Get-PSModuleTest { diff --git a/tests/srcWithManifest/functions/public/PSModule/New-PSModuleTest.ps1 b/tests/srcWithManifestTestRepo/src/functions/public/PSModule/New-PSModuleTest.ps1 similarity index 100% rename from tests/srcWithManifest/functions/public/PSModule/New-PSModuleTest.ps1 rename to tests/srcWithManifestTestRepo/src/functions/public/PSModule/New-PSModuleTest.ps1 diff --git a/tests/srcWithManifest/functions/public/PSModule/PSModule.md b/tests/srcWithManifestTestRepo/src/functions/public/PSModule/PSModule.md similarity index 100% rename from tests/srcWithManifest/functions/public/PSModule/PSModule.md rename to tests/srcWithManifestTestRepo/src/functions/public/PSModule/PSModule.md diff --git a/tests/srcWithManifest/functions/public/SomethingElse/Set-PSModuleTest.ps1 b/tests/srcWithManifestTestRepo/src/functions/public/SomethingElse/Set-PSModuleTest.ps1 similarity index 100% rename from tests/srcWithManifest/functions/public/SomethingElse/Set-PSModuleTest.ps1 rename to tests/srcWithManifestTestRepo/src/functions/public/SomethingElse/Set-PSModuleTest.ps1 diff --git a/tests/srcWithManifest/functions/public/SomethingElse/SomethingElse.md b/tests/srcWithManifestTestRepo/src/functions/public/SomethingElse/SomethingElse.md similarity index 100% rename from tests/srcWithManifest/functions/public/SomethingElse/SomethingElse.md rename to tests/srcWithManifestTestRepo/src/functions/public/SomethingElse/SomethingElse.md diff --git a/tests/srcWithManifest/functions/public/Test-PSModuleTest.ps1 b/tests/srcWithManifestTestRepo/src/functions/public/Test-PSModuleTest.ps1 similarity index 100% rename from tests/srcWithManifest/functions/public/Test-PSModuleTest.ps1 rename to tests/srcWithManifestTestRepo/src/functions/public/Test-PSModuleTest.ps1 diff --git a/tests/srcWithManifest/header.ps1 b/tests/srcWithManifestTestRepo/src/header.ps1 similarity index 100% rename from tests/srcWithManifest/header.ps1 rename to tests/srcWithManifestTestRepo/src/header.ps1 diff --git a/tests/srcWithManifest/init/initializer.ps1 b/tests/srcWithManifestTestRepo/src/init/initializer.ps1 similarity index 100% rename from tests/srcWithManifest/init/initializer.ps1 rename to tests/srcWithManifestTestRepo/src/init/initializer.ps1 diff --git a/tests/srcWithManifest/manifest.psd1 b/tests/srcWithManifestTestRepo/src/manifest.psd1 similarity index 100% rename from tests/srcWithManifest/manifest.psd1 rename to tests/srcWithManifestTestRepo/src/manifest.psd1 diff --git a/tests/srcWithManifest/modules/OtherPSModule.psm1 b/tests/srcWithManifestTestRepo/src/modules/OtherPSModule.psm1 similarity index 100% rename from tests/srcWithManifest/modules/OtherPSModule.psm1 rename to tests/srcWithManifestTestRepo/src/modules/OtherPSModule.psm1 diff --git a/tests/srcWithManifest/scripts/loader.ps1 b/tests/srcWithManifestTestRepo/src/scripts/loader.ps1 similarity index 100% rename from tests/srcWithManifest/scripts/loader.ps1 rename to tests/srcWithManifestTestRepo/src/scripts/loader.ps1 diff --git a/tests/srcWithManifest/types/DirectoryInfo.Types.ps1xml b/tests/srcWithManifestTestRepo/src/types/DirectoryInfo.Types.ps1xml similarity index 100% rename from tests/srcWithManifest/types/DirectoryInfo.Types.ps1xml rename to tests/srcWithManifestTestRepo/src/types/DirectoryInfo.Types.ps1xml diff --git a/tests/srcWithManifest/types/FileInfo.Types.ps1xml b/tests/srcWithManifestTestRepo/src/types/FileInfo.Types.ps1xml similarity index 100% rename from tests/srcWithManifest/types/FileInfo.Types.ps1xml rename to tests/srcWithManifestTestRepo/src/types/FileInfo.Types.ps1xml diff --git a/tests/srcWithManifest/variables/private/PrivateVariables.ps1 b/tests/srcWithManifestTestRepo/src/variables/private/PrivateVariables.ps1 similarity index 100% rename from tests/srcWithManifest/variables/private/PrivateVariables.ps1 rename to tests/srcWithManifestTestRepo/src/variables/private/PrivateVariables.ps1 diff --git a/tests/srcWithManifest/variables/public/Moons.ps1 b/tests/srcWithManifestTestRepo/src/variables/public/Moons.ps1 similarity index 100% rename from tests/srcWithManifest/variables/public/Moons.ps1 rename to tests/srcWithManifestTestRepo/src/variables/public/Moons.ps1 diff --git a/tests/srcWithManifest/variables/public/Planets.ps1 b/tests/srcWithManifestTestRepo/src/variables/public/Planets.ps1 similarity index 100% rename from tests/srcWithManifest/variables/public/Planets.ps1 rename to tests/srcWithManifestTestRepo/src/variables/public/Planets.ps1 diff --git a/tests/srcWithManifest/variables/public/SolarSystems.ps1 b/tests/srcWithManifestTestRepo/src/variables/public/SolarSystems.ps1 similarity index 100% rename from tests/srcWithManifest/variables/public/SolarSystems.ps1 rename to tests/srcWithManifestTestRepo/src/variables/public/SolarSystems.ps1 From 3f9d3e84ad2274257f1e93b60d9f4ff1ef1e4f3c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 19 Apr 2025 13:03:48 +0200 Subject: [PATCH 5/8] =?UTF-8?q?=F0=9F=93=96=20[Docs]:=20Update=20to=20docs?= =?UTF-8?q?=20(#113)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description This pull request updates the `README.md` file to improve documentation for a PowerShell module build process. The changes include adding a new step to the build process, clarifying repository structure expectations, and renaming a section for better clarity. ### Documentation Updates: * **Added a new step to the build process:** Documented the step that uploads the module artifact for use in subsequent workflow steps. (`README.md`, [README.mdR25](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R25)) * **Defined expected repository structure:** Added a section describing the expected repository structure, referencing the `Template-PSModule` repository as an example. (`README.md`, [README.mdR40-R43](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R40-R43)) * **Renamed "Sources" section to "References":** Updated the section title to better reflect its purpose. (`README.md`, [README.mdL154-R159](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L154-R159)) ## Type of change - [x] 📖 [Docs] - [ ] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- README.md | 83 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index a43ce3f1..048a291f 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ This step lets you add custom build logic to process or modify the module conten 1. **Copies the source code** of the module to an output folder. 1. **Builds the module manifest file** based on information from the GitHub repository and the source code. For more information, please read the [Module Manifest](#module-manifest) section. 1. **Builds the root module (.psm1) file** by combining source code and adding automation into the root module file. For more information, please read the [Root module](#root-module) section. +1. **Uploads the module artifact** so that it can be used in the next steps of the workflow. ## Usage @@ -36,6 +37,9 @@ This step lets you add custom build logic to process or modify the module conten | `Prerelease` | Allow prerelease versions if available. | `false` | `'false'` | | `WorkingDirectory` | The working directory where the script runs. | `false` | `'.'` | +## Expected repository structure + +The action expects the module repository to be structured similarly to [Template-PSModule](https://github.com/PSModule/Template-PSModule). ## Root module The `src` folder may contain a 'root module' file. If present, the build function will disregard this file and build a new root module file based on the source code in the module folder. @@ -90,49 +94,50 @@ During the module manifest build process the following steps are performed: 1. `ExternalModuleDependencies` is not automated. If specified in the source manifest, that value is used. 1. `HelpInfoURI` is not automated. If specified in the source manifest, that value is used. 1. Create a new manifest file in the output folder with the gathered information, which also generates a new `GUID` for the module. -1. Format the manifest file using the `Set-ModuleManifest` function from the [Utilities](https://github.com/PSModule/Utilities) module. -Linking the description to the module manifest file might show more how this works: +### Sources for properties in the manifest file + +Below is a list of properties in the module manifest file and their sources: ```powershell @{ - RootModule = 'Utilities.psm1' # Generated from the module name, .psm1 - ModuleVersion = '0.0.1' # Set during release using Publish-PSModule. - CompatiblePSEditions = @() # Get from source files, requires -PSEdition , null if not provided. - GUID = '' # Generated when saving the manifest using New-ModuleManifest. - Author = 'PSModule' # Derived from the GitHub Owner, unless specified in the source manifest. - CompanyName = 'PSModule' # Derived from the GitHub Owner, unless specified in the source manifest. - Copyright = '(c) 2024 PSModule. All rights reserved.' + RootModule = 'Utilities.psm1' # Generated as .psm1 from the module name; can be overridden in the source manifest. + ModuleVersion = '0.0.1' # Temporary version set during the build; updated by Publish‑PSModule during the release process. + CompatiblePSEditions = @() # Determined from #Requires -PSEdition statements in source files.; defaults to @('Core','Desktop') if none found. + GUID = '' # New GUID generated by New‑ModuleManifest when the manifest is created. + Author = 'PSModule' # Derived from the GitHub owner unless specified in the source manifest. + CompanyName = 'PSModule' # Derived from the GitHub owner unless specified in the source manifest. + Copyright = '(c) 2024 PSModule. All rights reserved.' # Default template; overridden if specified in the source manifest. Description = 'This is a module.' # Taken from the repository description or the source manifest. - PowerShellVersion = '' # Derived from source files, requires -Version [.], null if not provided. - PowerShellHostName = '' # Taken from the manifest file, null if not provided. - PowerShellHostVersion = '' # Taken from the manifest file, null if not provided. - DotNetFrameworkVersion = '' # Taken from the manifest file, null if not provided. - ClrVersion = '' # Taken from the manifest file, null if not provided. - ProcessorArchitecture = '' # Taken from the manifest file, null if not provided. - RequiredModules = @() # Derived from source files, ensuring required modules are installed. - RequiredAssemblies = @() # Collected from assemblies\*.dll and modules\*.dll. - ScriptsToProcess = @() # Collected from scripts\*.ps1 and classes\*.ps1 ordered by name. - TypesToProcess = @() # Collected from *.Types.ps1xml files in the source folder. - FormatsToProcess = @() # Collected from *.Format.ps1xml files in the source folder. - NestedModules = @() # Collected from modules\*.psm1, modules\*.ps1, and modules\*.dll. - FunctionsToExport = @() # Collected from public\*.ps1 files. - CmdletsToExport = @() # Taken from the manifest file, or empty if not provided. - VariablesToExport = @() # Collected from variables\public\*.ps1. - AliasesToExport = '*' # Derived from functions\public\*.ps1. - DscResourcesToExport = @() # Collected from resources\*.psm1. - ModuleList = @() # A listing of all .\*.psm1 files (informational only). - FileList = @() # A listing of all .\* files (informational only). + PowerShellVersion = '' # Derived from #Requires -Version statements in source files; blank if none. + PowerShellHostName = '' # Preserved from the source manifest if provided; otherwise omitted. + PowerShellHostVersion = '' # Preserved from the source manifest if provided; otherwise omitted. + DotNetFrameworkVersion = '' # Preserved from the source manifest if provided; otherwise omitted. + ClrVersion = '' # Preserved from the source manifest if provided; otherwise omitted. + ProcessorArchitecture = '' # Preserved from the source manifest if provided; otherwise omitted. + RequiredModules = @() # Gathered from #Requires -Modules statements in source files. + RequiredAssemblies = @() # Collected from assemblies/*.dll and modules/*.dll (depth = 1). + ScriptsToProcess = @() # Collected from scripts/*.ps1, loaded alphabetically into the caller session. + TypesToProcess = @() # Collected from *.Types.ps1xml files anywhere in the source folder. + FormatsToProcess = @() # Collected from *.Format.ps1xml files anywhere in the source folder. + NestedModules = @() # Collected from modules/* (.psm1, .ps1 or .dll one level down). + FunctionsToExport = @() # Collected from functions/public/*.ps1 files. + CmdletsToExport = @() # Preserved from the source manifest if provided; empty otherwise. + VariablesToExport = @() # Collected from variables/public/*.ps1 files. + AliasesToExport = '*' # Generated from functions/public/*.ps1. + DscResourcesToExport = @() # Collected from resources/*.psm1 files. + ModuleList = @() # Informational list of all additional *.psm1 files in the module. + FileList = @() # Informational list of all files in the module source folder. PrivateData = @{ PSData = @{ - Tags = @() # Derived from repository topics and compatibility tags. - LicenseUri = '' # Generated public link to .\LICENSE. - ProjectUri = '' # Generated public link to the GitHub Repository. - IconUri = '' # Derived from .\icon\icon.png. - ReleaseNotes = '' # To be updated during release. - Prerelease = '' # Normalized version of the branch name, updated during release. - RequireLicenseAcceptance = $false - ExternalModuleDependencies = @() + Tags = @() # Generated from repository topics plus compatibility tags. + LicenseUri = '' # Public link to LICENSE file (or value from source manifest). + ProjectUri = '' # Public link to the GitHub repository (or value from source manifest). + IconUri = '' # Public link to icon\icon.png (or value from source manifest). + ReleaseNotes = '' # Not automated; supply via PR or release description. + Prerelease = '' # Managed by Publish‑PSModule; populated during release. + RequireLicenseAcceptance = $false # Defaults to $false unless specified in the source manifest. + ExternalModuleDependencies = @() # Not automated; preserved if present in the source manifest. ExperimentalFeatures = @( @{ Name = "SomeExperimentalFeature" @@ -142,8 +147,8 @@ Linking the description to the module manifest file might show more how this wor } OtherKeys = @{} } - HelpInfoURI = '' # Taken from the source manifest if provided. - DefaultCommandPrefix = '' # Taken from the source manifest if provided. + HelpInfoURI = '' # Not automated; preserved if provided in the source manifest. + DefaultCommandPrefix = '' # Not automated; preserved if provided in the source manifest. } ``` @@ -151,7 +156,7 @@ Linking the description to the module manifest file might show more how this wor This action does not require any special permissions. -## Sources +## References **Module manifest:** From 0d98e7db9c66175e9f9a159499af980e62063cde Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 2 Jun 2025 01:31:05 +0200 Subject: [PATCH 6/8] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20initiali?= =?UTF-8?q?zation=20step=20and=20dependency=20on=20`Utilities`=20(#114)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description This pull request simplifies the codebase by removing redundant module dependencies and improving code readability across various scripts. It also consolidates file exclusions in the `.jscpd.json` configuration and updates logic for handling module manifest properties. ### Module Dependency Removal: * Removed `#Requires` statements for unused module dependencies (`GitHub`, `Utilities`, `Hashtable`) across multiple scripts, including `Build-PSModule.ps1`, `Build-PSModuleManifest.ps1`, and `Build-PSModuleRootModule.ps1` files. [[1]](diffhunk://#diff-c688e346ad60fbe881bd05b6a5dbc1cd712fdca0bf8b8527965db583af825fd9L11-L12) [[2]](diffhunk://#diff-50cfb011f5c8aeef8145003927ec3e5edfdf26e5d417bcee6e441517c07454f9L14-L15) [[3]](diffhunk://#diff-1d337ff39f37506a54fda1c5d0487f1b2c2ef318f216a4d9a56c3e7248b69879L1-R1) [[4]](diffhunk://#diff-faeb855accbc346b12f7a0ece1d91f67e26e8929ab8133aedca4051d179c66faL18-L19) ### Configuration Updates: * Consolidated file exclusions in `.github/linters/.jscpd.json` by replacing specific file paths with a wildcard (`**/scripts/helpers/**`). ### Workflow Simplification: * Removed the `Initialize-PSModule` step from the `Action-Test.yml` workflow, streamlining the setup process. [[1]](diffhunk://#diff-a12ae5c885b0673c0ff6f70c2670886907590d624626e07da4c52e01aeaf56a4L28-L30) [[2]](diffhunk://#diff-a12ae5c885b0673c0ff6f70c2670886907590d624626e07da4c52e01aeaf56a4L45-L47) [[3]](diffhunk://#diff-a12ae5c885b0673c0ff6f70c2670886907590d624626e07da4c52e01aeaf56a4L62-L64) ### Code Readability Improvements: * Replaced custom `IsNotNullOrEmpty` function calls with native `.NET` methods like `[string]::IsNullOrEmpty` for better clarity and maintainability in scripts such as `Build-PSModuleManifest.ps1` and `Get-PSModuleAliasesToExport.ps1`. [[1]](diffhunk://#diff-50cfb011f5c8aeef8145003927ec3e5edfdf26e5d417bcee6e441517c07454f9L63-R64) [[2]](diffhunk://#diff-50cfb011f5c8aeef8145003927ec3e5edfdf26e5d417bcee6e441517c07454f9L76-R74) [[3]](diffhunk://#diff-ae18191466ffa02c1a8429365cf96d8768f5eae03331c4a35199f8cd961e76a7L33-R30) [[4]](diffhunk://#diff-f542f4a75d778df60fee6e176c795e133be2ed109d8212c05aa545383bd26c46L33-R30) ### Suppression Attribute Adjustments: * Updated `Diagnostics.CodeAnalysis.SuppressMessageAttribute` to include `Scope = 'Function'` for consistency in scripts like `Get-PSModuleClassesToExport.ps1` and `Get-PSModuleCmdletsToExport.ps1`. [[1]](diffhunk://#diff-c51cdeca9e44fe598bc10e94c98fc0d72f8a6fb36e872193b2fc9b9b1348f1a9L20-R20) [[2]](diffhunk://#diff-f542f4a75d778df60fee6e176c795e133be2ed109d8212c05aa545383bd26c46L13-R14) ## Type of change - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas --- .github/linters/.jscpd.json | 4 +--- .github/workflows/Action-Test.yml | 9 --------- scripts/helpers/Build-PSModule.ps1 | 2 -- scripts/helpers/Build/Build-PSModuleBase.ps1 | 1 - scripts/helpers/Build/Build-PSModuleManifest.ps1 | 8 +++----- scripts/helpers/Build/Build-PSModuleRootModule.ps1 | 5 +---- scripts/helpers/Build/Get-PSModuleAliasesToExport.ps1 | 9 +++------ scripts/helpers/Build/Get-PSModuleClassesToExport.ps1 | 2 +- scripts/helpers/Build/Get-PSModuleCmdletsToExport.ps1 | 9 +++------ scripts/helpers/Build/Get-PSModuleFunctionsToExport.ps1 | 6 ++---- .../Build/Update-PSModuleManifestAliasesToExport.ps1 | 2 -- scripts/main.ps1 | 2 -- 12 files changed, 14 insertions(+), 45 deletions(-) diff --git a/.github/linters/.jscpd.json b/.github/linters/.jscpd.json index 7cc00e60..f734bf16 100644 --- a/.github/linters/.jscpd.json +++ b/.github/linters/.jscpd.json @@ -6,9 +6,7 @@ "ignore": [ "**/tests/**", "**/.github/workflows/Action-Test.yml", - "**/scripts/helpers/Build/Build-PSModuleManifest.ps1", - "**/scripts/helpers/Build/Build-PSModuleRootModule.ps1", - "**/scripts/helpers/Build/PSScriptAnalyzer.Tests.psd1" + "**/scripts/helpers/**" ], "absolute": true } diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index a334e868..9b426109 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -25,9 +25,6 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 - - name: Initialize environment - uses: PSModule/Initialize-PSModule@v1 - - name: Action-Test uses: ./ with: @@ -42,9 +39,6 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 - - name: Initialize environment - uses: PSModule/Initialize-PSModule@v1 - - name: Action-Test uses: ./ with: @@ -59,9 +53,6 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 - - name: Initialize environment - uses: PSModule/Initialize-PSModule@v1 - - name: Action-Test uses: ./ with: diff --git a/scripts/helpers/Build-PSModule.ps1 b/scripts/helpers/Build-PSModule.ps1 index ea854597..29a4d8ea 100644 --- a/scripts/helpers/Build-PSModule.ps1 +++ b/scripts/helpers/Build-PSModule.ps1 @@ -8,8 +8,6 @@ #> [OutputType([void])] [CmdletBinding()] - #Requires -Modules @{ ModuleName = 'GitHub'; ModuleVersion = '0.13.2' } - #Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' } [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSReviewUnusedParameter', '', Scope = 'Function', Justification = 'LogGroup - Scoping affects the variables line of sight.' diff --git a/scripts/helpers/Build/Build-PSModuleBase.ps1 b/scripts/helpers/Build/Build-PSModuleBase.ps1 index a0b2c3db..4a0b9035 100644 --- a/scripts/helpers/Build/Build-PSModuleBase.ps1 +++ b/scripts/helpers/Build/Build-PSModuleBase.ps1 @@ -11,7 +11,6 @@ Build-PSModuleBase -SourceFolderPath 'C:\MyModule\src\MyModule' -OutputFolderPath 'C:\MyModule\build\MyModule' #> [CmdletBinding()] - #Requires -Modules @{ ModuleName = 'GitHub'; ModuleVersion = '0.13.2' } [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSReviewUnusedParameter', '', Scope = 'Function', Justification = 'LogGroup - Scoping affects the variables line of sight.' diff --git a/scripts/helpers/Build/Build-PSModuleManifest.ps1 b/scripts/helpers/Build/Build-PSModuleManifest.ps1 index 62260198..e3ae0f29 100644 --- a/scripts/helpers/Build/Build-PSModuleManifest.ps1 +++ b/scripts/helpers/Build/Build-PSModuleManifest.ps1 @@ -11,8 +11,6 @@ Build-PSModuleManifest -SourceFolderPath 'C:\MyModule\src\MyModule' -OutputFolderPath 'C:\MyModule\build\MyModule' #> [CmdletBinding()] - #Requires -Modules @{ ModuleName = 'GitHub'; ModuleVersion = '0.13.2' } - #Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' } [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSAvoidLongLines', '', Scope = 'Function', Justification = 'Easier to read the multi ternery operators in a single line.' @@ -60,10 +58,10 @@ $manifest.ModuleVersion = '999.0.0' Write-Host "[ModuleVersion] - [$($manifest.ModuleVersion)]" - $manifest.Author = $manifest.Keys -contains 'Author' ? ($manifest.Author | IsNotNullOrEmpty) ? $manifest.Author : $env:GITHUB_REPOSITORY_OWNER : $env:GITHUB_REPOSITORY_OWNER + $manifest.Author = $manifest.Keys -contains 'Author' ? (-not [string]::IsNullOrEmpty($manifest.Author)) ? $manifest.Author : $env:GITHUB_REPOSITORY_OWNER : $env:GITHUB_REPOSITORY_OWNER Write-Host "[Author] - [$($manifest.Author)]" - $manifest.CompanyName = $manifest.Keys -contains 'CompanyName' ? ($manifest.CompanyName | IsNotNullOrEmpty) ? $manifest.CompanyName : $env:GITHUB_REPOSITORY_OWNER : $env:GITHUB_REPOSITORY_OWNER + $manifest.CompanyName = $manifest.Keys -contains 'CompanyName' ? (-not [string]::IsNullOrEmpty($manifest.CompanyName)) ? $manifest.CompanyName : $env:GITHUB_REPOSITORY_OWNER : $env:GITHUB_REPOSITORY_OWNER Write-Host "[CompanyName] - [$($manifest.CompanyName)]" $year = Get-Date -Format 'yyyy' @@ -73,7 +71,7 @@ Write-Host "[Copyright] - [$($manifest.Copyright)]" $repoDescription = gh repo view --json description | ConvertFrom-Json | Select-Object -ExpandProperty description - $manifest.Description = $manifest.Keys -contains 'Description' ? ($manifest.Description | IsNotNullOrEmpty) ? $manifest.Description : $repoDescription : $repoDescription + $manifest.Description = $manifest.Keys -contains 'Description' ? (-not [string]::IsNullOrEmpty($manifest.Description)) ? $manifest.Description : $repoDescription : $repoDescription Write-Host "[Description] - [$($manifest.Description)]" $manifest.PowerShellHostName = $manifest.Keys -contains 'PowerShellHostName' ? -not [string]::IsNullOrEmpty($manifest.PowerShellHostName) ? $manifest.PowerShellHostName : $null : $null diff --git a/scripts/helpers/Build/Build-PSModuleRootModule.ps1 b/scripts/helpers/Build/Build-PSModuleRootModule.ps1 index adef93a7..b3b9ff16 100644 --- a/scripts/helpers/Build/Build-PSModuleRootModule.ps1 +++ b/scripts/helpers/Build/Build-PSModuleRootModule.ps1 @@ -1,7 +1,4 @@ -#Requires -Modules @{ ModuleName = 'GitHub'; ModuleVersion = '0.13.2' } -#Requires -Modules @{ ModuleName = 'Hashtable'; ModuleVersion = '1.1.1' } - -function Build-PSModuleRootModule { +function Build-PSModuleRootModule { <# .SYNOPSIS Compiles the module root module files. diff --git a/scripts/helpers/Build/Get-PSModuleAliasesToExport.ps1 b/scripts/helpers/Build/Get-PSModuleAliasesToExport.ps1 index 5c8a990e..adc21d13 100644 --- a/scripts/helpers/Build/Get-PSModuleAliasesToExport.ps1 +++ b/scripts/helpers/Build/Get-PSModuleAliasesToExport.ps1 @@ -10,11 +10,8 @@ Get-PSModuleAliasesToExport -SourceFolderPath 'C:\MyModule\src\MyModule' #> [CmdletBinding()] - #Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' } - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSAvoidUsingWriteHost', '', Scope = 'Function', - Justification = 'Want to just write to the console, not the pipeline.' - )] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Scope = 'Function', Justification = 'Want to just write to the console, not the pipeline.')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Scope = 'Function', Justification = 'Contains long links.')] param( # Path to the folder where the module source code is located. [Parameter(Mandatory)] @@ -30,7 +27,7 @@ $manifest = Get-ModuleManifest -Path $manifestFilePath -Verbose:$false Write-Host "[$manifestPropertyName]" - $aliasesToExport = (($manifest.AliasesToExport).count -eq 0) -or ($manifest.AliasesToExport | IsNullOrEmpty) ? '*' : $manifest.AliasesToExport + $aliasesToExport = (($manifest.AliasesToExport).count -eq 0) -or [string]::IsNullOrEmpty($manifest.AliasesToExport) ? '*' : $manifest.AliasesToExport $aliasesToExport | ForEach-Object { Write-Host "[$manifestPropertyName] - [$_]" } diff --git a/scripts/helpers/Build/Get-PSModuleClassesToExport.ps1 b/scripts/helpers/Build/Get-PSModuleClassesToExport.ps1 index b01219a6..4b541f63 100644 --- a/scripts/helpers/Build/Get-PSModuleClassesToExport.ps1 +++ b/scripts/helpers/Build/Get-PSModuleClassesToExport.ps1 @@ -17,7 +17,7 @@ .NOTES Inspired by [about_Classes | Exporting classes with type accelerators](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_classes?view=powershell-7.4#exporting-classes-with-type-accelerators) #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains long links.')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Scope = 'Function', Justification = 'Contains long links.')] [CmdletBinding()] param ( # The path to the module root folder. diff --git a/scripts/helpers/Build/Get-PSModuleCmdletsToExport.ps1 b/scripts/helpers/Build/Get-PSModuleCmdletsToExport.ps1 index 2e07f8c3..1ac20e65 100644 --- a/scripts/helpers/Build/Get-PSModuleCmdletsToExport.ps1 +++ b/scripts/helpers/Build/Get-PSModuleCmdletsToExport.ps1 @@ -10,11 +10,8 @@ Get-PSModuleCmdletsToExport -SourceFolderPath 'C:\MyModule\src\MyModule' #> [CmdletBinding()] - #Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' } - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSAvoidUsingWriteHost', '', Scope = 'Function', - Justification = 'Want to just write to the console, not the pipeline.' - )] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Scope = 'Function', Justification = 'Want to just write to the console, not the pipeline.')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Scope = 'Function', Justification = 'Contains long links.')] param( # Path to the folder where the module source code is located. [Parameter(Mandatory)] @@ -30,7 +27,7 @@ $manifest = Get-ModuleManifest -Path $manifestFilePath -Verbose:$false Write-Host "[$manifestPropertyName]" - $cmdletsToExport = (($manifest.CmdletsToExport).count -eq 0) -or ($manifest.CmdletsToExport | IsNullOrEmpty) ? '' : $manifest.CmdletsToExport + $cmdletsToExport = (($manifest.CmdletsToExport).count -eq 0) -or [string]::IsNullOrEmpty($manifest.CmdletsToExport) ? '' : $manifest.CmdletsToExport $cmdletsToExport | ForEach-Object { Write-Host "[$manifestPropertyName] - [$_]" } diff --git a/scripts/helpers/Build/Get-PSModuleFunctionsToExport.ps1 b/scripts/helpers/Build/Get-PSModuleFunctionsToExport.ps1 index 03671c89..3d64494d 100644 --- a/scripts/helpers/Build/Get-PSModuleFunctionsToExport.ps1 +++ b/scripts/helpers/Build/Get-PSModuleFunctionsToExport.ps1 @@ -10,10 +10,8 @@ Get-PSModuleFunctionsToExport -SourceFolderPath 'C:\MyModule\src\MyModule' #> [CmdletBinding()] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSAvoidUsingWriteHost', '', Scope = 'Function', - Justification = 'Want to just write to the console, not the pipeline.' - )] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Scope = 'Function', Justification = 'Want to just write to the console, not the pipeline.')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Scope = 'Function', Justification = 'Contains long links.')] [OutputType([array])] param( # Path to the folder where the module source code is located. diff --git a/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 b/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 index 887b73cf..65608df8 100644 --- a/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 +++ b/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 @@ -15,8 +15,6 @@ 'PSAvoidUsingWriteHost', '', Scope = 'Function', Justification = 'Want to just write to the console, not the pipeline.' )] - #Requires -Modules @{ ModuleName = 'GitHub'; ModuleVersion = '0.13.2' } - #Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' } [CmdletBinding()] param( # Name of the module. diff --git a/scripts/main.ps1 b/scripts/main.ps1 index c760ab99..af18b668 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -5,8 +5,6 @@ [CmdletBinding()] param() -#Requires -Modules Utilities - $path = (Join-Path -Path $PSScriptRoot -ChildPath 'helpers') | Get-Item | Resolve-Path -Relative LogGroup "Loading helper scripts from [$path]" { Get-ChildItem -Path $path -Filter '*.ps1' -Recurse | Resolve-Path -Relative | ForEach-Object { From 46d8c8c0a0ac8969052799fafbb86bc6f739c1ac Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 2 Jun 2025 02:31:58 +0200 Subject: [PATCH 7/8] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20Build-?= =?UTF-8?q?PSModule=20action=20without=20Github-Script=20(#115)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description This pull request includes updates to the PowerShell module build process and related scripts, focusing on improving compatibility with GitHub Actions and simplifying output handling. The changes primarily affect the `action.yml` file and several PowerShell scripts. ### Updates to GitHub Actions configuration: * [`action.yml`](diffhunk://#diff-1243c5424efaaa19bd8e813c5e6f6da46316e63761421b3e5f5c8ced9a36e6b6L43-R55): Replaced the `uses` directive for running PowerShell scripts with the `shell: pwsh` option and updated the `run` block to execute the build script directly. Simplified artifact upload by changing the path reference to use `steps.build.outputs.ModuleOutputFolderPath` instead of parsing JSON. ### Updates to script handling: * [`scripts/main.ps1`](diffhunk://#diff-dc2e5a659836b1b73abb03421c567f5018c2755677c4a0aa764cb26117b68011R16-L23): Added a new environment variable `$env:GITHUB_REPOSITORY_NAME` derived from `$env:GITHUB_REPOSITORY` for repository name extraction. Replaced `Set-GitHubOutput` calls with direct appending to `$env:GITHUB_OUTPUT` for compatibility with GitHub Actions. [[1]](diffhunk://#diff-dc2e5a659836b1b73abb03421c567f5018c2755677c4a0aa764cb26117b68011R16-L23) [[2]](diffhunk://#diff-dc2e5a659836b1b73abb03421c567f5018c2755677c4a0aa764cb26117b68011L53-R53) ### Updates to URI generation: * [`scripts/helpers/Build/Build-PSModuleManifest.ps1`](diffhunk://#diff-50cfb011f5c8aeef8145003927ec3e5edfdf26e5d417bcee6e441517c07454f9L390-R390): Simplified the generation of `LicenseUri` and `IconUri` by using `$env:GITHUB_REPOSITORY` directly instead of combining `$env:GITHUB_REPOSITORY_OWNER` and `$env:GITHUB_REPOSITORY_NAME`. [[1]](diffhunk://#diff-50cfb011f5c8aeef8145003927ec3e5edfdf26e5d417bcee6e441517c07454f9L390-R390) [[2]](diffhunk://#diff-50cfb011f5c8aeef8145003927ec3e5edfdf26e5d417bcee6e441517c07454f9L406-R406) ## Type of change - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas --- README.md | 15 +++------ action.yml | 32 ++++--------------- scripts/helpers/Build-PSModule.ps1 | 4 +-- scripts/helpers/Build/Build-PSModuleBase.ps1 | 4 +-- .../helpers/Build/Build-PSModuleManifest.ps1 | 16 +++++----- .../Build/Build-PSModuleRootModule.ps1 | 12 +++---- ...Update-PSModuleManifestAliasesToExport.ps1 | 2 +- scripts/main.ps1 | 14 ++++---- 8 files changed, 37 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index 048a291f..7cc352da 100644 --- a/README.md +++ b/README.md @@ -26,16 +26,11 @@ This step lets you add custom build logic to process or modify the module conten ## Usage -| Name | Description | Required | Default | -| --------------------| ----------------------------------------------------------------------------------------------- | -------- | ----------------- | -| `Name` | Name of the module to process. | `false` | | -| `Path` | Path to the folder where the modules are located. | `false` | `src` | -| `ModulesOutputPath` | Path to the folder where the built modules are outputted. | `false` | `outputs/modules` | -| `Debug` | Enable debug output. | `false` | `'false'` | -| `Verbose` | Enable verbose output. | `false` | `'false'` | -| `Version` | Specifies the version of the GitHub module to be installed. The value must be an exact version. | `false` | | -| `Prerelease` | Allow prerelease versions if available. | `false` | `'false'` | -| `WorkingDirectory` | The working directory where the script runs. | `false` | `'.'` | +| Name | Description | Required | Default | +| ------------------ | ------------------------------------------------------ | -------- | --------- | +| `Name` | Name of the module to process. | `false` | | +| `ArtifactName` | Name of the artifact to upload. | `false` | `module` | +| `WorkingDirectory` | The working directory where the script will run from. | `false` | `'.'` | ## Expected repository structure diff --git a/action.yml b/action.yml index 62ee0287..5117c561 100644 --- a/action.yml +++ b/action.yml @@ -13,21 +13,6 @@ inputs: description: Name of the artifact to upload. required: false default: module - Debug: - description: Enable debug output. - required: false - default: 'false' - Verbose: - description: Enable verbose output. - required: false - default: 'false' - Version: - description: Specifies the version of the GitHub module to be installed. The value must be an exact version. - required: false - Prerelease: - description: Allow prerelease versions if available. - required: false - default: 'false' WorkingDirectory: description: The working directory where the script will run from. required: false @@ -40,24 +25,19 @@ runs: uses: PSModule/Install-PSModuleHelpers@v1 - name: Run Build-PSModule - uses: PSModule/GitHub-Script@v1 + shell: pwsh id: build + working-directory: ${{ inputs.WorkingDirectory }} env: PSMODULE_BUILD_PSMODULE_INPUT_Name: ${{ inputs.Name }} - with: - Debug: ${{ inputs.Debug }} - Prerelease: ${{ inputs.Prerelease }} - Verbose: ${{ inputs.Verbose }} - Version: ${{ inputs.Version }} - WorkingDirectory: ${{ inputs.WorkingDirectory }} - Script: | - # Build-PSModule - ${{ github.action_path }}/scripts/main.ps1 + run: | + # Build-PSModule + ${{ github.action_path }}/scripts/main.ps1 - name: Upload module artifact uses: actions/upload-artifact@v4 with: name: ${{ inputs.ArtifactName }} - path: ${{ fromJson(steps.build.outputs.result).moduleOutputFolderPath }} + path: ${{ steps.build.outputs.ModuleOutputFolderPath }} if-no-files-found: error retention-days: 1 diff --git a/scripts/helpers/Build-PSModule.ps1 b/scripts/helpers/Build-PSModule.ps1 index 29a4d8ea..15f1ac79 100644 --- a/scripts/helpers/Build-PSModule.ps1 +++ b/scripts/helpers/Build-PSModule.ps1 @@ -30,7 +30,7 @@ [string] $ModuleOutputFolderPath ) - LogGroup "Building module [$ModuleName]" { + Set-GitHubLogGroup "Building module [$ModuleName]" { $moduleSourceFolder = Get-Item -Path $ModuleSourceFolderPath $moduleOutputFolder = New-Item -Path $ModuleOutputFolderPath -Name $ModuleName -ItemType Directory -Force [pscustomobject]@{ @@ -44,7 +44,7 @@ Build-PSModuleRootModule -ModuleName $ModuleName -ModuleOutputFolder $moduleOutputFolder Update-PSModuleManifestAliasesToExport -ModuleName $ModuleName -ModuleSourceFolder $moduleSourceFolder -ModuleOutputFolder $moduleOutputFolder - LogGroup 'Build manifest file - Final Result' { + Set-GitHubLogGroup 'Build manifest file - Final Result' { $outputManifestPath = Join-Path -Path $ModuleOutputFolder -ChildPath "$ModuleName.psd1" Show-FileContent -Path $outputManifestPath } diff --git a/scripts/helpers/Build/Build-PSModuleBase.ps1 b/scripts/helpers/Build/Build-PSModuleBase.ps1 index 4a0b9035..cc95352b 100644 --- a/scripts/helpers/Build/Build-PSModuleBase.ps1 +++ b/scripts/helpers/Build/Build-PSModuleBase.ps1 @@ -33,7 +33,7 @@ [System.IO.DirectoryInfo] $ModuleOutputFolder ) - LogGroup 'Build base' { + Set-GitHubLogGroup 'Build base' { $relModuleSourceFolder = $ModuleSourceFolder | Resolve-Path -Relative $relModuleOutputFolder = $ModuleOutputFolder | Resolve-Path -Relative Write-Host "Copying files from [$relModuleSourceFolder] to [$relModuleOutputFolder]" @@ -41,7 +41,7 @@ $null = New-Item -Path $ModuleOutputFolder -Name "$ModuleName.psm1" -ItemType File -Force } - LogGroup 'Build base - Result' { + Set-GitHubLogGroup 'Build base - Result' { Get-ChildItem -Path $ModuleOutputFolder -Recurse -Force | Resolve-Path -Relative | Sort-Object } } diff --git a/scripts/helpers/Build/Build-PSModuleManifest.ps1 b/scripts/helpers/Build/Build-PSModuleManifest.ps1 index e3ae0f29..56aab2dd 100644 --- a/scripts/helpers/Build/Build-PSModuleManifest.ps1 +++ b/scripts/helpers/Build/Build-PSModuleManifest.ps1 @@ -33,7 +33,7 @@ [System.IO.DirectoryInfo] $ModuleOutputFolder ) - LogGroup 'Build manifest file' { + Set-GitHubLogGroup 'Build manifest file' { $sourceManifestFilePath = Join-Path -Path $ModuleOutputFolder -ChildPath "$ModuleName.psd1" Write-Host "[SourceManifestFilePath] - [$sourceManifestFilePath]" if (-not (Test-Path -Path $sourceManifestFilePath)) { @@ -387,7 +387,7 @@ #> Write-Host '[LicenseUri]' - $licenseUri = "https://github.com/$env:GITHUB_REPOSITORY_OWNER/$env:GITHUB_REPOSITORY_NAME/blob/main/LICENSE" + $licenseUri = "https://github.com/$env:GITHUB_REPOSITORY/blob/main/LICENSE" $manifest.LicenseUri = $PSData.Keys -contains 'LicenseUri' ? $null -ne $PSData.LicenseUri ? $PSData.LicenseUri : $licenseUri : $licenseUri Write-Host "[LicenseUri] - [$($manifest.LicenseUri)]" if ([string]::IsNullOrEmpty($manifest.LicenseUri)) { @@ -403,7 +403,7 @@ } Write-Host '[IconUri]' - $iconUri = "https://raw.githubusercontent.com/$env:GITHUB_REPOSITORY_OWNER/$env:GITHUB_REPOSITORY_NAME/main/icon/icon.png" + $iconUri = "https://raw.githubusercontent.com/$env:GITHUB_REPOSITORY/main/icon/icon.png" $manifest.IconUri = $PSData.Keys -contains 'IconUri' ? $null -ne $PSData.IconUri ? $PSData.IconUri : $iconUri : $iconUri Write-Host "[IconUri] - [$($manifest.IconUri)]" if ([string]::IsNullOrEmpty($manifest.IconUri)) { @@ -442,23 +442,23 @@ New-ModuleManifest -Path $outputManifestPath @manifest } - LogGroup 'Build manifest file - Result - Before format' { + Set-GitHubLogGroup 'Build manifest file - Result - Before format' { Show-FileContent -Path $outputManifestPath } - LogGroup 'Build manifest file - Format' { + Set-GitHubLogGroup 'Build manifest file - Format' { Set-ModuleManifest -Path $outputManifestPath } - LogGroup 'Build manifest file - Result - After format' { + Set-GitHubLogGroup 'Build manifest file - Result - After format' { Show-FileContent -Path $outputManifestPath } - LogGroup 'Build manifest file - Validate - Install module dependencies' { + Set-GitHubLogGroup 'Build manifest file - Validate - Install module dependencies' { Resolve-PSModuleDependency -ManifestFilePath $outputManifestPath } - LogGroup 'Build manifest file - Validate - Test manifest file' { + Set-GitHubLogGroup 'Build manifest file - Validate - Test manifest file' { Test-ModuleManifest -Path $outputManifestPath | Format-List | Out-String } } diff --git a/scripts/helpers/Build/Build-PSModuleRootModule.ps1 b/scripts/helpers/Build/Build-PSModuleRootModule.ps1 index b3b9ff16..3b1bfbd8 100644 --- a/scripts/helpers/Build/Build-PSModuleRootModule.ps1 +++ b/scripts/helpers/Build/Build-PSModuleRootModule.ps1 @@ -51,7 +51,7 @@ # Get the path separator for the current OS $pathSeparator = [System.IO.Path]::DirectorySeparatorChar - LogGroup 'Build root module' { + Set-GitHubLogGroup 'Build root module' { $rootModuleFile = New-Item -Path $ModuleOutputFolder -Name "$ModuleName.psm1" -Force #region - Analyze source files @@ -254,26 +254,26 @@ Export-ModuleMember @exports } - LogGroup 'Build root module - Result - Before format' { + Set-GitHubLogGroup 'Build root module - Result - Before format' { Write-Host (Show-FileContent -Path $rootModuleFile) } - LogGroup 'Build root module - Format' { + Set-GitHubLogGroup 'Build root module - Format' { $AllContent = Get-Content -Path $rootModuleFile -Raw $settings = Join-Path -Path $PSScriptRoot 'PSScriptAnalyzer.Tests.psd1' Invoke-Formatter -ScriptDefinition $AllContent -Settings $settings | Out-File -FilePath $rootModuleFile -Encoding utf8BOM -Force } - LogGroup 'Build root module - Result - After format' { + Set-GitHubLogGroup 'Build root module - Result - After format' { Write-Host (Show-FileContent -Path $rootModuleFile) } - # LogGroup 'Build root module - Validate - Import' { + # Set-GitHubLogGroup 'Build root module - Validate - Import' { # Install-PSModule -Path $ModuleOutputFolder # } - # LogGroup 'Build root module - Validate - File list' { + # Set-GitHubLogGroup 'Build root module - Validate - File list' { # Get-ChildItem -Path $ModuleOutputFolder -Recurse -Force | Resolve-Path -Relative | Sort-Object # } } diff --git a/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 b/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 index 65608df8..5597cd1e 100644 --- a/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 +++ b/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 @@ -29,7 +29,7 @@ [Parameter(Mandatory)] [System.IO.DirectoryInfo] $ModuleOutputFolder ) - LogGroup 'Updating aliases to export in module manifest' { + Set-GitHubLogGroup 'Updating aliases to export in module manifest' { Write-Host "Module name: [$ModuleName]" Write-Host "Module output folder: [$ModuleSourceFolder]" diff --git a/scripts/main.ps1 b/scripts/main.ps1 index af18b668..f5f6fba5 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -6,21 +6,21 @@ param() $path = (Join-Path -Path $PSScriptRoot -ChildPath 'helpers') | Get-Item | Resolve-Path -Relative -LogGroup "Loading helper scripts from [$path]" { +Set-GitHubLogGroup "Loading helper scripts from [$path]" { Get-ChildItem -Path $path -Filter '*.ps1' -Recurse | Resolve-Path -Relative | ForEach-Object { Write-Host "$_" . $_ } } -LogGroup 'Loading inputs' { +$env:GITHUB_REPOSITORY_NAME = $env:GITHUB_REPOSITORY -replace '.+/' + +Set-GitHubLogGroup 'Loading inputs' { $moduleName = if ([string]::IsNullOrEmpty($env:PSMODULE_BUILD_PSMODULE_INPUT_Name)) { $env:GITHUB_REPOSITORY_NAME } else { $env:PSMODULE_BUILD_PSMODULE_INPUT_Name } - Set-GitHubOutput -Name ModuleName -Value $moduleName - $sourceFolderPath = Resolve-Path -Path 'src' | Select-Object -ExpandProperty Path $moduleOutputFolderPath = Join-Path $pwd -ChildPath 'outputs/module' [pscustomobject]@{ @@ -30,14 +30,14 @@ LogGroup 'Loading inputs' { } | Format-List | Out-String } -LogGroup 'Build local scripts' { +Set-GitHubLogGroup 'Build local scripts' { Write-Host 'Execution order:' $scripts = Get-ChildItem -Filter '*build.ps1' -Recurse | Sort-Object -Property Name | Resolve-Path -Relative $scripts | ForEach-Object { Write-Host " - $_" } $scripts | ForEach-Object { - LogGroup "Build local scripts - [$_]" { + Set-GitHubLogGroup "Build local scripts - [$_]" { . $_ } } @@ -50,6 +50,6 @@ $params = @{ } Build-PSModule @params -Set-GithubOutput -Name ModuleOutputFolderPath -Value $moduleOutputFolderPath +"ModuleOutputFolderPath=$moduleOutputFolderPath" >> $env:GITHUB_OUTPUT exit 0 From 108f15fb963eb339fc5356f552da64ccffbd3690 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 20 Aug 2025 12:57:25 +0200 Subject: [PATCH 8/8] Bump actions/checkout from 4 to 5 (#116) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5.
Release notes

Sourced from actions/checkout's releases.

v5.0.0

What's Changed

⚠️ Minimum Compatible Runner Version

v2.327.1
Release Notes

Make sure your runner is updated to this version or newer to use this release.

Full Changelog: https://github.com/actions/checkout/compare/v4...v5.0.0

v4.3.0

What's Changed

New Contributors

Full Changelog: https://github.com/actions/checkout/compare/v4...v4.3.0

v4.2.2

What's Changed

Full Changelog: https://github.com/actions/checkout/compare/v4.2.1...v4.2.2

v4.2.1

What's Changed

New Contributors

Full Changelog: https://github.com/actions/checkout/compare/v4.2.0...v4.2.1

... (truncated)

Changelog

Sourced from actions/checkout's changelog.

Changelog

V5.0.0

V4.3.0

v4.2.2

v4.2.1

v4.2.0

v4.1.7

v4.1.6

v4.1.5

v4.1.4

v4.1.3

... (truncated)

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions/checkout&package-manager=github_actions&previous-version=4&new-version=5)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/Action-Test.yml | 6 +++--- .github/workflows/Auto-Release.yml | 2 +- .github/workflows/Linter.yml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 9b426109..54e91a3c 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -23,7 +23,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repo - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Action-Test uses: ./ @@ -37,7 +37,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repo - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Action-Test uses: ./ @@ -51,7 +51,7 @@ jobs: runs-on: ubuntu-24.04 steps: - name: Checkout repo - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Action-Test uses: ./ diff --git a/.github/workflows/Auto-Release.yml b/.github/workflows/Auto-Release.yml index 680da5c0..50a5a410 100644 --- a/.github/workflows/Auto-Release.yml +++ b/.github/workflows/Auto-Release.yml @@ -26,7 +26,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout Code - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Auto-Release uses: PSModule/Auto-Release@v1 diff --git a/.github/workflows/Linter.yml b/.github/workflows/Linter.yml index 1f677cbd..94f34b02 100644 --- a/.github/workflows/Linter.yml +++ b/.github/workflows/Linter.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repo - uses: actions/checkout@v4 + uses: actions/checkout@v5 with: fetch-depth: 0