Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 5 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,11 @@ 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` |
| `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` | `'.'` |
| Name | Description | Required | Default |
| ------------------ | ------------------------------------------------------ | -------- | --------- |
| `Name` | Name of the module to process. | `false` | |
| `ArtifactName` | Name of the artifact to upload. | `false` | `module` |
| `WorkingDirectory` | The working directory where the script will run from. | `false` | `'.'` |

## Expected repository structure

Expand Down
32 changes: 6 additions & 26 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,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
Expand All @@ -40,24 +25,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
with:
name: ${{ inputs.ArtifactName }}
path: ${{ fromJson(steps.build.outputs.result).moduleOutputFolderPath }}
path: ${{ steps.build.outputs.ModuleOutputFolderPath }}
if-no-files-found: error
retention-days: 1
4 changes: 2 additions & 2 deletions scripts/helpers/Build-PSModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,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]@{
Expand All @@ -44,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
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/helpers/Build/Build-PSModuleBase.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
[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]"
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' {
Set-GitHubLogGroup 'Build base - Result' {
Get-ChildItem -Path $ModuleOutputFolder -Recurse -Force | Resolve-Path -Relative | Sort-Object
}
}
16 changes: 8 additions & 8 deletions scripts/helpers/Build/Build-PSModuleManifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,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)) {
Expand Down Expand Up @@ -387,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)) {
Expand All @@ -403,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)) {
Expand Down Expand Up @@ -442,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
}
}
12 changes: 6 additions & 6 deletions scripts/helpers/Build/Build-PSModuleRootModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
# 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
Expand Down Expand Up @@ -254,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
# }
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,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]"

Expand Down
14 changes: 7 additions & 7 deletions scripts/main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
param()

$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]@{
Expand All @@ -30,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 - [$_]" {
. $_
}
}
Expand All @@ -50,6 +50,6 @@ $params = @{
}
Build-PSModule @params

Set-GithubOutput -Name ModuleOutputFolderPath -Value $moduleOutputFolderPath
"ModuleOutputFolderPath=$moduleOutputFolderPath" >> $env:GITHUB_OUTPUT

exit 0
Loading