diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index cba9f20..a334e86 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 ec157c9..680da5c 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 a504324..a43ce3f 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 cb7314c..62ee028 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 ef5c67c..ea85459 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 ffb664d..a0b2c3d 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 2a611f0..6226019 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 a388e67..adef93a 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 3356890..0000000 --- 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 79fa949..0000000 --- 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 accf607..0000000 --- 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 47d64e4..887b73c 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 d831ebe..c760ab9 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 86beb12..eae698a 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 86beb12..f544230 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