From 7d827b04edf559dbcc2d36bef8726b07612b8fd5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 22 Jan 2025 13:33:31 +0100 Subject: [PATCH 01/13] refactor init, boilerplate and output --- action.yml | 5 +- scripts/boilerplate.ps1 | 43 ++++++++++++++++ scripts/init.ps1 | 85 +++++++++++++++++++++++++++++++ scripts/main.ps1 | 108 ---------------------------------------- scripts/outputs.ps1 | 21 ++++---- 5 files changed, 140 insertions(+), 122 deletions(-) create mode 100644 scripts/boilerplate.ps1 create mode 100644 scripts/init.ps1 delete mode 100644 scripts/main.ps1 diff --git a/action.yml b/action.yml index 5935e46..92a6a34 100644 --- a/action.yml +++ b/action.yml @@ -66,6 +66,7 @@ runs: GITHUB_ACTION_INPUT_Prerelease: ${{ inputs.Prerelease }} run: | # GitHub-Script - . $(Join-Path -Path '${{ github.action_path }}' -ChildPath 'scripts\main.ps1') + . ${{ github.action_path }}\scripts\init.ps1 + . ${{ github.action_path }}\scripts\boilerplate.ps1 ${{ inputs.Script }} - . $(Join-Path -Path '${{ github.action_path }}' -ChildPath 'scripts\outputs.ps1') + . ${{ github.action_path }}\scripts\outputs.ps1 diff --git a/scripts/boilerplate.ps1 b/scripts/boilerplate.ps1 new file mode 100644 index 0000000..2a2043c --- /dev/null +++ b/scripts/boilerplate.ps1 @@ -0,0 +1,43 @@ +[CmdletBinding()] +param() + +$scriptName = $MyInvocation.MyCommand.Name +Write-Debug "[$scriptName] - Start" + +try { + if ($env:GITHUB_ACTION_INPUT_ShowBoilerplate -ne 'true') { + return + } + + $title = "┏━━━━━┫ $Name ┣━━━━━┓" + Write-Output $title + + LogGroup ' - Installed modules' { + Get-InstalledPSResource | Select-Object Name, Version, Prerelease | Sort-Object -Property Name | Format-Table -AutoSize + } + + LogGroup ' - GitHub connection' { + if ($providedClientID -and $providedPrivateKey) { + Connect-GitHub -ClientID $env:GITHUB_ACTION_INPUT_ClientID -PrivateKey $env:GITHUB_ACTION_INPUT_PrivateKey -Silent -PassThru | + Select-Object * | Format-List + } elseif ($providedToken) { + Connect-GitHub -Token $env:GITHUB_ACTION_INPUT_Token -Silent -PassThru | + Select-Object * | Format-List + } else { + Write-Output 'No connection provided' + } + } + + LogGroup ' - Configuration' { + Get-GitHubConfig | Format-List + } + + $endingFence = '┗' + ('━' * ($title.Length - 2)) + '┛' + Write-Output $endingFence +} catch { + throw $_ +} + +Write-Debug "[$scriptName] - End" +$DebugPreference = $env:GITHUB_ACTION_INPUT_Debug -eq 'true' ? 'Continue' : 'SilentlyContinue' +$VerbosePreference = $env:GITHUB_ACTION_INPUT_Verbose -eq 'true' ? 'Continue' : 'SilentlyContinue' diff --git a/scripts/init.ps1 b/scripts/init.ps1 new file mode 100644 index 0000000..3a3bf9d --- /dev/null +++ b/scripts/init.ps1 @@ -0,0 +1,85 @@ +[CmdletBinding()] +param() + +$scriptName = $MyInvocation.MyCommand.Name +Write-Debug "[$scriptName] - Start" + +try { + $env:PSMODULE_GITHUB_SCRIPT = $true + + if ($VerbosePreference -eq 'Continue') { + Write-Output '┏━━━━━┫ GitHub-Script - Init ┣━━━━━┓' + Write-Output '::group:: - SetupGitHub PowerShell module' + } + $Name = 'GitHub' + $Version = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Version) ? $null : $env:GITHUB_ACTION_INPUT_Version + $Prerelease = $env:GITHUB_ACTION_INPUT_Prerelease -eq 'true' + + $alreadyInstalled = Get-InstalledPSResource -Name $Name -ErrorAction SilentlyContinue + if ($Version) { + Write-Verbose "Filtering by version: $Version" + $alreadyInstalled = $alreadyInstalled | Where-Object Version -EQ $Version + } + if ($Prerelease) { + Write-Verbose 'Filtering by prerelease' + $alreadyInstalled = $alreadyInstalled | Where-Object Prerelease -EQ $Prerelease + } + Write-Verbose 'Already installed:' + Write-Verbose ($alreadyInstalled | Format-Table) + if (-not $alreadyInstalled) { + $params = @{ + Name = $Name + Repository = 'PSGallery' + TrustRepository = $true + Prerelease = $Prerelease + } + if ($Version) { + $params['Version'] = $Version + } + $Count = 5 + $Delay = 10 + for ($i = 1; $i -le $Count; $i++) { + try { + Install-PSResource @params -ErrorAction Stop + break + } catch { + Write-Warning $_.Exception.Message + if ($i -eq $Count) { + throw $_ + } + Start-Sleep -Seconds $Delay + } + } + } + + $alreadyImported = Get-Module -Name $Name + Write-Verbose 'Already imported:' + Write-Verbose ($alreadyImported | Format-Table) + if (-not $alreadyImported) { + Write-Verbose "Importing module: $Name" + Import-Module -Name $Name + } + + $providedToken = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Token) + $providedClientID = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_ClientID) + $providedPrivateKey = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_PrivateKey) + $moduleStatus = [pscustomobject]@{ + Name = $Name + Version = [string]::IsNullOrEmpty($Version) ? 'latest' : $Version + Prerelease = $Prerelease + 'Already installed' = $null -ne $alreadyInstalled + 'Already imported' = $null -ne $alreadyImported + 'Provided Token' = $providedToken + 'Provided ClientID' = $providedClientID + 'Provided PrivateKey' = $providedPrivateKey + } + Write-Verbose ($moduleStatus | Format-List) + if ($VerbosePreference -eq 'Continue') { + Write-Output '::endgroup::' + Write-Output '┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛' + } +} catch { + throw $_ +} + +Write-Debug "[$scriptName] - End" diff --git a/scripts/main.ps1 b/scripts/main.ps1 deleted file mode 100644 index 5bce82b..0000000 --- a/scripts/main.ps1 +++ /dev/null @@ -1,108 +0,0 @@ -[CmdletBinding()] -param() - -begin { - Write-Debug '[main] - Start' -} - -process { - try { - $env:PSMODULE_GITHUB_SCRIPT = $true - Write-Output '┏━━━━━┫ GitHub-Script ┣━━━━━┓' - Write-Output '::group:: - Setup GitHub PowerShell' - - $Name = 'GitHub' - $Version = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Version) ? $null : $env:GITHUB_ACTION_INPUT_Version - $Prerelease = $env:GITHUB_ACTION_INPUT_Prerelease -eq 'true' - - $alreadyInstalled = Get-InstalledPSResource -Name $Name -ErrorAction SilentlyContinue - if ($Version) { - Write-Verbose "Filtering by version: $Version" - $alreadyInstalled = $alreadyInstalled | Where-Object Version -EQ $Version - } - if ($Prerelease) { - Write-Verbose 'Filtering by prerelease' - $alreadyInstalled = $alreadyInstalled | Where-Object Prerelease -EQ $Prerelease - } - Write-Verbose 'Already installed:' - $alreadyInstalled | Format-Table - if (-not $alreadyInstalled) { - $params = @{ - Name = $Name - Repository = 'PSGallery' - TrustRepository = $true - Prerelease = $Prerelease - } - if ($Version) { - $params['Version'] = $Version - } - $Count = 5 - $Delay = 10 - for ($i = 1; $i -le $Count; $i++) { - try { - Install-PSResource @params -ErrorAction Stop - break - } catch { - Write-Warning $_.Exception.Message - if ($i -eq $Count) { - throw $_ - } - Start-Sleep -Seconds $Delay - } - } - } - - $alreadyImported = Get-Module -Name $Name - Write-Verbose 'Already imported:' - $alreadyImported | Format-Table - if (-not $alreadyImported) { - Write-Verbose "Importing module: $Name" - Import-Module -Name $Name - } - - $providedToken = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Token) - $providedClientID = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_ClientID) - $providedPrivateKey = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_PrivateKey) - [pscustomobject]@{ - Name = $Name - Version = [string]::IsNullOrEmpty($Version) ? 'latest' : $Version - Prerelease = $Prerelease - 'Already installed' = $null -ne $alreadyInstalled - 'Already imported' = $null -ne $alreadyImported - 'Provided Token' = $providedToken - 'Provided ClientID' = $providedClientID - 'Provided PrivateKey' = $providedPrivateKey - } | Format-List - Write-Output '::endgroup::' - - LogGroup ' - Installed modules' { - Get-InstalledPSResource | Select-Object Name, Version, Prerelease | Sort-Object -Property Name | Format-Table -AutoSize - } - - LogGroup ' - GitHub connection' { - if ($providedClientID -and $providedPrivateKey) { - Connect-GitHub -ClientID $env:GITHUB_ACTION_INPUT_ClientID -PrivateKey $env:GITHUB_ACTION_INPUT_PrivateKey -Silent -PassThru | - Select-Object * | Format-List - } elseif ($providedToken) { - Connect-GitHub -Token $env:GITHUB_ACTION_INPUT_Token -Silent -PassThru | - Select-Object * | Format-List - } else { - Write-Output 'No connection provided' - } - } - - LogGroup ' - Configuration' { - Get-GitHubConfig | Format-List - } - - Write-Output '┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛' - } catch { - throw $_ - } -} - -end { - Write-Debug '[main] - End' - $DebugPreference = $env:GITHUB_ACTION_INPUT_Debug -eq 'true' ? 'Continue' : 'SilentlyContinue' - $VerbosePreference = $env:GITHUB_ACTION_INPUT_Verbose -eq 'true' ? 'Continue' : 'SilentlyContinue' -} diff --git a/scripts/outputs.ps1 b/scripts/outputs.ps1 index f847c4b..8169aa8 100644 --- a/scripts/outputs.ps1 +++ b/scripts/outputs.ps1 @@ -1,25 +1,24 @@ [CmdletBinding()] param() -begin { $DebugPreference = 'SilentlyContinue' $VerbosePreference = 'SilentlyContinue' - Write-Debug '[outputs] - Start' -} + $scriptName = $MyInvocation.MyCommand.Name + Write-Debug "[$scriptName] - Start" -process { try { - Write-Debug "[outputs] - ShowOutput: $env:GITHUB_ACTION_INPUT_ShowOutput" + Write-Debug "[$scriptName] - ShowOutput: $env:GITHUB_ACTION_INPUT_ShowOutput" if ($env:GITHUB_ACTION_INPUT_ShowOutput -ne 'true') { return } $result = (Get-GitHubOutput).result - Write-Debug "[outputs] - Result: $(-not $result)" + Write-Debug "[$scriptName] - Result: $(-not $result)" if (-not $result) { return } - Write-Host '┏━━━━━┫ GitHub-Script ┣━━━━━┓' + $title = "┏━━━━━┫ $Name ┣━━━━━┓" + Write-Output $title LogGroup ' - Outputs' { if ([string]::IsNullOrEmpty($env:GITHUB_ACTION)) { Write-GitHubWarning 'Outputs cannot be accessed as the step has no ID.' @@ -32,12 +31,10 @@ process { $result | Format-List Write-Host "Access outputs using `${{ fromJson(steps.$env:GITHUB_ACTION.outputs.result). }}" } - Write-Host '┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛' + $endingFence = '┗' + ('━' * ($title.Length - 2)) + '┛' + Write-Output $endingFence } catch { throw $_ } -} -end { - Write-Debug '[outputs] - End' -} + Write-Debug "$scriptName - End" From 3216b7d17d615b91ec642566757fb799652f9a3b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 22 Jan 2025 14:09:02 +0100 Subject: [PATCH 02/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Improve=20verbo?= =?UTF-8?q?se=20output=20formatting=20in=20init=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/init.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/init.ps1 b/scripts/init.ps1 index 3a3bf9d..205d892 100644 --- a/scripts/init.ps1 +++ b/scripts/init.ps1 @@ -24,8 +24,8 @@ try { Write-Verbose 'Filtering by prerelease' $alreadyInstalled = $alreadyInstalled | Where-Object Prerelease -EQ $Prerelease } - Write-Verbose 'Already installed:' - Write-Verbose ($alreadyInstalled | Format-Table) + Write-Verbose "Already installed:" + Write-Verbose "$($alreadyInstalled | Format-List)" if (-not $alreadyInstalled) { $params = @{ Name = $Name @@ -54,7 +54,7 @@ try { $alreadyImported = Get-Module -Name $Name Write-Verbose 'Already imported:' - Write-Verbose ($alreadyImported | Format-Table) + Write-Verbose "$($alreadyImported | Format-Table)" if (-not $alreadyImported) { Write-Verbose "Importing module: $Name" Import-Module -Name $Name From 6faddddc442f1f2a7b759b21bbb09c41abb1ce80 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 22 Jan 2025 14:11:32 +0100 Subject: [PATCH 03/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Standardize=20v?= =?UTF-8?q?erbose=20output=20formatting=20in=20init=20and=20outputs=20scri?= =?UTF-8?q?pts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/init.ps1 | 4 +-- scripts/outputs.ps1 | 60 ++++++++++++++++++++++----------------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/scripts/init.ps1 b/scripts/init.ps1 index 205d892..a889aad 100644 --- a/scripts/init.ps1 +++ b/scripts/init.ps1 @@ -24,7 +24,7 @@ try { Write-Verbose 'Filtering by prerelease' $alreadyInstalled = $alreadyInstalled | Where-Object Prerelease -EQ $Prerelease } - Write-Verbose "Already installed:" + Write-Verbose 'Already installed:' Write-Verbose "$($alreadyInstalled | Format-List)" if (-not $alreadyInstalled) { $params = @{ @@ -73,7 +73,7 @@ try { 'Provided ClientID' = $providedClientID 'Provided PrivateKey' = $providedPrivateKey } - Write-Verbose ($moduleStatus | Format-List) + Write-Verbose "$($moduleStatus | Format-List)" if ($VerbosePreference -eq 'Continue') { Write-Output '::endgroup::' Write-Output '┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛' diff --git a/scripts/outputs.ps1 b/scripts/outputs.ps1 index 8169aa8..be924ff 100644 --- a/scripts/outputs.ps1 +++ b/scripts/outputs.ps1 @@ -1,40 +1,40 @@ [CmdletBinding()] param() - $DebugPreference = 'SilentlyContinue' - $VerbosePreference = 'SilentlyContinue' - $scriptName = $MyInvocation.MyCommand.Name - Write-Debug "[$scriptName] - Start" +$DebugPreference = 'SilentlyContinue' +$VerbosePreference = 'SilentlyContinue' +$scriptName = $MyInvocation.MyCommand.Name +Write-Debug "[$scriptName] - Start" - try { - Write-Debug "[$scriptName] - ShowOutput: $env:GITHUB_ACTION_INPUT_ShowOutput" - if ($env:GITHUB_ACTION_INPUT_ShowOutput -ne 'true') { - return - } +try { + Write-Debug "[$scriptName] - ShowOutput: $env:GITHUB_ACTION_INPUT_ShowOutput" + if ($env:GITHUB_ACTION_INPUT_ShowOutput -ne 'true') { + return + } - $result = (Get-GitHubOutput).result - Write-Debug "[$scriptName] - Result: $(-not $result)" - if (-not $result) { - return + $result = (Get-GitHubOutput).result + Write-Debug "[$scriptName] - Result: $(-not $result)" + if (-not $result) { + return + } + $title = "┏━━━━━┫ $Name ┣━━━━━┓" + Write-Output $title + LogGroup ' - Outputs' { + if ([string]::IsNullOrEmpty($env:GITHUB_ACTION)) { + Write-GitHubWarning 'Outputs cannot be accessed as the step has no ID.' } - $title = "┏━━━━━┫ $Name ┣━━━━━┓" - Write-Output $title - LogGroup ' - Outputs' { - if ([string]::IsNullOrEmpty($env:GITHUB_ACTION)) { - Write-GitHubWarning 'Outputs cannot be accessed as the step has no ID.' - } - if (-not (Test-Path -Path $env:GITHUB_OUTPUT)) { - Write-Warning "File not found: $env:GITHUB_OUTPUT" - } - - $result | Format-List - Write-Host "Access outputs using `${{ fromJson(steps.$env:GITHUB_ACTION.outputs.result). }}" + if (-not (Test-Path -Path $env:GITHUB_OUTPUT)) { + Write-Warning "File not found: $env:GITHUB_OUTPUT" } - $endingFence = '┗' + ('━' * ($title.Length - 2)) + '┛' - Write-Output $endingFence - } catch { - throw $_ + + $result | Format-List + Write-Host "Access outputs using `${{ fromJson(steps.$env:GITHUB_ACTION.outputs.result). }}" } + $endingFence = '┗' + ('━' * ($title.Length - 2)) + '┛' + Write-Output $endingFence +} catch { + throw $_ +} - Write-Debug "$scriptName - End" +Write-Debug "$scriptName - End" From 8a986f39632cdd47e63b236333ab94a4fab507bd Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 22 Jan 2025 14:18:12 +0100 Subject: [PATCH 04/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20GitH?= =?UTF-8?q?ub=20connection=20handling=20and=20improve=20output=20formattin?= =?UTF-8?q?g=20in=20init=20and=20boilerplate=20scripts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/boilerplate.ps1 | 16 ++++++---------- scripts/init.ps1 | 19 ++++++++++++++++--- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/scripts/boilerplate.ps1 b/scripts/boilerplate.ps1 index 2a2043c..b649e35 100644 --- a/scripts/boilerplate.ps1 +++ b/scripts/boilerplate.ps1 @@ -16,16 +16,12 @@ try { Get-InstalledPSResource | Select-Object Name, Version, Prerelease | Sort-Object -Property Name | Format-Table -AutoSize } - LogGroup ' - GitHub connection' { - if ($providedClientID -and $providedPrivateKey) { - Connect-GitHub -ClientID $env:GITHUB_ACTION_INPUT_ClientID -PrivateKey $env:GITHUB_ACTION_INPUT_PrivateKey -Silent -PassThru | - Select-Object * | Format-List - } elseif ($providedToken) { - Connect-GitHub -Token $env:GITHUB_ACTION_INPUT_Token -Silent -PassThru | - Select-Object * | Format-List - } else { - Write-Output 'No connection provided' - } + LogGroup ' - GitHub connection - Default' { + Get-GitHubContext | Format-List + } + + LogGroup ' - GitHub connection - List' { + Get-GitHubContext -ListAvailable | Format-Table } LogGroup ' - Configuration' { diff --git a/scripts/init.ps1 b/scripts/init.ps1 index a889aad..fb0899e 100644 --- a/scripts/init.ps1 +++ b/scripts/init.ps1 @@ -1,5 +1,7 @@ [CmdletBinding()] -param() +param( + [string]$Name = 'GitHub-Script - Init' +) $scriptName = $MyInvocation.MyCommand.Name Write-Debug "[$scriptName] - Start" @@ -8,7 +10,8 @@ try { $env:PSMODULE_GITHUB_SCRIPT = $true if ($VerbosePreference -eq 'Continue') { - Write-Output '┏━━━━━┫ GitHub-Script - Init ┣━━━━━┓' + $title = "┏━━━━━┫ $Name ┣━━━━━┓" + Write-Output $title Write-Output '::group:: - SetupGitHub PowerShell module' } $Name = 'GitHub' @@ -76,7 +79,17 @@ try { Write-Verbose "$($moduleStatus | Format-List)" if ($VerbosePreference -eq 'Continue') { Write-Output '::endgroup::' - Write-Output '┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛' + Write-Output '::group:: - GitHub connection' + } + if ($providedClientID -and $providedPrivateKey) { + Connect-GitHub -ClientID $env:GITHUB_ACTION_INPUT_ClientID -PrivateKey $env:GITHUB_ACTION_INPUT_PrivateKey -Silent + } elseif ($providedToken) { + Connect-GitHub -Token $env:GITHUB_ACTION_INPUT_Token -Silent + } + if ($VerbosePreference -eq 'Continue') { + Write-Output '::endgroup::' + $endingFence = '┗' + ('━' * ($title.Length - 2)) + '┛' + Write-Output $endingFence } } catch { throw $_ From 67ea93f11a7c4dfa11fc79a02c010760941aa0c4 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 22 Jan 2025 14:40:07 +0100 Subject: [PATCH 05/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20ShowInfo?= =?UTF-8?q?=20input=20to=20display=20environment=20information=20and=20ref?= =?UTF-8?q?actor=20script=20execution=20flow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- action.yml | 12 ++- scripts/boilerplate.ps1 | 39 --------- scripts/info.ps1 | 46 +++++++++++ scripts/init.ps1 | 170 ++++++++++++++++++++-------------------- scripts/outputs.ps1 | 8 +- 5 files changed, 146 insertions(+), 129 deletions(-) delete mode 100644 scripts/boilerplate.ps1 create mode 100644 scripts/info.ps1 diff --git a/action.yml b/action.yml index 92a6a34..31794fc 100644 --- a/action.yml +++ b/action.yml @@ -34,10 +34,14 @@ inputs: description: Allow prerelease versions if available. required: false default: 'false' + ShowInfo: + description: Show information about the environment. + required: false + default: 'true' ShowOutput: description: Show the output of the script. required: false - default: 'false' + default: 'true' WorkingDirectory: description: The working directory where the script will run from. required: false @@ -62,11 +66,13 @@ runs: GITHUB_ACTION_INPUT_Debug: ${{ inputs.Debug }} GITHUB_ACTION_INPUT_Verbose: ${{ inputs.Verbose }} GITHUB_ACTION_INPUT_Version: ${{ inputs.Version }} + GITHUB_ACTION_INPUT_ShowInfo: ${{ inputs.ShowInfo }} GITHUB_ACTION_INPUT_ShowOutput: ${{ inputs.ShowOutput }} GITHUB_ACTION_INPUT_Prerelease: ${{ inputs.Prerelease }} + run: | # GitHub-Script . ${{ github.action_path }}\scripts\init.ps1 - . ${{ github.action_path }}\scripts\boilerplate.ps1 + . ${{ github.action_path }}\scripts\info.ps1 ${{ inputs.Script }} - . ${{ github.action_path }}\scripts\outputs.ps1 + . ${{ github.action_path }}\scripts\result.ps1 diff --git a/scripts/boilerplate.ps1 b/scripts/boilerplate.ps1 deleted file mode 100644 index b649e35..0000000 --- a/scripts/boilerplate.ps1 +++ /dev/null @@ -1,39 +0,0 @@ -[CmdletBinding()] -param() - -$scriptName = $MyInvocation.MyCommand.Name -Write-Debug "[$scriptName] - Start" - -try { - if ($env:GITHUB_ACTION_INPUT_ShowBoilerplate -ne 'true') { - return - } - - $title = "┏━━━━━┫ $Name ┣━━━━━┓" - Write-Output $title - - LogGroup ' - Installed modules' { - Get-InstalledPSResource | Select-Object Name, Version, Prerelease | Sort-Object -Property Name | Format-Table -AutoSize - } - - LogGroup ' - GitHub connection - Default' { - Get-GitHubContext | Format-List - } - - LogGroup ' - GitHub connection - List' { - Get-GitHubContext -ListAvailable | Format-Table - } - - LogGroup ' - Configuration' { - Get-GitHubConfig | Format-List - } - - $endingFence = '┗' + ('━' * ($title.Length - 2)) + '┛' - Write-Output $endingFence -} catch { - throw $_ -} - -Write-Debug "[$scriptName] - End" -$DebugPreference = $env:GITHUB_ACTION_INPUT_Debug -eq 'true' ? 'Continue' : 'SilentlyContinue' -$VerbosePreference = $env:GITHUB_ACTION_INPUT_Verbose -eq 'true' ? 'Continue' : 'SilentlyContinue' diff --git a/scripts/info.ps1 b/scripts/info.ps1 new file mode 100644 index 0000000..9c967ab --- /dev/null +++ b/scripts/info.ps1 @@ -0,0 +1,46 @@ +[CmdletBinding()] +param() + +begin { + $scriptName = $MyInvocation.MyCommand.Name + Write-Debug "[$scriptName] - Start" +} + +process { + try { + Write-Debug "[$scriptName] - ShowInfo: $env:GITHUB_ACTION_INPUT_ShowInfo" + if ($env:GITHUB_ACTION_INPUT_ShowInfo -ne 'true') { + return + } + + $fenceStart = "┏━━━━━┫ $Name - Info ┣━━━━━┓" + Write-Output $fenceStart + + LogGroup ' - Installed modules' { + Get-InstalledPSResource | Select-Object Name, Version, Prerelease | Sort-Object -Property Name | Format-Table -AutoSize + } + + LogGroup ' - GitHub connection - Default' { + Get-GitHubContext | Format-List + } + + LogGroup ' - GitHub connection - List' { + Get-GitHubContext -ListAvailable | Format-Table + } + + LogGroup ' - Configuration' { + Get-GitHubConfig | Format-List + } + + $fenceEnd = '┗' + ('━' * ($fenceStart.Length - 2)) + '┛' + Write-Output $fenceEnd + } catch { + throw $_ + } +} + +end { + Write-Debug "[$scriptName] - End" + $DebugPreference = $env:GITHUB_ACTION_INPUT_Debug -eq 'true' ? 'Continue' : 'SilentlyContinue' + $VerbosePreference = $env:GITHUB_ACTION_INPUT_Verbose -eq 'true' ? 'Continue' : 'SilentlyContinue' +} diff --git a/scripts/init.ps1 b/scripts/init.ps1 index fb0899e..c625f20 100644 --- a/scripts/init.ps1 +++ b/scripts/init.ps1 @@ -1,98 +1,102 @@ [CmdletBinding()] -param( - [string]$Name = 'GitHub-Script - Init' -) +param() -$scriptName = $MyInvocation.MyCommand.Name -Write-Debug "[$scriptName] - Start" - -try { - $env:PSMODULE_GITHUB_SCRIPT = $true +begin { + $scriptName = $MyInvocation.MyCommand.Name + Write-Debug "[$scriptName] - Start" +} - if ($VerbosePreference -eq 'Continue') { - $title = "┏━━━━━┫ $Name ┣━━━━━┓" - Write-Output $title - Write-Output '::group:: - SetupGitHub PowerShell module' - } - $Name = 'GitHub' - $Version = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Version) ? $null : $env:GITHUB_ACTION_INPUT_Version - $Prerelease = $env:GITHUB_ACTION_INPUT_Prerelease -eq 'true' +process { + try { + $env:PSMODULE_GITHUB_SCRIPT = $true - $alreadyInstalled = Get-InstalledPSResource -Name $Name -ErrorAction SilentlyContinue - if ($Version) { - Write-Verbose "Filtering by version: $Version" - $alreadyInstalled = $alreadyInstalled | Where-Object Version -EQ $Version - } - if ($Prerelease) { - Write-Verbose 'Filtering by prerelease' - $alreadyInstalled = $alreadyInstalled | Where-Object Prerelease -EQ $Prerelease - } - Write-Verbose 'Already installed:' - Write-Verbose "$($alreadyInstalled | Format-List)" - if (-not $alreadyInstalled) { - $params = @{ - Name = $Name - Repository = 'PSGallery' - TrustRepository = $true - Prerelease = $Prerelease + if ($VerbosePreference -eq 'Continue') { + $fenceStart = "┏━━━━━┫ $Name - Init ┣━━━━━┓" + Write-Output $fenceStart + Write-Output '::group:: - SetupGitHub PowerShell module' } + $Name = 'GitHub' + $Version = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Version) ? $null : $env:GITHUB_ACTION_INPUT_Version + $Prerelease = $env:GITHUB_ACTION_INPUT_Prerelease -eq 'true' + + $alreadyInstalled = Get-InstalledPSResource -Name $Name -ErrorAction SilentlyContinue if ($Version) { - $params['Version'] = $Version + Write-Verbose "Filtering by version: $Version" + $alreadyInstalled = $alreadyInstalled | Where-Object Version -EQ $Version + } + if ($Prerelease) { + Write-Verbose 'Filtering by prerelease' + $alreadyInstalled = $alreadyInstalled | Where-Object Prerelease -EQ $Prerelease } - $Count = 5 - $Delay = 10 - for ($i = 1; $i -le $Count; $i++) { - try { - Install-PSResource @params -ErrorAction Stop - break - } catch { - Write-Warning $_.Exception.Message - if ($i -eq $Count) { - throw $_ + Write-Verbose 'Already installed:' + Write-Verbose "$($alreadyInstalled | Format-List)" + if (-not $alreadyInstalled) { + $params = @{ + Name = $Name + Repository = 'PSGallery' + TrustRepository = $true + Prerelease = $Prerelease + } + if ($Version) { + $params['Version'] = $Version + } + $Count = 5 + $Delay = 10 + for ($i = 1; $i -le $Count; $i++) { + try { + Install-PSResource @params -ErrorAction Stop + break + } catch { + Write-Warning $_.Exception.Message + if ($i -eq $Count) { + throw $_ + } + Start-Sleep -Seconds $Delay } - Start-Sleep -Seconds $Delay } } - } - $alreadyImported = Get-Module -Name $Name - Write-Verbose 'Already imported:' - Write-Verbose "$($alreadyImported | Format-Table)" - if (-not $alreadyImported) { - Write-Verbose "Importing module: $Name" - Import-Module -Name $Name - } + $alreadyImported = Get-Module -Name $Name + Write-Verbose 'Already imported:' + Write-Verbose "$($alreadyImported | Format-Table)" + if (-not $alreadyImported) { + Write-Verbose "Importing module: $Name" + Import-Module -Name $Name + } - $providedToken = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Token) - $providedClientID = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_ClientID) - $providedPrivateKey = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_PrivateKey) - $moduleStatus = [pscustomobject]@{ - Name = $Name - Version = [string]::IsNullOrEmpty($Version) ? 'latest' : $Version - Prerelease = $Prerelease - 'Already installed' = $null -ne $alreadyInstalled - 'Already imported' = $null -ne $alreadyImported - 'Provided Token' = $providedToken - 'Provided ClientID' = $providedClientID - 'Provided PrivateKey' = $providedPrivateKey - } - Write-Verbose "$($moduleStatus | Format-List)" - if ($VerbosePreference -eq 'Continue') { - Write-Output '::endgroup::' - Write-Output '::group:: - GitHub connection' - } - if ($providedClientID -and $providedPrivateKey) { - Connect-GitHub -ClientID $env:GITHUB_ACTION_INPUT_ClientID -PrivateKey $env:GITHUB_ACTION_INPUT_PrivateKey -Silent - } elseif ($providedToken) { - Connect-GitHub -Token $env:GITHUB_ACTION_INPUT_Token -Silent - } - if ($VerbosePreference -eq 'Continue') { - Write-Output '::endgroup::' - $endingFence = '┗' + ('━' * ($title.Length - 2)) + '┛' - Write-Output $endingFence + $providedToken = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Token) + $providedClientID = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_ClientID) + $providedPrivateKey = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_PrivateKey) + $moduleStatus = [pscustomobject]@{ + Name = $Name + Version = [string]::IsNullOrEmpty($Version) ? 'latest' : $Version + Prerelease = $Prerelease + 'Already installed' = $null -ne $alreadyInstalled + 'Already imported' = $null -ne $alreadyImported + 'Provided Token' = $providedToken + 'Provided ClientID' = $providedClientID + 'Provided PrivateKey' = $providedPrivateKey + } + Write-Verbose "$($moduleStatus | Format-List)" + if ($VerbosePreference -eq 'Continue') { + Write-Output '::endgroup::' + Write-Output '::group:: - GitHub connection' + } + if ($providedClientID -and $providedPrivateKey) { + Connect-GitHub -ClientID $env:GITHUB_ACTION_INPUT_ClientID -PrivateKey $env:GITHUB_ACTION_INPUT_PrivateKey -Silent + } elseif ($providedToken) { + Connect-GitHub -Token $env:GITHUB_ACTION_INPUT_Token -Silent + } + if ($VerbosePreference -eq 'Continue') { + Write-Output '::endgroup::' + $fenceEnd = '┗' + ('━' * ($fenceStart.Length - 2)) + '┛' + Write-Output $fenceEnd + } + } catch { + throw $_ } -} catch { - throw $_ } -Write-Debug "[$scriptName] - End" +end { + Write-Debug "[$scriptName] - End" +} diff --git a/scripts/outputs.ps1 b/scripts/outputs.ps1 index be924ff..fc393aa 100644 --- a/scripts/outputs.ps1 +++ b/scripts/outputs.ps1 @@ -17,8 +17,8 @@ try { if (-not $result) { return } - $title = "┏━━━━━┫ $Name ┣━━━━━┓" - Write-Output $title + $fenceStart = "┏━━━━━┫ $Name ┣━━━━━┓" + Write-Output $fenceStart LogGroup ' - Outputs' { if ([string]::IsNullOrEmpty($env:GITHUB_ACTION)) { Write-GitHubWarning 'Outputs cannot be accessed as the step has no ID.' @@ -31,8 +31,8 @@ try { $result | Format-List Write-Host "Access outputs using `${{ fromJson(steps.$env:GITHUB_ACTION.outputs.result). }}" } - $endingFence = '┗' + ('━' * ($title.Length - 2)) + '┛' - Write-Output $endingFence + $fenceEnd = '┗' + ('━' * ($fenceStart.Length - 2)) + '┛' + Write-Output $fenceEnd } catch { throw $_ } From db0acba01852fed3dc30acaa7ecfe36c04758e9a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 22 Jan 2025 14:48:57 +0100 Subject: [PATCH 06/13] Refactor action.yml to replace result.ps1 with outputs.ps1 in script execution --- action.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 31794fc..a3f5a50 100644 --- a/action.yml +++ b/action.yml @@ -69,10 +69,9 @@ runs: GITHUB_ACTION_INPUT_ShowInfo: ${{ inputs.ShowInfo }} GITHUB_ACTION_INPUT_ShowOutput: ${{ inputs.ShowOutput }} GITHUB_ACTION_INPUT_Prerelease: ${{ inputs.Prerelease }} - run: | # GitHub-Script . ${{ github.action_path }}\scripts\init.ps1 . ${{ github.action_path }}\scripts\info.ps1 ${{ inputs.Script }} - . ${{ github.action_path }}\scripts\result.ps1 + . ${{ github.action_path }}\scripts\outputs.ps1 From 6683e81b16275eb48c246a162a3a37d118e45b8c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 22 Jan 2025 14:53:59 +0100 Subject: [PATCH 07/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20ShowInit?= =?UTF-8?q?=20input=20to=20action.yml=20and=20update=20script=20outputs=20?= =?UTF-8?q?for=20consistent=20environment=20information=20display?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- action.yml | 4 ++++ scripts/info.ps1 | 4 +++- scripts/init.ps1 | 7 ++++++- scripts/outputs.ps1 | 4 +++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index a3f5a50..6271862 100644 --- a/action.yml +++ b/action.yml @@ -38,6 +38,10 @@ inputs: description: Show information about the environment. required: false default: 'true' + ShowInit: + description: Show information about the initialization. + required: false + default: 'false' ShowOutput: description: Show the output of the script. required: false diff --git a/scripts/info.ps1 b/scripts/info.ps1 index 9c967ab..0ad2ce0 100644 --- a/scripts/info.ps1 +++ b/scripts/info.ps1 @@ -8,12 +8,14 @@ begin { process { try { + $fenceTitle = 'GitHub-Script' + Write-Debug "[$scriptName] - ShowInfo: $env:GITHUB_ACTION_INPUT_ShowInfo" if ($env:GITHUB_ACTION_INPUT_ShowInfo -ne 'true') { return } - $fenceStart = "┏━━━━━┫ $Name - Info ┣━━━━━┓" + $fenceStart = "┏━━━━━┫ $fenceTitle - Info ┣━━━━━┓" Write-Output $fenceStart LogGroup ' - Installed modules' { diff --git a/scripts/init.ps1 b/scripts/init.ps1 index c625f20..b854e4d 100644 --- a/scripts/init.ps1 +++ b/scripts/init.ps1 @@ -9,9 +9,14 @@ begin { process { try { $env:PSMODULE_GITHUB_SCRIPT = $true + $fenceTitle = 'GitHub-Script' + + Write-Debug "[$scriptName] - ShowInit: $env:GITHUB_ACTION_INPUT_ShowInit" + if ($env:GITHUB_ACTION_INPUT_ShowInit -ne 'true') { + } if ($VerbosePreference -eq 'Continue') { - $fenceStart = "┏━━━━━┫ $Name - Init ┣━━━━━┓" + $fenceStart = "┏━━━━━┫ $fenceTitle - Init ┣━━━━━┓" Write-Output $fenceStart Write-Output '::group:: - SetupGitHub PowerShell module' } diff --git a/scripts/outputs.ps1 b/scripts/outputs.ps1 index fc393aa..ec8b1b2 100644 --- a/scripts/outputs.ps1 +++ b/scripts/outputs.ps1 @@ -7,6 +7,8 @@ $scriptName = $MyInvocation.MyCommand.Name Write-Debug "[$scriptName] - Start" try { + $fenceTitle = 'GitHub-Script' + Write-Debug "[$scriptName] - ShowOutput: $env:GITHUB_ACTION_INPUT_ShowOutput" if ($env:GITHUB_ACTION_INPUT_ShowOutput -ne 'true') { return @@ -17,7 +19,7 @@ try { if (-not $result) { return } - $fenceStart = "┏━━━━━┫ $Name ┣━━━━━┓" + $fenceStart = "┏━━━━━┫ $fenceTitle - Outputs ┣━━━━━┓" Write-Output $fenceStart LogGroup ' - Outputs' { if ([string]::IsNullOrEmpty($env:GITHUB_ACTION)) { From 5909176a79fdd9e1171572b5849ba021fda6180b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 22 Jan 2025 15:02:35 +0100 Subject: [PATCH 08/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20output?= =?UTF-8?q?=20formatting=20in=20init,=20info,=20and=20outputs=20scripts=20?= =?UTF-8?q?for=20consistency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/info.ps1 | 2 +- scripts/init.ps1 | 2 +- scripts/outputs.ps1 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/info.ps1 b/scripts/info.ps1 index 0ad2ce0..e2d5b87 100644 --- a/scripts/info.ps1 +++ b/scripts/info.ps1 @@ -15,7 +15,7 @@ process { return } - $fenceStart = "┏━━━━━┫ $fenceTitle - Info ┣━━━━━┓" + $fenceStart = "┏━━┫ $fenceTitle - Info ┣━━━━━━━━┓" Write-Output $fenceStart LogGroup ' - Installed modules' { diff --git a/scripts/init.ps1 b/scripts/init.ps1 index b854e4d..8989e44 100644 --- a/scripts/init.ps1 +++ b/scripts/init.ps1 @@ -16,7 +16,7 @@ process { } if ($VerbosePreference -eq 'Continue') { - $fenceStart = "┏━━━━━┫ $fenceTitle - Init ┣━━━━━┓" + $fenceStart = "┏━━┫ $fenceTitle - Init ┣━━━━━━━━┓" Write-Output $fenceStart Write-Output '::group:: - SetupGitHub PowerShell module' } diff --git a/scripts/outputs.ps1 b/scripts/outputs.ps1 index ec8b1b2..9e7c6fc 100644 --- a/scripts/outputs.ps1 +++ b/scripts/outputs.ps1 @@ -19,7 +19,7 @@ try { if (-not $result) { return } - $fenceStart = "┏━━━━━┫ $fenceTitle - Outputs ┣━━━━━┓" + $fenceStart = "┏━━┫ $fenceTitle - Outputs ┣━━━━━┓" Write-Output $fenceStart LogGroup ' - Outputs' { if ([string]::IsNullOrEmpty($env:GITHUB_ACTION)) { From 7d64476d720340d745e48bfc98c0ba6ce9446bdc Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 22 Jan 2025 15:07:56 +0100 Subject: [PATCH 09/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20ShowInit?= =?UTF-8?q?=20input=20to=20TestWorkflow=20and=20action.yml=20for=20improve?= =?UTF-8?q?d=20initialization=20output?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/TestWorkflow.yml | 9 ++++++++- action.yml | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/TestWorkflow.yml b/.github/workflows/TestWorkflow.yml index 973e194..3bfc8b8 100644 --- a/.github/workflows/TestWorkflow.yml +++ b/.github/workflows/TestWorkflow.yml @@ -47,6 +47,13 @@ jobs: Debug: true Verbose: true + - name: Action-Test [ShowInit] + uses: ./ + with: + Debug: true + Verbose: true + ShowInit: true + ActionTestWithScript: name: WithScript runs-on: ${{ inputs.runs-on }} @@ -121,7 +128,7 @@ jobs: Debug: true Verbose: true Prerelease: true - ShowOutput: true + ShowInit: true Script: | LogGroup 'Get-GitHubZen' { $cat = Get-GitHubOctocat diff --git a/action.yml b/action.yml index 6271862..d724a58 100644 --- a/action.yml +++ b/action.yml @@ -70,6 +70,7 @@ runs: GITHUB_ACTION_INPUT_Debug: ${{ inputs.Debug }} GITHUB_ACTION_INPUT_Verbose: ${{ inputs.Verbose }} GITHUB_ACTION_INPUT_Version: ${{ inputs.Version }} + GITHUB_ACTION_INPUT_ShowInit: ${{ inputs.ShowInit }} GITHUB_ACTION_INPUT_ShowInfo: ${{ inputs.ShowInfo }} GITHUB_ACTION_INPUT_ShowOutput: ${{ inputs.ShowOutput }} GITHUB_ACTION_INPUT_Prerelease: ${{ inputs.Prerelease }} From eb417706bbaa9197043f43b7702a3bb18b0f2404 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 22 Jan 2025 15:15:35 +0100 Subject: [PATCH 10/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Enhance=20initi?= =?UTF-8?q?alization=20output=20in=20init.ps1=20by=20adding=20ShowInit=20i?= =?UTF-8?q?nput=20for=20better=20visibility=20of=20module=20status=20and?= =?UTF-8?q?=20connection=20details?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/init.ps1 | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/scripts/init.ps1 b/scripts/init.ps1 index 8989e44..d8993a5 100644 --- a/scripts/init.ps1 +++ b/scripts/init.ps1 @@ -10,15 +10,14 @@ process { try { $env:PSMODULE_GITHUB_SCRIPT = $true $fenceTitle = 'GitHub-Script' + $showInit = $env:GITHUB_ACTION_INPUT_ShowInit -eq 'true' Write-Debug "[$scriptName] - ShowInit: $env:GITHUB_ACTION_INPUT_ShowInit" - if ($env:GITHUB_ACTION_INPUT_ShowInit -ne 'true') { - } - if ($VerbosePreference -eq 'Continue') { + if ($showInit) { $fenceStart = "┏━━┫ $fenceTitle - Init ┣━━━━━━━━┓" Write-Output $fenceStart - Write-Output '::group:: - SetupGitHub PowerShell module' + Write-Output '::group:: - Install GitHub PowerShell module' } $Name = 'GitHub' $Version = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Version) ? $null : $env:GITHUB_ACTION_INPUT_Version @@ -33,8 +32,11 @@ process { Write-Verbose 'Filtering by prerelease' $alreadyInstalled = $alreadyInstalled | Where-Object Prerelease -EQ $Prerelease } - Write-Verbose 'Already installed:' - Write-Verbose "$($alreadyInstalled | Format-List)" + + if ($showInit) { + Write-Output 'Already installed:' + $alreadyInstalled | Format-List + } if (-not $alreadyInstalled) { $params = @{ Name = $Name @@ -62,8 +64,10 @@ process { } $alreadyImported = Get-Module -Name $Name - Write-Verbose 'Already imported:' - Write-Verbose "$($alreadyImported | Format-Table)" + if ($showInit) { + Write-Output 'Already imported:' + $alreadyImported | Format-List + } if (-not $alreadyImported) { Write-Verbose "Importing module: $Name" Import-Module -Name $Name @@ -82,17 +86,18 @@ process { 'Provided ClientID' = $providedClientID 'Provided PrivateKey' = $providedPrivateKey } - Write-Verbose "$($moduleStatus | Format-List)" - if ($VerbosePreference -eq 'Continue') { + if ($showInit) { + Write-Output 'Module status:' + $moduleStatus | Format-List Write-Output '::endgroup::' - Write-Output '::group:: - GitHub connection' + Write-Output '::group:: - Connect to GitHub' } if ($providedClientID -and $providedPrivateKey) { - Connect-GitHub -ClientID $env:GITHUB_ACTION_INPUT_ClientID -PrivateKey $env:GITHUB_ACTION_INPUT_PrivateKey -Silent + Connect-GitHub -ClientID $env:GITHUB_ACTION_INPUT_ClientID -PrivateKey $env:GITHUB_ACTION_INPUT_PrivateKey -Silent:(-not $showInit) } elseif ($providedToken) { - Connect-GitHub -Token $env:GITHUB_ACTION_INPUT_Token -Silent + Connect-GitHub -Token $env:GITHUB_ACTION_INPUT_Token -Silent:(-not $showInit) } - if ($VerbosePreference -eq 'Continue') { + if ($showInit) { Write-Output '::endgroup::' $fenceEnd = '┗' + ('━' * ($fenceStart.Length - 2)) + '┛' Write-Output $fenceEnd From e4f718410dbe6e56d5da6fa1c5c4962d76b846fa Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 22 Jan 2025 15:25:40 +0100 Subject: [PATCH 11/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20README?= =?UTF-8?q?=20and=20action.yml=20to=20include=20ShowInfo=20and=20ShowInit?= =?UTF-8?q?=20inputs=20for=20enhanced=20environment=20and=20initialization?= =?UTF-8?q?=20visibility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ action.yml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 591deb1..5c19377 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ For more information on available functions and automatically loaded variables, | `Verbose` | Enable verbose output. | false | `'false'` | | `Version` | Specifies the exact version of the GitHub module to install. | false | | | `Prerelease` | Allow prerelease versions if available. | false | `'false'` | +| `ShowInfo` | Show information about the environment. | false | `'true'` | +| `ShowInit` | Show information about the initialization. | false | `'false'` | | `ShowOutput` | Show the script's output. | false | `'false'` | | `WorkingDirectory` | The working directory where the script runs. | false | `${{ github.workspace }}` | diff --git a/action.yml b/action.yml index d724a58..c7edc13 100644 --- a/action.yml +++ b/action.yml @@ -45,7 +45,7 @@ inputs: ShowOutput: description: Show the output of the script. required: false - default: 'true' + default: 'false' WorkingDirectory: description: The working directory where the script will run from. required: false From ac40131aa352aa47559acafce124067598d6e534 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 22 Jan 2025 15:30:05 +0100 Subject: [PATCH 12/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20module=20?= =?UTF-8?q?requirements=20to=20info.ps1=20and=20outputs.ps1=20for=20improv?= =?UTF-8?q?ed=20script=20dependencies=20management?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/info.ps1 | 2 ++ scripts/outputs.ps1 | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/info.ps1 b/scripts/info.ps1 index e2d5b87..8efdbf5 100644 --- a/scripts/info.ps1 +++ b/scripts/info.ps1 @@ -1,3 +1,5 @@ +#Requires -Modules GitHub + [CmdletBinding()] param() diff --git a/scripts/outputs.ps1 b/scripts/outputs.ps1 index 9e7c6fc..280e847 100644 --- a/scripts/outputs.ps1 +++ b/scripts/outputs.ps1 @@ -1,4 +1,6 @@ -[CmdletBinding()] +#Requires -Modules GitHub + +[CmdletBinding()] param() $DebugPreference = 'SilentlyContinue' From 70eb5f3563acff08fa1a5e927d969baa10fb57ff Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 22 Jan 2025 15:31:42 +0100 Subject: [PATCH 13/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20ShowOutpu?= =?UTF-8?q?t=20input=20to=20TestWorkflow=20for=20enhanced=20output=20visib?= =?UTF-8?q?ility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/TestWorkflow.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/TestWorkflow.yml b/.github/workflows/TestWorkflow.yml index 3bfc8b8..7e6728b 100644 --- a/.github/workflows/TestWorkflow.yml +++ b/.github/workflows/TestWorkflow.yml @@ -129,6 +129,7 @@ jobs: Verbose: true Prerelease: true ShowInit: true + ShowOutput: true Script: | LogGroup 'Get-GitHubZen' { $cat = Get-GitHubOctocat