Skip to content

Commit 46d8c8c

Browse files
🩹 [Patch]: Refactor Build-PSModule action without Github-Script (#115)
## Description This pull request includes updates to the PowerShell module build process and related scripts, focusing on improving compatibility with GitHub Actions and simplifying output handling. The changes primarily affect the `action.yml` file and several PowerShell scripts. ### Updates to GitHub Actions configuration: * [`action.yml`](diffhunk://#diff-1243c5424efaaa19bd8e813c5e6f6da46316e63761421b3e5f5c8ced9a36e6b6L43-R55): Replaced the `uses` directive for running PowerShell scripts with the `shell: pwsh` option and updated the `run` block to execute the build script directly. Simplified artifact upload by changing the path reference to use `steps.build.outputs.ModuleOutputFolderPath` instead of parsing JSON. ### Updates to script handling: * [`scripts/main.ps1`](diffhunk://#diff-dc2e5a659836b1b73abb03421c567f5018c2755677c4a0aa764cb26117b68011R16-L23): Added a new environment variable `$env:GITHUB_REPOSITORY_NAME` derived from `$env:GITHUB_REPOSITORY` for repository name extraction. Replaced `Set-GitHubOutput` calls with direct appending to `$env:GITHUB_OUTPUT` for compatibility with GitHub Actions. [[1]](diffhunk://#diff-dc2e5a659836b1b73abb03421c567f5018c2755677c4a0aa764cb26117b68011R16-L23) [[2]](diffhunk://#diff-dc2e5a659836b1b73abb03421c567f5018c2755677c4a0aa764cb26117b68011L53-R53) ### Updates to URI generation: * [`scripts/helpers/Build/Build-PSModuleManifest.ps1`](diffhunk://#diff-50cfb011f5c8aeef8145003927ec3e5edfdf26e5d417bcee6e441517c07454f9L390-R390): Simplified the generation of `LicenseUri` and `IconUri` by using `$env:GITHUB_REPOSITORY` directly instead of combining `$env:GITHUB_REPOSITORY_OWNER` and `$env:GITHUB_REPOSITORY_NAME`. [[1]](diffhunk://#diff-50cfb011f5c8aeef8145003927ec3e5edfdf26e5d417bcee6e441517c07454f9L390-R390) [[2]](diffhunk://#diff-50cfb011f5c8aeef8145003927ec3e5edfdf26e5d417bcee6e441517c07454f9L406-R406) ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent 0d98e7d commit 46d8c8c

File tree

8 files changed

+37
-62
lines changed

8 files changed

+37
-62
lines changed

README.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,11 @@ This step lets you add custom build logic to process or modify the module conten
2626

2727
## Usage
2828

29-
| Name | Description | Required | Default |
30-
| --------------------| ----------------------------------------------------------------------------------------------- | -------- | ----------------- |
31-
| `Name` | Name of the module to process. | `false` | |
32-
| `Path` | Path to the folder where the modules are located. | `false` | `src` |
33-
| `ModulesOutputPath` | Path to the folder where the built modules are outputted. | `false` | `outputs/modules` |
34-
| `Debug` | Enable debug output. | `false` | `'false'` |
35-
| `Verbose` | Enable verbose output. | `false` | `'false'` |
36-
| `Version` | Specifies the version of the GitHub module to be installed. The value must be an exact version. | `false` | |
37-
| `Prerelease` | Allow prerelease versions if available. | `false` | `'false'` |
38-
| `WorkingDirectory` | The working directory where the script runs. | `false` | `'.'` |
29+
| Name | Description | Required | Default |
30+
| ------------------ | ------------------------------------------------------ | -------- | --------- |
31+
| `Name` | Name of the module to process. | `false` | |
32+
| `ArtifactName` | Name of the artifact to upload. | `false` | `module` |
33+
| `WorkingDirectory` | The working directory where the script will run from. | `false` | `'.'` |
3934

4035
## Expected repository structure
4136

action.yml

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,6 @@ inputs:
1313
description: Name of the artifact to upload.
1414
required: false
1515
default: module
16-
Debug:
17-
description: Enable debug output.
18-
required: false
19-
default: 'false'
20-
Verbose:
21-
description: Enable verbose output.
22-
required: false
23-
default: 'false'
24-
Version:
25-
description: Specifies the version of the GitHub module to be installed. The value must be an exact version.
26-
required: false
27-
Prerelease:
28-
description: Allow prerelease versions if available.
29-
required: false
30-
default: 'false'
3116
WorkingDirectory:
3217
description: The working directory where the script will run from.
3318
required: false
@@ -40,24 +25,19 @@ runs:
4025
uses: PSModule/Install-PSModuleHelpers@v1
4126

4227
- name: Run Build-PSModule
43-
uses: PSModule/GitHub-Script@v1
28+
shell: pwsh
4429
id: build
30+
working-directory: ${{ inputs.WorkingDirectory }}
4531
env:
4632
PSMODULE_BUILD_PSMODULE_INPUT_Name: ${{ inputs.Name }}
47-
with:
48-
Debug: ${{ inputs.Debug }}
49-
Prerelease: ${{ inputs.Prerelease }}
50-
Verbose: ${{ inputs.Verbose }}
51-
Version: ${{ inputs.Version }}
52-
WorkingDirectory: ${{ inputs.WorkingDirectory }}
53-
Script: |
54-
# Build-PSModule
55-
${{ github.action_path }}/scripts/main.ps1
33+
run: |
34+
# Build-PSModule
35+
${{ github.action_path }}/scripts/main.ps1
5636
5737
- name: Upload module artifact
5838
uses: actions/upload-artifact@v4
5939
with:
6040
name: ${{ inputs.ArtifactName }}
61-
path: ${{ fromJson(steps.build.outputs.result).moduleOutputFolderPath }}
41+
path: ${{ steps.build.outputs.ModuleOutputFolderPath }}
6242
if-no-files-found: error
6343
retention-days: 1

scripts/helpers/Build-PSModule.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
[string] $ModuleOutputFolderPath
3131
)
3232

33-
LogGroup "Building module [$ModuleName]" {
33+
Set-GitHubLogGroup "Building module [$ModuleName]" {
3434
$moduleSourceFolder = Get-Item -Path $ModuleSourceFolderPath
3535
$moduleOutputFolder = New-Item -Path $ModuleOutputFolderPath -Name $ModuleName -ItemType Directory -Force
3636
[pscustomobject]@{
@@ -44,7 +44,7 @@
4444
Build-PSModuleRootModule -ModuleName $ModuleName -ModuleOutputFolder $moduleOutputFolder
4545
Update-PSModuleManifestAliasesToExport -ModuleName $ModuleName -ModuleSourceFolder $moduleSourceFolder -ModuleOutputFolder $moduleOutputFolder
4646

47-
LogGroup 'Build manifest file - Final Result' {
47+
Set-GitHubLogGroup 'Build manifest file - Final Result' {
4848
$outputManifestPath = Join-Path -Path $ModuleOutputFolder -ChildPath "$ModuleName.psd1"
4949
Show-FileContent -Path $outputManifestPath
5050
}

scripts/helpers/Build/Build-PSModuleBase.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@
3333
[System.IO.DirectoryInfo] $ModuleOutputFolder
3434
)
3535

36-
LogGroup 'Build base' {
36+
Set-GitHubLogGroup 'Build base' {
3737
$relModuleSourceFolder = $ModuleSourceFolder | Resolve-Path -Relative
3838
$relModuleOutputFolder = $ModuleOutputFolder | Resolve-Path -Relative
3939
Write-Host "Copying files from [$relModuleSourceFolder] to [$relModuleOutputFolder]"
4040
Copy-Item -Path "$ModuleSourceFolder\*" -Destination $ModuleOutputFolder -Recurse -Force -Exclude "$ModuleName.psm1"
4141
$null = New-Item -Path $ModuleOutputFolder -Name "$ModuleName.psm1" -ItemType File -Force
4242
}
4343

44-
LogGroup 'Build base - Result' {
44+
Set-GitHubLogGroup 'Build base - Result' {
4545
Get-ChildItem -Path $ModuleOutputFolder -Recurse -Force | Resolve-Path -Relative | Sort-Object
4646
}
4747
}

scripts/helpers/Build/Build-PSModuleManifest.ps1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
[System.IO.DirectoryInfo] $ModuleOutputFolder
3434
)
3535

36-
LogGroup 'Build manifest file' {
36+
Set-GitHubLogGroup 'Build manifest file' {
3737
$sourceManifestFilePath = Join-Path -Path $ModuleOutputFolder -ChildPath "$ModuleName.psd1"
3838
Write-Host "[SourceManifestFilePath] - [$sourceManifestFilePath]"
3939
if (-not (Test-Path -Path $sourceManifestFilePath)) {
@@ -387,7 +387,7 @@
387387
#>
388388

389389
Write-Host '[LicenseUri]'
390-
$licenseUri = "https://github.com/$env:GITHUB_REPOSITORY_OWNER/$env:GITHUB_REPOSITORY_NAME/blob/main/LICENSE"
390+
$licenseUri = "https://github.com/$env:GITHUB_REPOSITORY/blob/main/LICENSE"
391391
$manifest.LicenseUri = $PSData.Keys -contains 'LicenseUri' ? $null -ne $PSData.LicenseUri ? $PSData.LicenseUri : $licenseUri : $licenseUri
392392
Write-Host "[LicenseUri] - [$($manifest.LicenseUri)]"
393393
if ([string]::IsNullOrEmpty($manifest.LicenseUri)) {
@@ -403,7 +403,7 @@
403403
}
404404

405405
Write-Host '[IconUri]'
406-
$iconUri = "https://raw.githubusercontent.com/$env:GITHUB_REPOSITORY_OWNER/$env:GITHUB_REPOSITORY_NAME/main/icon/icon.png"
406+
$iconUri = "https://raw.githubusercontent.com/$env:GITHUB_REPOSITORY/main/icon/icon.png"
407407
$manifest.IconUri = $PSData.Keys -contains 'IconUri' ? $null -ne $PSData.IconUri ? $PSData.IconUri : $iconUri : $iconUri
408408
Write-Host "[IconUri] - [$($manifest.IconUri)]"
409409
if ([string]::IsNullOrEmpty($manifest.IconUri)) {
@@ -442,23 +442,23 @@
442442
New-ModuleManifest -Path $outputManifestPath @manifest
443443
}
444444

445-
LogGroup 'Build manifest file - Result - Before format' {
445+
Set-GitHubLogGroup 'Build manifest file - Result - Before format' {
446446
Show-FileContent -Path $outputManifestPath
447447
}
448448

449-
LogGroup 'Build manifest file - Format' {
449+
Set-GitHubLogGroup 'Build manifest file - Format' {
450450
Set-ModuleManifest -Path $outputManifestPath
451451
}
452452

453-
LogGroup 'Build manifest file - Result - After format' {
453+
Set-GitHubLogGroup 'Build manifest file - Result - After format' {
454454
Show-FileContent -Path $outputManifestPath
455455
}
456456

457-
LogGroup 'Build manifest file - Validate - Install module dependencies' {
457+
Set-GitHubLogGroup 'Build manifest file - Validate - Install module dependencies' {
458458
Resolve-PSModuleDependency -ManifestFilePath $outputManifestPath
459459
}
460460

461-
LogGroup 'Build manifest file - Validate - Test manifest file' {
461+
Set-GitHubLogGroup 'Build manifest file - Validate - Test manifest file' {
462462
Test-ModuleManifest -Path $outputManifestPath | Format-List | Out-String
463463
}
464464
}

scripts/helpers/Build/Build-PSModuleRootModule.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
# Get the path separator for the current OS
5252
$pathSeparator = [System.IO.Path]::DirectorySeparatorChar
5353

54-
LogGroup 'Build root module' {
54+
Set-GitHubLogGroup 'Build root module' {
5555
$rootModuleFile = New-Item -Path $ModuleOutputFolder -Name "$ModuleName.psm1" -Force
5656

5757
#region - Analyze source files
@@ -254,26 +254,26 @@ Export-ModuleMember @exports
254254

255255
}
256256

257-
LogGroup 'Build root module - Result - Before format' {
257+
Set-GitHubLogGroup 'Build root module - Result - Before format' {
258258
Write-Host (Show-FileContent -Path $rootModuleFile)
259259
}
260260

261-
LogGroup 'Build root module - Format' {
261+
Set-GitHubLogGroup 'Build root module - Format' {
262262
$AllContent = Get-Content -Path $rootModuleFile -Raw
263263
$settings = Join-Path -Path $PSScriptRoot 'PSScriptAnalyzer.Tests.psd1'
264264
Invoke-Formatter -ScriptDefinition $AllContent -Settings $settings |
265265
Out-File -FilePath $rootModuleFile -Encoding utf8BOM -Force
266266
}
267267

268-
LogGroup 'Build root module - Result - After format' {
268+
Set-GitHubLogGroup 'Build root module - Result - After format' {
269269
Write-Host (Show-FileContent -Path $rootModuleFile)
270270
}
271271

272-
# LogGroup 'Build root module - Validate - Import' {
272+
# Set-GitHubLogGroup 'Build root module - Validate - Import' {
273273
# Install-PSModule -Path $ModuleOutputFolder
274274
# }
275275

276-
# LogGroup 'Build root module - Validate - File list' {
276+
# Set-GitHubLogGroup 'Build root module - Validate - File list' {
277277
# Get-ChildItem -Path $ModuleOutputFolder -Recurse -Force | Resolve-Path -Relative | Sort-Object
278278
# }
279279
}

scripts/helpers/Build/Update-PSModuleManifestAliasesToExport.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
[Parameter(Mandatory)]
3030
[System.IO.DirectoryInfo] $ModuleOutputFolder
3131
)
32-
LogGroup 'Updating aliases to export in module manifest' {
32+
Set-GitHubLogGroup 'Updating aliases to export in module manifest' {
3333
Write-Host "Module name: [$ModuleName]"
3434
Write-Host "Module output folder: [$ModuleSourceFolder]"
3535

scripts/main.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66
param()
77

88
$path = (Join-Path -Path $PSScriptRoot -ChildPath 'helpers') | Get-Item | Resolve-Path -Relative
9-
LogGroup "Loading helper scripts from [$path]" {
9+
Set-GitHubLogGroup "Loading helper scripts from [$path]" {
1010
Get-ChildItem -Path $path -Filter '*.ps1' -Recurse | Resolve-Path -Relative | ForEach-Object {
1111
Write-Host "$_"
1212
. $_
1313
}
1414
}
1515

16-
LogGroup 'Loading inputs' {
16+
$env:GITHUB_REPOSITORY_NAME = $env:GITHUB_REPOSITORY -replace '.+/'
17+
18+
Set-GitHubLogGroup 'Loading inputs' {
1719
$moduleName = if ([string]::IsNullOrEmpty($env:PSMODULE_BUILD_PSMODULE_INPUT_Name)) {
1820
$env:GITHUB_REPOSITORY_NAME
1921
} else {
2022
$env:PSMODULE_BUILD_PSMODULE_INPUT_Name
2123
}
22-
Set-GitHubOutput -Name ModuleName -Value $moduleName
23-
2424
$sourceFolderPath = Resolve-Path -Path 'src' | Select-Object -ExpandProperty Path
2525
$moduleOutputFolderPath = Join-Path $pwd -ChildPath 'outputs/module'
2626
[pscustomobject]@{
@@ -30,14 +30,14 @@ LogGroup 'Loading inputs' {
3030
} | Format-List | Out-String
3131
}
3232

33-
LogGroup 'Build local scripts' {
33+
Set-GitHubLogGroup 'Build local scripts' {
3434
Write-Host 'Execution order:'
3535
$scripts = Get-ChildItem -Filter '*build.ps1' -Recurse | Sort-Object -Property Name | Resolve-Path -Relative
3636
$scripts | ForEach-Object {
3737
Write-Host " - $_"
3838
}
3939
$scripts | ForEach-Object {
40-
LogGroup "Build local scripts - [$_]" {
40+
Set-GitHubLogGroup "Build local scripts - [$_]" {
4141
. $_
4242
}
4343
}
@@ -50,6 +50,6 @@ $params = @{
5050
}
5151
Build-PSModule @params
5252

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

5555
exit 0

0 commit comments

Comments
 (0)