diff --git a/README.md b/README.md index 048a291..7cc352d 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/action.yml b/action.yml index 62ee028..5117c56 100644 --- a/action.yml +++ b/action.yml @@ -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 @@ -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 diff --git a/scripts/helpers/Build-PSModule.ps1 b/scripts/helpers/Build-PSModule.ps1 index 29a4d8e..15f1ac7 100644 --- a/scripts/helpers/Build-PSModule.ps1 +++ b/scripts/helpers/Build-PSModule.ps1 @@ -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]@{ @@ -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 } diff --git a/scripts/helpers/Build/Build-PSModuleBase.ps1 b/scripts/helpers/Build/Build-PSModuleBase.ps1 index 4a0b903..cc95352 100644 --- a/scripts/helpers/Build/Build-PSModuleBase.ps1 +++ b/scripts/helpers/Build/Build-PSModuleBase.ps1 @@ -33,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]" @@ -41,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 e3ae0f2..56aab2d 100644 --- a/scripts/helpers/Build/Build-PSModuleManifest.ps1 +++ b/scripts/helpers/Build/Build-PSModuleManifest.ps1 @@ -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)) { @@ -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)) { @@ -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)) { @@ -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 } } diff --git a/scripts/helpers/Build/Build-PSModuleRootModule.ps1 b/scripts/helpers/Build/Build-PSModuleRootModule.ps1 index b3b9ff1..3b1bfbd 100644 --- a/scripts/helpers/Build/Build-PSModuleRootModule.ps1 +++ b/scripts/helpers/Build/Build-PSModuleRootModule.ps1 @@ -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 @@ -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 # } } diff --git a/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 b/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 index 65608df..5597cd1 100644 --- a/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 +++ b/scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1 @@ -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]" diff --git a/scripts/main.ps1 b/scripts/main.ps1 index af18b66..f5f6fba 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -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]@{ @@ -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 - [$_]" { . $_ } } @@ -50,6 +50,6 @@ $params = @{ } Build-PSModule @params -Set-GithubOutput -Name ModuleOutputFolderPath -Value $moduleOutputFolderPath +"ModuleOutputFolderPath=$moduleOutputFolderPath" >> $env:GITHUB_OUTPUT exit 0