Skip to content

🩹 [Patch]: Add debug-logging #22

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 23 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
24826f5
🩹 [Patch]: Refactor main and outputs scripts for improved readability…
MariusStorhaug Jan 11, 2025
d069849
🪲 [Fix]: Improve error handling in action.yml for script execution
MariusStorhaug Jan 11, 2025
da708fe
🩹 [Patch]: Update debug messages in main and outputs scripts for cons…
MariusStorhaug Jan 11, 2025
fe6f2a9
🩹 [Patch]: Enhance debug output and error handling in outputs.ps1 for…
MariusStorhaug Jan 11, 2025
7b6410e
🩹 [Patch]: Comment out debug and verbose preferences in outputs.ps1 f…
MariusStorhaug Jan 11, 2025
dd76545
🩹 [Patch]: Adjust debug and verbose preferences in main.ps1 for consi…
MariusStorhaug Jan 11, 2025
909741d
🪲 [Fix]: Update exit codes in action.yml for improved error handling
MariusStorhaug Jan 11, 2025
436a1e4
🩹 [Patch]: Capture exit codes from main and outputs scripts in action…
MariusStorhaug Jan 11, 2025
fe21819
🩹 [Patch]: Comment out script execution and error handling in action.…
MariusStorhaug Jan 11, 2025
2268945
🩹 [Patch]: Comment out script execution and error handling in action.…
MariusStorhaug Jan 11, 2025
7517b29
🩹 [Patch]: Uncomment script execution in action.yml for improved func…
MariusStorhaug Jan 11, 2025
584a97d
🩹 [Patch]: Refactor main.ps1 for improved error handling and debuggin…
MariusStorhaug Jan 11, 2025
6a7f319
🩹 [Patch]: Comment out logging groups in main.ps1 for debugging purposes
MariusStorhaug Jan 11, 2025
27090c6
🩹 [Patch]: Uncomment logging for installed modules in main.ps1 to enh…
MariusStorhaug Jan 11, 2025
2a23504
🩹 [Patch]: Uncomment GitHub connection logging in main.ps1 for enhanc…
MariusStorhaug Jan 11, 2025
a63be7e
🩹 [Patch]: Uncomment GitHub connection logging in main.ps1 for improv…
MariusStorhaug Jan 11, 2025
281a039
🩹 [Patch]: Restore execution of outputs.ps1 in action.yml for proper …
MariusStorhaug Jan 11, 2025
5226772
🩹 [Patch]: Uncomment GitHub connection logging in main.ps1 for improv…
MariusStorhaug Jan 11, 2025
e976c9a
🩹 [Patch]: Refactor GitHub connection logging in main.ps1 for improve…
MariusStorhaug Jan 11, 2025
bdc6fbb
🩹 [Patch]: Simplify GitHub connection logging in main.ps1 for improve…
MariusStorhaug Jan 11, 2025
a5f1b9d
🩹 [Patch]: Enhance error handling in Install-PSResource call in main.…
MariusStorhaug Jan 11, 2025
4a4224f
🩹 [Patch]: Enable debug and verbose preferences in outputs.ps1 for en…
MariusStorhaug Jan 11, 2025
eaa01f9
🩹 [Patch]: Restore debug and verbose preferences in main.ps1 and outp…
MariusStorhaug Jan 11, 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
171 changes: 93 additions & 78 deletions scripts/main.ps1
Original file line number Diff line number Diff line change
@@ -1,93 +1,108 @@
[CmdletBinding()]
param()

$env:PSMODULE_GITHUB_SCRIPT = $true
Write-Host '┏━━━━━┫ GitHub-Script ┣━━━━━┓'
Write-Host '::group:: - Setup GitHub PowerShell'
begin {
Write-Debug '[main] - Start'
}

$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
Write-Host '┏━━━━━┫ GitHub-Script ┣━━━━━┓'
Write-Host '::group:: - Setup GitHub PowerShell'

$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
break
} catch {
if ($i -eq $Count) {
throw $_
$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
}
}
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
}
$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-Host '::endgroup::'
$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-Host '::endgroup::'

LogGroup ' - Installed modules' {
Get-InstalledPSResource | Select-Object Name, Version, Prerelease | Sort-Object -Property Name | Format-Table -AutoSize
}
LogGroup ' - Installed modules' {
Get-InstalledPSResource | Select-Object Name, Version, Prerelease | Sort-Object -Property Name | Format-Table -AutoSize
}

if ($providedClientID -and $providedPrivateKey) {
LogGroup ' - GitHub connection - GitHub App' {
Connect-GitHub -ClientID $env:GITHUB_ACTION_INPUT_ClientID -PrivateKey $env:GITHUB_ACTION_INPUT_PrivateKey -Silent -PassThru |
Format-List
}
} elseif ($providedToken) {
LogGroup ' - GitHub connection - Token' {
Connect-GitHub -Token $env:GITHUB_ACTION_INPUT_Token -Silent -PassThru |
Format-List
}
}

LogGroup ' - Configuration' {
Get-GitHubConfig | Format-List
}

LogGroup ' - GitHub connection' {
if ($providedClientID -and $providedPrivateKey) {
Write-Verbose 'Connected using provided GitHub App'
Connect-GitHub -ClientID $env:GITHUB_ACTION_INPUT_ClientID -PrivateKey $env:GITHUB_ACTION_INPUT_PrivateKey -Silent
} elseif ($providedToken) {
Write-Verbose 'Connected using provided token'
Connect-GitHub -Token $env:GITHUB_ACTION_INPUT_Token -Silent
Write-Host '┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛'
} catch {
throw $_
}
Get-GitHubContext | Format-List
}

LogGroup ' - Configuration' {
Get-GitHubConfig | Format-List
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'
}

Write-Host '┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛'

$DebugPreference = $env:GITHUB_ACTION_INPUT_Debug -eq 'true' ? 'Continue' : 'SilentlyContinue'
$VerbosePreference = $env:GITHUB_ACTION_INPUT_Verbose -eq 'true' ? 'Continue' : 'SilentlyContinue'
58 changes: 35 additions & 23 deletions scripts/outputs.ps1
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
[CmdletBinding()]
param()

$DebugPreference = 'SilentlyContinue'
$VerbosePreference = 'SilentlyContinue'

if ($env:GITHUB_ACTION_INPUT_ShowOutput -ne 'true') {
return
}

$result = (Get-GitHubOutput).result
if (-not $result) {
return
begin {
$DebugPreference = 'SilentlyContinue'
$VerbosePreference = 'SilentlyContinue'
Write-Debug '[outputs] - Start'
}

Write-Host '┏━━━━━┫ GitHub-Script ┣━━━━━┓'

LogGroup ' - Outputs' {
if ([string]::IsNullOrEmpty($env:GITHUB_ACTION)) {
Write-GitHubWarning 'Outputs cannot be accessed as the step has no ID.'
process {
try {
Write-Debug "[outputs] - 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)"
if (-not $result) {
return
}
Write-Host '┏━━━━━┫ GitHub-Script ┣━━━━━┓'
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).<output-name> }}"
}
Write-Host '┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛'
} catch {
throw $_
}

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).<output-name> }}"
}

Write-Host '┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛'
end {
Write-Debug '[outputs] - End'
}