Skip to content

🌟 [Major]: Standalone Module Builder with isolation #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 51 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
09f6f1e
🩹 [Patch]: Remove unused module artifact input and upload step from a…
MariusStorhaug Feb 16, 2025
b8e7877
🩹 [Patch]: Remove `ModuleArtifactName` from workflow and documentation
MariusStorhaug Feb 16, 2025
0f421df
🩹 [Patch]: Add OutputType attribute to Build-PSModule function
MariusStorhaug Feb 16, 2025
1999d04
🩹 [Patch]: Ensure script exits cleanly after module build
MariusStorhaug Feb 16, 2025
02d1045
Merge branch 'main' of https://github.com/PSModule/Build-PSModule int…
MariusStorhaug Feb 20, 2025
dbe6e5f
🩹 [Refactor]: Update input parameters and paths in action.yml and scr…
MariusStorhaug Feb 24, 2025
48b0c50
🩹 [Refactor]: Remove unused input parameters and clean up workflow st…
MariusStorhaug Feb 24, 2025
3ad4646
🩹 [Add]: Introduce new assemblies, configuration, and settings files …
MariusStorhaug Feb 24, 2025
6015376
🩹 [Refactor]: Update test paths in Action-Test.yml for consistency an…
MariusStorhaug Feb 24, 2025
b305ae4
🩹 [Add]: Implement artifact upload step and set GitHub output for mod…
MariusStorhaug Feb 24, 2025
9921397
🩹 [Fix]: Update artifact upload path to use input parameter for impro…
MariusStorhaug Feb 24, 2025
1c9f792
🩹 [Add]: Introduce ArtifactName input parameter for artifact upload f…
MariusStorhaug Feb 24, 2025
8048696
🩹 [Fix]: Correct input reference for ArtifactName in action.yml for p…
MariusStorhaug Feb 24, 2025
67afbe5
🩹 [Fix]: Simplify artifact upload path in action.yml for consistency
MariusStorhaug Feb 24, 2025
bd01dd0
🩹 [Refactor]: Update action.yml to add WorkingDirectory input and str…
MariusStorhaug Feb 28, 2025
6ce3387
🩹 [Fix]: Replace Path with WorkingDirectory in Action-Test.yml for co…
MariusStorhaug Feb 28, 2025
b74819c
🩹 [Refactor]: Remove ConvertTo-Hashtable function and update Import-P…
MariusStorhaug Mar 1, 2025
1946683
🩹 [Fix]: Remove ModuleName parameter from Import-PSModule for improve…
MariusStorhaug Mar 1, 2025
16f218a
🩹 [Fix]: Update PSSemVer module version in Get-PSModuleTest.ps1 for c…
MariusStorhaug Mar 1, 2025
8562aaa
🩹 [Refactor]: Update output formatting in main.ps1 for improved reada…
MariusStorhaug Mar 2, 2025
23ada90
🩹 [Refactor]: Enhance logging in Build-PSModule.ps1 to display module…
MariusStorhaug Mar 2, 2025
a2c604c
🩹 [Refactor]: Update Build-PSModuleBase.ps1 to use relative paths for…
MariusStorhaug Mar 2, 2025
616fae4
🩹 [Refactor]: Modify Build-PSModuleBase.ps1 to log relative paths for…
MariusStorhaug Mar 2, 2025
d8d6736
🩹 [Refactor]: Simplify Set-ModuleManifest call and enhance Test-Modul…
MariusStorhaug Mar 2, 2025
7c0aa18
🩹 [Refactor]: Change output format in Build-PSModuleRootModule.ps1 to…
MariusStorhaug Mar 2, 2025
822c481
🩹 [Refactor]: Streamline output handling in Build-PSModuleRootModule.…
MariusStorhaug Mar 2, 2025
d5eb28d
🩹 [Refactor]: Update output handling in Import-PSModule.ps1 to conver…
MariusStorhaug Mar 2, 2025
a999ec9
🩹 [Refactor]: Update Build-PSModuleBase.ps1 and Build-PSModuleRootMod…
MariusStorhaug Mar 2, 2025
d5865d4
🩹 [Refactor]: Integrate PSModuleHelpers installation and remove unuse…
MariusStorhaug Mar 5, 2025
5f46958
🩹 [Refactor]: Replace Add-PSModulePath with Install-PSModule in Build…
MariusStorhaug Mar 5, 2025
be6767e
🩹 [Refactor]: Replace Import-PSModule with Import-Module for consiste…
MariusStorhaug Mar 5, 2025
816091c
🩹 [Refactor]: Remove Import-Module call from Build-PSModuleRootModule…
MariusStorhaug Mar 5, 2025
cb7d001
🩹 [Enhancement]: Add compatibility tags for Windows, Linux, and MacOS…
MariusStorhaug Mar 5, 2025
87205b8
🩹 [Refactor]: Update module output path resolution in action.yml and …
MariusStorhaug Mar 6, 2025
ce838e8
🩹 [Documentation]: Update default values in README.md and action.yml …
MariusStorhaug Mar 6, 2025
9ca5440
🩹 [Refactor]: Remove GITHUB_TOKEN environment variable from Auto-Rele…
MariusStorhaug Mar 8, 2025
b5b42c0
🩹 [Refactor]: Update parameters in Build-PSModule scripts for improve…
MariusStorhaug Mar 10, 2025
02b3fdb
🩹 [Refactor]: Correct public functions path in Update-PSModuleManifes…
MariusStorhaug Mar 10, 2025
fbace4f
🩹 [Refactor]: Update file path retrieval in Update-PSModuleManifestAl…
MariusStorhaug Mar 10, 2025
0bf7009
🩹 [Refactor]: Rename variable for alias retrieval in Update-PSModuleM…
MariusStorhaug Mar 10, 2025
11775bb
🩹 [Refactor]: Simplify alias output in Update-PSModuleManifestAliases…
MariusStorhaug Mar 10, 2025
f29095d
🩹 [Refactor]: Add ModuleOutputFolder parameter to Update-PSModuleMani…
MariusStorhaug Mar 10, 2025
8e5662f
🩹 [Refactor]: Suppress output of type accelerator removal in Build-PS…
MariusStorhaug Mar 10, 2025
db4e395
🩹 [Refactor]: Add check for PSEdition to determine Windows environmen…
MariusStorhaug Mar 23, 2025
dd7608c
🩹 [Refactor]: Set $IsWindows variable based on PSEdition in Build-PSM…
MariusStorhaug Mar 23, 2025
986e9cd
🩹 [Refactor]: Suppress code analysis warnings for IsWindows variable …
MariusStorhaug Mar 23, 2025
0a21646
🩹 [Refactor]: Remove redundant check for Windows environment in Build…
MariusStorhaug Mar 23, 2025
c46ebaf
🩹 [Refactor]: Rearrange header content addition in Build-PSModuleRoot…
MariusStorhaug Mar 23, 2025
e818294
🩹 [Refactor]: Update module manifest loading method in Build-PSModule…
MariusStorhaug Mar 31, 2025
1734e53
🩹 [Refactor]: Replace direct script execution with Import-PowerShellD…
MariusStorhaug Mar 31, 2025
38187d3
Merge branch 'main' into v4
MariusStorhaug Apr 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions .github/workflows/Action-Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -67,6 +66,5 @@ jobs:
uses: ./
with:
Name: PSModuleTest
Path: tests/srcWithManifest
ModulesOutputPath: tests/outputs/modules
ModuleArtifactName: moduleWithManifest
ArtifactName: PSModuleTestWithManifest
WorkingDirectory: tests/srcWithManifestTestRepo
2 changes: 0 additions & 2 deletions .github/workflows/Auto-Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
31 changes: 15 additions & 16 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
19 changes: 8 additions & 11 deletions scripts/helpers/Build-PSModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand All @@ -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"
Expand Down
10 changes: 6 additions & 4 deletions scripts/helpers/Build/Build-PSModuleBase.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
5 changes: 3 additions & 2 deletions scripts/helpers/Build/Build-PSModuleManifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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' {
Expand All @@ -460,6 +461,6 @@
}

LogGroup 'Build manifest file - Validate - Test manifest file' {
Test-ModuleManifest -Path $outputManifestPath
Test-ModuleManifest -Path $outputManifestPath | Format-List | Out-String
}
}
37 changes: 26 additions & 11 deletions scripts/helpers/Build/Build-PSModuleRootModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -224,7 +240,7 @@ Write-Debug "[`$scriptName] - $relativePath - Done"

$exportsString = $exports | Format-Hashtable

Write-Host ($exportsString | Out-String)
$exportsString | Out-String

$params = @{
Path = $rootModuleFile
Expand Down Expand Up @@ -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
# }
}
32 changes: 0 additions & 32 deletions scripts/helpers/Build/ConvertTo-Hashtable.ps1

This file was deleted.

53 changes: 0 additions & 53 deletions scripts/helpers/Build/Import-PSModule.ps1

This file was deleted.

Loading
Loading