diff --git a/.github/dependabot.yml b/.github/dependabot.yml index f57e1e95..53188fef 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -7,5 +7,8 @@ version: 2 updates: - package-ecosystem: github-actions # See documentation for possible values directory: / # Location of package manifests + labels: + - dependencies + - github-actions schedule: interval: weekly diff --git a/.github/linters/.jscpd.json b/.github/linters/.jscpd.json index 7cc00e60..f734bf16 100644 --- a/.github/linters/.jscpd.json +++ b/.github/linters/.jscpd.json @@ -6,9 +6,7 @@ "ignore": [ "**/tests/**", "**/.github/workflows/Action-Test.yml", - "**/scripts/helpers/Build/Build-PSModuleManifest.ps1", - "**/scripts/helpers/Build/Build-PSModuleRootModule.ps1", - "**/scripts/helpers/Build/PSScriptAnalyzer.Tests.psd1" + "**/scripts/helpers/**" ], "absolute": true } diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index a334e868..6799002c 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -23,10 +23,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repo - uses: actions/checkout@v4 - - - name: Initialize environment - uses: PSModule/Initialize-PSModule@v1 + uses: actions/checkout@v6 - name: Action-Test uses: ./ @@ -40,10 +37,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repo - uses: actions/checkout@v4 - - - name: Initialize environment - uses: PSModule/Initialize-PSModule@v1 + uses: actions/checkout@v6 - name: Action-Test uses: ./ @@ -57,10 +51,7 @@ jobs: runs-on: ubuntu-24.04 steps: - name: Checkout repo - uses: actions/checkout@v4 - - - name: Initialize environment - uses: PSModule/Initialize-PSModule@v1 + uses: actions/checkout@v6 - name: Action-Test uses: ./ diff --git a/.github/workflows/Auto-Release.yml b/.github/workflows/Auto-Release.yml index 680da5c0..976b40c7 100644 --- a/.github/workflows/Auto-Release.yml +++ b/.github/workflows/Auto-Release.yml @@ -26,7 +26,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout Code - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Auto-Release uses: PSModule/Auto-Release@v1 diff --git a/.github/workflows/Linter.yml b/.github/workflows/Linter.yml index 1f677cbd..19626293 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@v6 with: fetch-depth: 0 diff --git a/README.md b/README.md index 048a291f..479041a5 100644 --- a/README.md +++ b/README.md @@ -1,173 +1,3 @@ # Build-PSModule -This action "compiles" the module source code into an efficient PowerShell module that is ready to be published to the PowerShell Gallery. - -This GitHub Action is a part of the [PSModule framework](https://github.com/PSModule). It is recommended to use the [Process-PSModule workflow](https://github.com/PSModule/Process-PSModule) to automate the whole process of managing the PowerShell module. - -## Supported module types - -- Script module type -- Manifest module type - -## Supported practices and principles - -- [PowerShellGallery Publishing Guidelines and Best Practices](https://learn.microsoft.com/powershell/gallery/concepts/publishing-guidelines) are followed as much as possible. - -## How it works - -During the build process the following steps are performed: - -1. **Runs local build scripts:** Searches for any `*build.ps1` files anywhere in the repository. These scripts are executed in **alphabetical order by filename** (irrespective of their path). -This step lets you add custom build logic to process or modify the module contents before further build steps are performed. -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` | -| `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` | `'.'` | - -## 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. - -The root module file is the main file that is loaded when the module is imported. It is built from the source code files in the module folder in the following order: - -1. Adds a module header from `header.ps1` if it exists and removes the file from the module folder. -1. Adds a data loader that loads files from the `data` folder as variables in the module scope, if the folder exists. The variables are available using the `$script:` syntax. -1. Adds content from the following folders into the root module file. The files on the root of a folder are added before recursively processing subfolders (folders are processed in alphabetical order). Once a file is processed, it is removed from the module folder. - 1. `init` - 1. `classes/private` - 1. `classes/public` - 1. `functions/private` - 1. `functions/public` - 1. `variables/private` - 1. `variables/public` - 1. `*.ps1` on module root -1. Adds a `class` and `enum` exporter that exports the ones from the `classes/public` folder to the caller session, using [TypeAccelerators](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_classes?view=powershell-7.4#exporting-classes-with-type-accelerators). -1. Adds the `Export-ModuleMember` function to the end of the file, to ensure that only the functions, cmdlets, variables and aliases defined in the `public` folders are exported. - -## Module manifest - -The module manifest file describes the module and its contents. PowerShell uses it to load the module and its prerequisites. It also contains important metadata used by the PowerShell Gallery. If a file exists in the source code folder (`src`), it will be used as the base for the module manifest file. While most values in the module manifest are calculated during the build process, some values are preserved if specified in the source manifest file. - -During the module manifest build process the following steps are performed: - -1. Get the manifest file from the source code. If it does not exist, a new manifest file is created. -1. Generate and set the `RootModule` based on the module name. -1. Set a temporary `ModuleVersion` (this is updated during the release process by [Publish-PSModule](https://github.com/PSModule/Publish-PSModule)). -1. Set the `Author` and `CompanyName` based on the GitHub Owner. If a value exists in the source manifest file, that value is used. -1. Set the `Copyright` information based on a default text (`(c) 2024 >>OwnerName<<. All rights reserved.`) and includes the `Author`, `CompanyName` or both when applicable. If a value exists in the source manifest file, that value is used. -1. Set the `Description` based on the GitHub repository description. If a value exists in the source manifest file, that value is used. -1. Set various properties such as `PowerShellHostName`, `PowerShellHostVersion`, `DotNetFrameworkVersion`, `ClrVersion`, and `ProcessorArchitecture`. If values exist in the source manifest file, those values are used. -1. Get the list of files in the module source folder and set the `FileList` property in the manifest. -1. Get the list of required assemblies (`*.dll` files) from the `assemblies` and `modules` (depth = 1) folder and set the `RequiredAssemblies` property. -1. Get the list of nested modules (`*.psm1`, `*.ps1` and `*.dll` files one level down) from the `modules` folder and set the `NestedModules` property. -1. Get the list of scripts to process (`*.ps1` files) from the `scripts` folder and set the `ScriptsToProcess` property. This ensures that the scripts are loaded into the caller session. -1. Get the list of types to process by searching for `*.Types.ps1xml` files in the entire module source folder and set the `TypesToProcess` property. -1. Get the list of formats to process by searching for `*.Format.ps1xml` files in the entire module source folder and set the `FormatsToProcess` property. -1. Get the list of DSC resources to export by searching for `*.psm1` files in the `resources` folder and set the `DscResourcesToExport` property. -1. Get the list of functions, cmdlets, aliases, and variables from the respective `\public` folders and set the respective properties in the manifest. -1. Get the list of modules by searching for all `*.psm1` files in the entire module source folder (excluding the root module) and set the `ModuleList` property. -1. Gather information from source files to update `RequiredModules`, `PowerShellVersion`, and `CompatiblePSEditions` properties. -1. Gather additional information from the GitHub repository: - - `Tags` are generated from repository topics plus compatibility tags from the source files. - - `LicenseUri` is generated assuming there is a `LICENSE` file at the repository root. If a value exists in the source manifest file, that value is used. - - `ProjectUri` is set to the GitHub repository URL. If a value exists in the source manifest file, that value is used. - - `IconUri` is generated assuming there is an `icon.png` file in the `icon` folder at the repository root. If a value exists in the source manifest file, that value is used. -1. `ReleaseNotes` are not automated (could be set via PR or release description). -1. `PreRelease` is managed externally by [Publish-PSModule](https://github.com/PSModule/Publish-PSModule). -1. `RequireLicenseAcceptance` defaults to `false` unless specified in the source manifest. -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. - -### 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 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 #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 = @() # 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" - Description = "This is an experimental feature." - } - ) - } - OtherKeys = @{} - } - HelpInfoURI = '' # Not automated; preserved if provided in the source manifest. - DefaultCommandPrefix = '' # Not automated; preserved if provided in the source manifest. -} -``` - -## Permissions - -This action does not require any special permissions. - -## References - -**Module manifest:** - -- [about_Module_Manifests](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_module_manifests) -- [How to write a PowerShell module manifest](https://learn.microsoft.com/powershell/scripting/developer/module/how-to-write-a-powershell-module-manifest) -- [New-ModuleManifest](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/new-modulemanifest) -- [Update-ModuleManifest](https://learn.microsoft.com/powershell/module/powershellget/update-modulemanifest) -- [Package metadata values that impact the PowerShell Gallery UI](https://learn.microsoft.com/powershell/gallery/concepts/package-manifest-affecting-ui#powershell-gallery-feature-elements-controlled-by-the-module-manifest) -- [PowerShellGallery Publishing Guidelines and Best Practices](https://learn.microsoft.com/en-us/powershell/gallery/concepts/publishing-guidelines#tag-your-package-with-the-compatible-pseditions-and-platforms) - -**Modules:** - -- [PowerShell scripting performance considerations](https://learn.microsoft.com/powershell/scripting/dev-cross-plat/performance/script-authoring-considerations) -- [PowerShell module authoring considerations](https://learn.microsoft.com/powershell/scripting/dev-cross-plat/performance/module-authoring-considerations) +This GitHub Action is a part of the [PSModule framework](https://github.com/PSModule). diff --git a/action.yml b/action.yml index 62ee0287..a593fd52 100644 --- a/action.yml +++ b/action.yml @@ -1,9 +1,6 @@ -name: Build-PSModule (by PSModule) +name: Build-PSModule description: Build a PowerShell module to the PowerShell Gallery. author: PSModule -branding: - icon: package - color: gray-dark inputs: Name: @@ -13,21 +10,6 @@ inputs: description: Name of the artifact to upload. required: false default: module - Debug: - description: Enable debug output. - required: false - default: 'false' - Verbose: - description: Enable verbose output. - required: false - default: 'false' - Version: - description: Specifies the version of the GitHub module to be installed. The value must be an exact version. - required: false - Prerelease: - description: Allow prerelease versions if available. - required: false - default: 'false' WorkingDirectory: description: The working directory where the script will run from. required: false @@ -40,24 +22,19 @@ runs: uses: PSModule/Install-PSModuleHelpers@v1 - name: Run Build-PSModule - uses: PSModule/GitHub-Script@v1 + shell: pwsh id: build + working-directory: ${{ inputs.WorkingDirectory }} env: PSMODULE_BUILD_PSMODULE_INPUT_Name: ${{ inputs.Name }} - with: - Debug: ${{ inputs.Debug }} - Prerelease: ${{ inputs.Prerelease }} - Verbose: ${{ inputs.Verbose }} - Version: ${{ inputs.Version }} - WorkingDirectory: ${{ inputs.WorkingDirectory }} - Script: | - # Build-PSModule - ${{ github.action_path }}/scripts/main.ps1 + run: | + # Build-PSModule + ${{ github.action_path }}/scripts/main.ps1 - name: Upload module artifact - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v5 with: name: ${{ inputs.ArtifactName }} - path: ${{ fromJson(steps.build.outputs.result).moduleOutputFolderPath }} + path: ${{ steps.build.outputs.ModuleOutputFolderPath }} if-no-files-found: error retention-days: 1 diff --git a/scripts/helpers/Build-PSModule.ps1 b/scripts/helpers/Build-PSModule.ps1 index ea854597..15f1ac79 100644 --- a/scripts/helpers/Build-PSModule.ps1 +++ b/scripts/helpers/Build-PSModule.ps1 @@ -8,8 +8,6 @@ #> [OutputType([void])] [CmdletBinding()] - #Requires -Modules @{ ModuleName = 'GitHub'; ModuleVersion = '0.13.2' } - #Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' } [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSReviewUnusedParameter', '', Scope = 'Function', Justification = 'LogGroup - Scoping affects the variables line of sight.' @@ -32,7 +30,7 @@ [string] $ModuleOutputFolderPath ) - LogGroup "Building module [$ModuleName]" { + Set-GitHubLogGroup "Building module [$ModuleName]" { $moduleSourceFolder = Get-Item -Path $ModuleSourceFolderPath $moduleOutputFolder = New-Item -Path $ModuleOutputFolderPath -Name $ModuleName -ItemType Directory -Force [pscustomobject]@{ @@ -46,7 +44,7 @@ Build-PSModuleRootModule -ModuleName $ModuleName -ModuleOutputFolder $moduleOutputFolder Update-PSModuleManifestAliasesToExport -ModuleName $ModuleName -ModuleSourceFolder $moduleSourceFolder -ModuleOutputFolder $moduleOutputFolder - LogGroup 'Build manifest file - Final Result' { + Set-GitHubLogGroup 'Build manifest file - Final Result' { $outputManifestPath = Join-Path -Path $ModuleOutputFolder -ChildPath "$ModuleName.psd1" Show-FileContent -Path $outputManifestPath } diff --git a/scripts/helpers/Build/Build-PSModuleBase.ps1 b/scripts/helpers/Build/Build-PSModuleBase.ps1 index a0b2c3db..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,7 +33,7 @@ [System.IO.DirectoryInfo] $ModuleOutputFolder ) - LogGroup 'Build base' { + Set-GitHubLogGroup 'Build base' { $relModuleSourceFolder = $ModuleSourceFolder | Resolve-Path -Relative $relModuleOutputFolder = $ModuleOutputFolder | Resolve-Path -Relative Write-Host "Copying files from [$relModuleSourceFolder] to [$relModuleOutputFolder]" @@ -42,7 +41,7 @@ $null = New-Item -Path $ModuleOutputFolder -Name "$ModuleName.psm1" -ItemType File -Force } - LogGroup 'Build base - Result' { + Set-GitHubLogGroup 'Build base - Result' { Get-ChildItem -Path $ModuleOutputFolder -Recurse -Force | Resolve-Path -Relative | Sort-Object } } diff --git a/scripts/helpers/Build/Build-PSModuleManifest.ps1 b/scripts/helpers/Build/Build-PSModuleManifest.ps1 index 62260198..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 @@ -389,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)) { @@ -405,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)) { @@ -444,23 +442,23 @@ New-ModuleManifest -Path $outputManifestPath @manifest } - LogGroup 'Build manifest file - Result - Before format' { + Set-GitHubLogGroup 'Build manifest file - Result - Before format' { Show-FileContent -Path $outputManifestPath } - LogGroup 'Build manifest file - Format' { + Set-GitHubLogGroup 'Build manifest file - Format' { Set-ModuleManifest -Path $outputManifestPath } - LogGroup 'Build manifest file - Result - After format' { + Set-GitHubLogGroup 'Build manifest file - Result - After format' { Show-FileContent -Path $outputManifestPath } - LogGroup 'Build manifest file - Validate - Install module dependencies' { + Set-GitHubLogGroup 'Build manifest file - Validate - Install module dependencies' { Resolve-PSModuleDependency -ManifestFilePath $outputManifestPath } - LogGroup 'Build manifest file - Validate - Test manifest file' { + Set-GitHubLogGroup 'Build manifest file - Validate - Test manifest file' { Test-ModuleManifest -Path $outputManifestPath | Format-List | Out-String } } diff --git a/scripts/helpers/Build/Build-PSModuleRootModule.ps1 b/scripts/helpers/Build/Build-PSModuleRootModule.ps1 index adef93a7..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 @@ -257,26 +254,26 @@ Export-ModuleMember @exports } - LogGroup 'Build root module - Result - Before format' { + Set-GitHubLogGroup 'Build root module - Result - Before format' { Write-Host (Show-FileContent -Path $rootModuleFile) } - LogGroup 'Build root module - Format' { + Set-GitHubLogGroup 'Build root module - Format' { $AllContent = Get-Content -Path $rootModuleFile -Raw $settings = Join-Path -Path $PSScriptRoot 'PSScriptAnalyzer.Tests.psd1' Invoke-Formatter -ScriptDefinition $AllContent -Settings $settings | Out-File -FilePath $rootModuleFile -Encoding utf8BOM -Force } - LogGroup 'Build root module - Result - After format' { + Set-GitHubLogGroup 'Build root module - Result - After format' { Write-Host (Show-FileContent -Path $rootModuleFile) } - # LogGroup 'Build root module - Validate - Import' { + # Set-GitHubLogGroup 'Build root module - Validate - Import' { # Install-PSModule -Path $ModuleOutputFolder # } - # LogGroup 'Build root module - Validate - File list' { + # Set-GitHubLogGroup 'Build root module - Validate - File list' { # Get-ChildItem -Path $ModuleOutputFolder -Recurse -Force | Resolve-Path -Relative | Sort-Object # } } diff --git a/scripts/helpers/Build/Get-PSModuleAliasesToExport.ps1 b/scripts/helpers/Build/Get-PSModuleAliasesToExport.ps1 index 5c8a990e..adc21d13 100644 --- a/scripts/helpers/Build/Get-PSModuleAliasesToExport.ps1 +++ b/scripts/helpers/Build/Get-PSModuleAliasesToExport.ps1 @@ -10,11 +10,8 @@ Get-PSModuleAliasesToExport -SourceFolderPath 'C:\MyModule\src\MyModule' #> [CmdletBinding()] - #Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' } - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSAvoidUsingWriteHost', '', Scope = 'Function', - Justification = 'Want to just write to the console, not the pipeline.' - )] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Scope = 'Function', Justification = 'Want to just write to the console, not the pipeline.')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Scope = 'Function', Justification = 'Contains long links.')] param( # Path to the folder where the module source code is located. [Parameter(Mandatory)] @@ -30,7 +27,7 @@ $manifest = Get-ModuleManifest -Path $manifestFilePath -Verbose:$false Write-Host "[$manifestPropertyName]" - $aliasesToExport = (($manifest.AliasesToExport).count -eq 0) -or ($manifest.AliasesToExport | IsNullOrEmpty) ? '*' : $manifest.AliasesToExport + $aliasesToExport = (($manifest.AliasesToExport).count -eq 0) -or [string]::IsNullOrEmpty($manifest.AliasesToExport) ? '*' : $manifest.AliasesToExport $aliasesToExport | ForEach-Object { Write-Host "[$manifestPropertyName] - [$_]" } diff --git a/scripts/helpers/Build/Get-PSModuleClassesToExport.ps1 b/scripts/helpers/Build/Get-PSModuleClassesToExport.ps1 index b01219a6..4b541f63 100644 --- a/scripts/helpers/Build/Get-PSModuleClassesToExport.ps1 +++ b/scripts/helpers/Build/Get-PSModuleClassesToExport.ps1 @@ -17,7 +17,7 @@ .NOTES Inspired by [about_Classes | Exporting classes with type accelerators](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_classes?view=powershell-7.4#exporting-classes-with-type-accelerators) #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains long links.')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Scope = 'Function', Justification = 'Contains long links.')] [CmdletBinding()] param ( # The path to the module root folder. diff --git a/scripts/helpers/Build/Get-PSModuleCmdletsToExport.ps1 b/scripts/helpers/Build/Get-PSModuleCmdletsToExport.ps1 index 2e07f8c3..1ac20e65 100644 --- a/scripts/helpers/Build/Get-PSModuleCmdletsToExport.ps1 +++ b/scripts/helpers/Build/Get-PSModuleCmdletsToExport.ps1 @@ -10,11 +10,8 @@ Get-PSModuleCmdletsToExport -SourceFolderPath 'C:\MyModule\src\MyModule' #> [CmdletBinding()] - #Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' } - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSAvoidUsingWriteHost', '', Scope = 'Function', - Justification = 'Want to just write to the console, not the pipeline.' - )] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Scope = 'Function', Justification = 'Want to just write to the console, not the pipeline.')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Scope = 'Function', Justification = 'Contains long links.')] param( # Path to the folder where the module source code is located. [Parameter(Mandatory)] @@ -30,7 +27,7 @@ $manifest = Get-ModuleManifest -Path $manifestFilePath -Verbose:$false Write-Host "[$manifestPropertyName]" - $cmdletsToExport = (($manifest.CmdletsToExport).count -eq 0) -or ($manifest.CmdletsToExport | IsNullOrEmpty) ? '' : $manifest.CmdletsToExport + $cmdletsToExport = (($manifest.CmdletsToExport).count -eq 0) -or [string]::IsNullOrEmpty($manifest.CmdletsToExport) ? '' : $manifest.CmdletsToExport $cmdletsToExport | ForEach-Object { Write-Host "[$manifestPropertyName] - [$_]" } diff --git a/scripts/helpers/Build/Get-PSModuleFunctionsToExport.ps1 b/scripts/helpers/Build/Get-PSModuleFunctionsToExport.ps1 index 03671c89..3d64494d 100644 --- a/scripts/helpers/Build/Get-PSModuleFunctionsToExport.ps1 +++ b/scripts/helpers/Build/Get-PSModuleFunctionsToExport.ps1 @@ -10,10 +10,8 @@ Get-PSModuleFunctionsToExport -SourceFolderPath 'C:\MyModule\src\MyModule' #> [CmdletBinding()] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSAvoidUsingWriteHost', '', Scope = 'Function', - Justification = 'Want to just write to the console, not the pipeline.' - )] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Scope = 'Function', Justification = 'Want to just write to the console, not the pipeline.')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Scope = 'Function', Justification = 'Contains long links.')] [OutputType([array])] param( # Path to the folder where the module source code is located. diff --git a/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 b/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 index 887b73cf..5597cd1e 100644 --- a/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 +++ b/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 @@ -15,8 +15,6 @@ 'PSAvoidUsingWriteHost', '', Scope = 'Function', Justification = 'Want to just write to the console, not the pipeline.' )] - #Requires -Modules @{ ModuleName = 'GitHub'; ModuleVersion = '0.13.2' } - #Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' } [CmdletBinding()] param( # Name of the module. @@ -31,7 +29,7 @@ [Parameter(Mandatory)] [System.IO.DirectoryInfo] $ModuleOutputFolder ) - LogGroup 'Updating aliases to export in module manifest' { + Set-GitHubLogGroup 'Updating aliases to export in module manifest' { Write-Host "Module name: [$ModuleName]" Write-Host "Module output folder: [$ModuleSourceFolder]" diff --git a/scripts/main.ps1 b/scripts/main.ps1 index c760ab99..f5f6fba5 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -5,24 +5,22 @@ [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' { +$env:GITHUB_REPOSITORY_NAME = $env:GITHUB_REPOSITORY -replace '.+/' + +Set-GitHubLogGroup 'Loading inputs' { $moduleName = if ([string]::IsNullOrEmpty($env:PSMODULE_BUILD_PSMODULE_INPUT_Name)) { $env:GITHUB_REPOSITORY_NAME } else { $env:PSMODULE_BUILD_PSMODULE_INPUT_Name } - Set-GitHubOutput -Name ModuleName -Value $moduleName - $sourceFolderPath = Resolve-Path -Path 'src' | Select-Object -ExpandProperty Path $moduleOutputFolderPath = Join-Path $pwd -ChildPath 'outputs/module' [pscustomobject]@{ @@ -32,14 +30,14 @@ LogGroup 'Loading inputs' { } | Format-List | Out-String } -LogGroup 'Build local scripts' { +Set-GitHubLogGroup 'Build local scripts' { Write-Host 'Execution order:' $scripts = Get-ChildItem -Filter '*build.ps1' -Recurse | Sort-Object -Property Name | Resolve-Path -Relative $scripts | ForEach-Object { Write-Host " - $_" } $scripts | ForEach-Object { - LogGroup "Build local scripts - [$_]" { + Set-GitHubLogGroup "Build local scripts - [$_]" { . $_ } } @@ -52,6 +50,6 @@ $params = @{ } Build-PSModule @params -Set-GithubOutput -Name ModuleOutputFolderPath -Value $moduleOutputFolderPath +"ModuleOutputFolderPath=$moduleOutputFolderPath" >> $env:GITHUB_OUTPUT exit 0 diff --git a/tests/srcTestRepo/src/variables/public/Planets.ps1 b/tests/srcTestRepo/src/variables/public/Planets.ps1 index 736584b9..5927bc51 100644 --- a/tests/srcTestRepo/src/variables/public/Planets.ps1 +++ b/tests/srcTestRepo/src/variables/public/Planets.ps1 @@ -1,4 +1,4 @@ -$script:Planets = @( +$script:Planets = @( @{ Name = 'Mercury' Mass = 0.330 diff --git a/tests/srcWithManifestTestRepo/src/variables/public/Planets.ps1 b/tests/srcWithManifestTestRepo/src/variables/public/Planets.ps1 index 736584b9..5927bc51 100644 --- a/tests/srcWithManifestTestRepo/src/variables/public/Planets.ps1 +++ b/tests/srcWithManifestTestRepo/src/variables/public/Planets.ps1 @@ -1,4 +1,4 @@ -$script:Planets = @( +$script:Planets = @( @{ Name = 'Mercury' Mass = 0.330