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. 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:
- 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. - Copies the source code of the module to an output folder.
- Builds the module manifest file based on information from the GitHub repository and the source code. For more information, please read the Module Manifest section.
- 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 section.
- Uploads the module artifact so that it can be used in the next steps of the workflow.
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 |
'.' |
The action expects the module repository to be structured similarly to Template-PSModule.
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:
- Adds a module header from
header.ps1
if it exists and removes the file from the module folder. - 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:<filename>
syntax. - 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.
init
classes/private
classes/public
functions/private
functions/public
variables/private
variables/public
*.ps1
on module root
- Adds a
class
andenum
exporter that exports the ones from theclasses/public
folder to the caller session, using TypeAccelerators. - Adds the
Export-ModuleMember
function to the end of the file, to ensure that only the functions, cmdlets, variables and aliases defined in thepublic
folders are exported.
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:
- Get the manifest file from the source code. If it does not exist, a new manifest file is created.
- Generate and set the
RootModule
based on the module name. - Set a temporary
ModuleVersion
(this is updated during the release process by Publish-PSModule). - Set the
Author
andCompanyName
based on the GitHub Owner. If a value exists in the source manifest file, that value is used. - Set the
Copyright
information based on a default text ((c) 2024 >>OwnerName<<. All rights reserved.
) and includes theAuthor
,CompanyName
or both when applicable. If a value exists in the source manifest file, that value is used. - Set the
Description
based on the GitHub repository description. If a value exists in the source manifest file, that value is used. - Set various properties such as
PowerShellHostName
,PowerShellHostVersion
,DotNetFrameworkVersion
,ClrVersion
, andProcessorArchitecture
. If values exist in the source manifest file, those values are used. - Get the list of files in the module source folder and set the
FileList
property in the manifest. - Get the list of required assemblies (
*.dll
files) from theassemblies
andmodules
(depth = 1) folder and set theRequiredAssemblies
property. - Get the list of nested modules (
*.psm1
,*.ps1
and*.dll
files one level down) from themodules
folder and set theNestedModules
property. - Get the list of scripts to process (
*.ps1
files) from thescripts
folder and set theScriptsToProcess
property. This ensures that the scripts are loaded into the caller session. - Get the list of types to process by searching for
*.Types.ps1xml
files in the entire module source folder and set theTypesToProcess
property. - Get the list of formats to process by searching for
*.Format.ps1xml
files in the entire module source folder and set theFormatsToProcess
property. - Get the list of DSC resources to export by searching for
*.psm1
files in theresources
folder and set theDscResourcesToExport
property. - Get the list of functions, cmdlets, aliases, and variables from the respective
<type>\public
folders and set the respective properties in the manifest. - Get the list of modules by searching for all
*.psm1
files in the entire module source folder (excluding the root module) and set theModuleList
property. - Gather information from source files to update
RequiredModules
,PowerShellVersion
, andCompatiblePSEditions
properties. - 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 aLICENSE
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 anicon.png
file in theicon
folder at the repository root. If a value exists in the source manifest file, that value is used.
ReleaseNotes
are not automated (could be set via PR or release description).PreRelease
is managed externally by Publish-PSModule.RequireLicenseAcceptance
defaults tofalse
unless specified in the source manifest.ExternalModuleDependencies
is not automated. If specified in the source manifest, that value is used.HelpInfoURI
is not automated. If specified in the source manifest, that value is used.- Create a new manifest file in the output folder with the gathered information, which also generates a new
GUID
for the module.
Below is a list of properties in the module manifest file and their sources:
@{
RootModule = 'Utilities.psm1' # Generated as <ModuleName>.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 = '<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.
}
This action does not require any special 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: