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 38a09542..54e91a3c 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -23,32 +23,39 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repo - uses: actions/checkout@v4 + uses: actions/checkout@v5 - - name: Initialize environment - uses: PSModule/Initialize-PSModule@main + - name: Action-Test + uses: ./ + with: + Name: PSModuleTest + ArtifactName: PSModuleTestDefault + WorkingDirectory: tests/srcTestRepo + + ActionTestMinimal: + name: Action-Test - [Minimal] + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v5 - name: Action-Test uses: ./ with: Name: PSModuleTest - Path: tests/src - ModulesOutputPath: tests/outputs/modules + ArtifactName: PSModuleTestMinimal + WorkingDirectory: tests/srcMinimalTestRepo ActionTestWithManifest: name: Action-Test - [DefaultWithManifest] runs-on: ubuntu-24.04 steps: - name: Checkout repo - uses: actions/checkout@v4 - - - name: Initialize environment - uses: PSModule/Initialize-PSModule@main + uses: actions/checkout@v5 - name: Action-Test 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..50a5a410 100644 --- a/.github/workflows/Auto-Release.yml +++ b/.github/workflows/Auto-Release.yml @@ -26,11 +26,9 @@ 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 - env: - GITHUB_TOKEN: ${{ github.token }} # Used for GitHub CLI authentication with: IncrementalPrerelease: false 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 diff --git a/README.md b/README.md index a5043243..7cc352da 100644 --- a/README.md +++ b/README.md @@ -22,20 +22,19 @@ 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 -| 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` | | +| `ArtifactName` | Name of the artifact to upload. | `false` | `module` | +| `WorkingDirectory` | The working directory where the script will run from. | `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 +89,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 +142,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 +151,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:** diff --git a/action.yml b/action.yml index cb7314ca..5117c561 100644 --- a/action.yml +++ b/action.yml @@ -9,56 +9,35 @@ 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: - 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. + WorkingDirectory: + description: The working directory where the script will run from. required: false - Prerelease: - description: Allow prerelease versions if available. - required: false - default: 'false' + default: '.' runs: using: composite steps: + - name: Install-PSModuleHelpers + uses: PSModule/Install-PSModuleHelpers@v1 + - name: Run Build-PSModule - uses: PSModule/GitHub-Script@v1 + shell: pwsh + id: build + working-directory: ${{ inputs.WorkingDirectory }} env: - GITHUB_ACTION_INPUT_Name: ${{ inputs.Name }} - GITHUB_ACTION_INPUT_Path: ${{ inputs.Path }} - GITHUB_ACTION_INPUT_ModulesOutputPath: ${{ inputs.ModulesOutputPath }} - with: - Debug: ${{ inputs.Debug }} - Prerelease: ${{ inputs.Prerelease }} - Verbose: ${{ inputs.Verbose }} - Version: ${{ inputs.Version }} - Script: | - # Build-PSModule - ${{ github.action_path }}\scripts\main.ps1 + PSMODULE_BUILD_PSMODULE_INPUT_Name: ${{ inputs.Name }} + run: | + # Build-PSModule + ${{ 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: ${{ 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 ef5c67cb..15f1ac79 100644 --- a/scripts/helpers/Build-PSModule.ps1 +++ b/scripts/helpers/Build-PSModule.ps1 @@ -6,9 +6,8 @@ .DESCRIPTION Builds a module. #> + [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.' @@ -28,28 +27,24 @@ # 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 - } + Set-GitHubLogGroup "Building module [$ModuleName]" { $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' { + 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 ffb664dd..cc95352b 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.' @@ -34,13 +33,15 @@ [System.IO.DirectoryInfo] $ModuleOutputFolder ) - 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 + Set-GitHubLogGroup 'Build base' { + $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 + 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 2a611f0d..56aab2dd 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.' @@ -35,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)) { @@ -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 @@ -363,6 +361,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') { @@ -388,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)) { @@ -404,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)) { @@ -443,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-ModuleManifest -Path $outputManifestPath -Verbose + 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' { - Test-ModuleManifest -Path $outputManifestPath + 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 a388e673..3b1bfbd8 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. @@ -54,7 +51,7 @@ function Build-PSModuleRootModule { # 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 @@ -115,7 +112,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 +127,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 +157,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 +237,7 @@ Write-Debug "[`$scriptName] - $relativePath - Done" $exportsString = $exports | Format-Hashtable - Write-Host ($exportsString | Out-String) + $exportsString | Out-String $params = @{ Path = $rootModuleFile @@ -241,27 +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' { - Add-PSModulePath -Path (Split-Path -Path $ModuleOutputFolder -Parent) - Import-PSModule -Path $ModuleOutputFolder -ModuleName $ModuleName - } + # Set-GitHubLogGroup '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 - } + # 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/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/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/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/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..5597cd1e 100644 --- a/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 +++ b/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 @@ -15,29 +15,83 @@ '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. [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' { + Set-GitHubLogGroup '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..f5f6fba5 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -5,50 +5,51 @@ [CmdletBinding()] param() -#Requires -Modules Utilities - $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' { - $moduleName = ($env:GITHUB_ACTION_INPUT_Name | IsNullOrEmpty) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_Name - Write-Host "Module name: [$moduleName]" +$env:GITHUB_REPOSITORY_NAME = $env:GITHUB_REPOSITORY -replace '.+/' - $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." +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 } - - $modulesOutputFolderPath = Join-Path $env:GITHUB_WORKSPACE $env:GITHUB_ACTION_INPUT_ModulesOutputPath - Write-Host "Modules output path: [$modulesOutputFolderPath]" + $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' { +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 - [$_]" { . $_ } } } $params = @{ - ModuleName = $moduleName - ModuleSourceFolderPath = $moduleSourceFolderPath - ModulesOutputFolderPath = $modulesOutputFolderPath + ModuleName = $moduleName + ModuleSourceFolderPath = $sourceFolderPath + ModuleOutputFolderPath = $moduleOutputFolderPath } - Build-PSModule @params + +"ModuleOutputFolderPath=$moduleOutputFolderPath" >> $env:GITHUB_OUTPUT + +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/srcWithManifest/functions/public/Test-PSModuleTest.ps1 b/tests/srcTestRepo/src/functions/public/Test-PSModuleTest.ps1 similarity index 100% rename from tests/srcWithManifest/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/srcWithManifestTestRepo/src/functions/public/Test-PSModuleTest.ps1 b/tests/srcWithManifestTestRepo/src/functions/public/Test-PSModuleTest.ps1 new file mode 100644 index 00000000..26be2b9b --- /dev/null +++ b/tests/srcWithManifestTestRepo/src/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!" +} 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