This action "compiles" the module source code into a efficient PowerShell module that is ready to be published to the PowerShell Gallery.
This GitHub Action is a part of the PSModule framework. It is recommended to use the Process-PSModule workflow to automate the whole process of managing the PowerShell module.
- Script module type
- Manifest module type
- PowerShellGallery Publishing Guidelines and Best Practices are followed as much as possible.
During the build process the following steps are performed:
- Copies the source code of the module to an output folder.
- Builds the module manifest file based of info on the GitHub repository and source code. Read the Module Manifest section for more information.
- Builds the root module (.psm1) file by combining source code and adding automation into the root module file. Read the Root module section for more information.
- Builds the module documentation using platyPS and comment based help in the source code. Read the Module documentation section for more information.
| 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 |
DocsOutputPath |
Path to the folder where the built docs are outputted. | false |
outputs/docs |
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:
- Adds module headers from
header.ps1. - Adds data loader automation that loads files from the
datafolder as variables in the module scope, if it exists. The variables are available using the ´$script:´ syntax. - Adds content from subfolders, in the order:
- Init
- Private
- Public
- *.ps1 on module root
- Adds the Export-ModuleMember function to the end of the file, to make sure that only the functions, cmdlets, variables and aliases that are defined in the module are exported.
The root module file that is included in the source files contains the same functionality but is not optimized for performance. The goal with this is to have a quick way to import and test the module without having to build it.
The module manifest file is the file that describes the module and its content. It is used by PowerShell to load the module and its prerequisites. The file also contains important metadata that is used by the PowerShell Gallery.
During the module manifest build process the following steps are performed:
- Get the manifest file from the source code. Content from this file overrides any value that would be calculated based on the source code.
- Find and set the
RootModulebased on filename and extension. - Set a temporary
ModuleVersion, as this is set during the release process by Publish-PSModule. - Set the
AuthorandCompanyNamebased on GitHub Owner. - Set the
Copyrightinformation based on a default text ((c) 2024 >>OwnerName<<. All rights reserved.) and adds either theAuthor,CompanyNameor both (Author | CompanyName) when these are different. - Set the
Descriptionbased on the GitHub repository description. - Set various properties in the manifest such as
PowerShellHostName,PowerShellHostVersion,DotNetFrameworkVersion,ClrVersion, andProcessorArchitecture. There is currently no automation for these properties. - Get the list of files in the module source folder and set the
FileListproperty in the manifest. - Get the list of required assemblies (
*.dllfiles) from theassembliesfolder and set theRequiredAssembliesproperty in the manifest. - Get the list of nested modules (
*.psm1files) from themodulesfolder and set theNestedModulesproperty in the manifest. - Get the list of scripts to process (
*.ps1files) from theclassesandscriptsfolders and set theScriptsToProcessproperty in the manifest. This ensures that the scripts are loaded to the caller session (parent of module session). - Get the list of types to process by searching for
*.Types.ps1xmlfiles in the entire module source folder and set theTypesToProcessproperty in the manifest. - Get the list of formats to process by searching for
*.Format.ps1xmlfiles in the entire module source folder and set theFormatsToProcessproperty in the manifest. - Get the list of DSC resources to export by searching for
*.psm1files in theresourcesfolder and set theDscResourcesToExportproperty in the manifest. - Get the list of functions, cmdlets, aliases, and variables to export and set the respective properties in the manifest.
- Get the list of modules by searching for all
*.psm1files in the entire module source folder, excluding the root module and set theModuleListproperty in the manifest. - Gather information from source files to update
RequiredModules,PowerShellVersion, andCompatiblePSEditionsproperties. - The following values are gathered from the GitHub repository:
Tagsare generated from Repository topics in addition to compatability tags gathered from the source code.LicenseUriis generated assuming there is aLICENSEfile on the root of the repository.ProjectUriis the URL to the GitHub repositoryIconUriis generated assuming there is aicon.pngfile in theiconfolder on the repository root.
ReleaseNotescurrently not automated, but could be the PR description or release description.PreReleaseis not managed here, but is managed from Publish-PSModuleRequireLicenseAcceptanceis not automated and defaults tofalse, andExternalModuleDependenciesis currenlty not automated.HelpInfoURIis not automated.- Create a new manifest file in the output folder with the gathered info above. This also generates a new
GUIDfor the module. - Format the manifest file using the
Set-ModuleManifestfunction from the Utilities module.
Linking the description to the module manifest file might show more how this works:
@{
RootModule = 'Utilities.psm1' # Get files from root of folder wher name is same as the folder and file extension is .psm1, .ps1, .psd1, .dll, .cdxml, .xaml. Error if there are multiple files that meet the criteria.
ModuleVersion = '0.0.1' # Set during release using Publish-PSModule.
CompatiblePSEditions = @() # Get from source files, REQUIRES -PSEdition <PSEdition-Name>, null if not provided.
GUID = '<GUID>' # Generated when finally saving the manifest using New-ModuleManifest.
Author = 'PSModule' # Get from GitHub Owner, else use info from source manifest file.
CompanyName = 'PSModule' # Get from GitHub Owner, else use info from source manifest file.
Copyright = '(c) 2024 PSModule. All rights reserved.' # Generated from the current year and Author and Company values.
Description = 'This is a module.' # Get from the repository description, else use info from source manifest file.
PowerShellVersion = '' # Get from source files, REQUIRES -Version <N>[.<n>], null if not provided.
PowerShellHostName = '' # Get from manifest file, null if not provided.
PowerShellHostVersion = '' # Get from manifest file, null if not provided.
DotNetFrameworkVersion = '' # Get from manifest file, null if not provided.
ClrVersion = '' # Get from manifest file, null if not provided.
ProcessorArchitecture = '' # Get from manifest file, null if not provided.
RequiredModules = @() # Get from source files, REQUIRES -Modules <Module-Name> | <Hashtable> -> Need to be installed and loaded on build time. Will be installed in global session state during installtion.
RequiredAssemblies = @() # Get from assemblies\*.dll.
ScriptsToProcess = @() # Get from scripts\*.ps1 and classes\*.ps1 ordered by name. These are loaded to the caller session (parent of module session).
TypesToProcess = @() # Get from *.Types.ps1xml anywhere in the source module folder.
FormatsToProcess = @() # Get from *.Format.ps1xml anywhere in the source module folder.
NestedModules = @() # Get from modules\*.psm1.
FunctionsToExport = @() # Get from public\*.ps1.
CmdletsToExport = @() # Get from manifest file, @() if not provided.
VariablesToExport = @() # To be automated, currently adds '@()' to the manifest file.
AliasesToExport = '*' # To be automated, currently adds '*' to the manifest file.
DscResourcesToExport = @() # Get from resources\*.psm1.
ModuleList = @() # Get from listing all .\*.psm1 files - Informational only.
FileList = @() # Get from listing all .\* files - Informational only.
PrivateData = @{ # <https://learn.microsoft.com/en-us/powershell/gallery/concepts/package-manifest-affecting-ui?view=powershellget-2.x>
PSData = @{
Tags = @() # Get from repository topics + compatability tags collected from source files.
LicenseUri = '' # Generate public link to .\LICENSE.
ProjectUri = '' # Generate public link to GitHub Repository.
IconUri = '' # Get from .\icon\icon.png.
ReleaseNotes = '' # Update during release -> PR description or release description.
Prerelease = '' # Update during release -> uses a normalized version of the branch name.
RequireLicenseAcceptance = $false ## Get from manifest file, default is $false.
ExternalModuleDependencies = @() # Get from source manifest file
ExperimentalFeatures = @( # Get from source manifest file
@{
Name = "SomeExperimentalFeature"
Description = "This is an experimental feature."
}
)
}
OtherKeys = @{} # Get from manifest file
}
HelpInfoURI = '' # Get from source manifest file
DefaultCommandPrefix = '' # Get from source manifest file
}The module manifest file that is included in the source files contains the same functionality but is not optimized for performance and does not automatically gather all the information that is gathered during the build process. The goal with this is to have a quick way to import and test the module without having to build it.
The source module manifest is also the only place where some of the values can be controlled. These values are typically difficult to calculate and are not automated.
The module documentation is built using platyPS and comment based help in the source code. The documentation is currently not published anywhere, but should be published to GitHub Pages in a future release.
The action does not require any permissions.
Module manifest:
- about_Module_Manifests
- How to write a PowerShell module manifest
- New-ModuleManifest
- Update-ModuleManifest
- Package metadata values that impact the PowerShell Gallery UI
- PowerShellGallery Publishing Guidelines and Best Practices
Modules:
Documentation: