Skip to content

Commit 8ada046

Browse files
🚀 [Feature]: Add functionality to configure the action logging (#30)
## Description This pull request introduces several changes to the GitHub Actions workflow and associated scripts to enhance debugging and initialization information. The key updates include adding new inputs for showing initialization and environment information, and restructuring scripts for better modularity and clarity. - Fixes #26 ### Updates to action inputs: * [`action.yml`](diffhunk://#diff-1243c5424efaaa19bd8e813c5e6f6da46316e63761421b3e5f5c8ced9a36e6b6R37-R44): Added new inputs `ShowInfo` and `ShowInit` to provide options for showing environment and initialization information. [[1]](diffhunk://#diff-1243c5424efaaa19bd8e813c5e6f6da46316e63761421b3e5f5c8ced9a36e6b6R37-R44) [[2]](diffhunk://#diff-1243c5424efaaa19bd8e813c5e6f6da46316e63761421b3e5f5c8ced9a36e6b6R73-R82) ### Script restructuring and enhancements: * `scripts/init.ps1` (renamed from `scripts/main.ps1`): Refactored to include logic for showing initialization information and added debug statements for better traceability. [[1]](diffhunk://#diff-f47ceebe9ade2bb55cede031de8267e9c87b09336a93fcd557c02c1f488554b6L1-R21) [[2]](diffhunk://#diff-f47ceebe9ade2bb55cede031de8267e9c87b09336a93fcd557c02c1f488554b6L27-R39) [[3]](diffhunk://#diff-f47ceebe9ade2bb55cede031de8267e9c87b09336a93fcd557c02c1f488554b6L56-R70) [[4]](diffhunk://#diff-f47ceebe9ade2bb55cede031de8267e9c87b09336a93fcd557c02c1f488554b6L66-R79) [[5]](diffhunk://#diff-f47ceebe9ade2bb55cede031de8267e9c87b09336a93fcd557c02c1f488554b6L75-R111) * [`scripts/info.ps1`](diffhunk://#diff-82c586f67d16e32953b47a962c269d0a484f8aa660d71ad354e91fd2d4334cd9R1-R50): New script added to display detailed information about the environment and GitHub context. Content moved from `scripts/main.ps1` (now called `scripts/init.ps1`) * [`scripts/outputs.ps1`](diffhunk://#diff-ee715ca93229232e95883bf00629fd14e3bf174cdc17b723c4cc5d70e6a60a58L1-R25): Updated to include debug statements and formatted output for better readability. [[1]](diffhunk://#diff-ee715ca93229232e95883bf00629fd14e3bf174cdc17b723c4cc5d70e6a60a58L1-R25) [[2]](diffhunk://#diff-ee715ca93229232e95883bf00629fd14e3bf174cdc17b723c4cc5d70e6a60a58L35-R44) ### Documentation updates: * [`README.md`](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R22-R23): Updated to include descriptions for the new inputs `ShowInfo` and `ShowInit`. ### Update action tests: * [`.github/workflows/TestWorkflow.yml`](diffhunk://#diff-242a265d6d6bfff6094c9285345022d0e6d7ddde58504dfc80249fafbd89ba2cR50-R56): Added `Action-Test [ShowInit]` job to display initialization information and modified existing jobs to use `ShowInit`. [[1]](diffhunk://#diff-242a265d6d6bfff6094c9285345022d0e6d7ddde58504dfc80249fafbd89ba2cR50-R56) [[2]](diffhunk://#diff-242a265d6d6bfff6094c9285345022d0e6d7ddde58504dfc80249fafbd89ba2cL124-R131) ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [x] 🚀 [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 ca9e2ea commit 8ada046

File tree

6 files changed

+220
-144
lines changed

6 files changed

+220
-144
lines changed

.github/workflows/TestWorkflow.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ jobs:
4747
Debug: true
4848
Verbose: true
4949

50+
- name: Action-Test [ShowInit]
51+
uses: ./
52+
with:
53+
Debug: true
54+
Verbose: true
55+
ShowInit: true
56+
5057
ActionTestWithScript:
5158
name: WithScript
5259
runs-on: ${{ inputs.runs-on }}
@@ -121,6 +128,7 @@ jobs:
121128
Debug: true
122129
Verbose: true
123130
Prerelease: true
131+
ShowInit: true
124132
ShowOutput: true
125133
Script: |
126134
LogGroup 'Get-GitHubZen' {

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ For more information on available functions and automatically loaded variables,
1919
| `Verbose` | Enable verbose output. | false | `'false'` |
2020
| `Version` | Specifies the exact version of the GitHub module to install. | false | |
2121
| `Prerelease` | Allow prerelease versions if available. | false | `'false'` |
22+
| `ShowInfo` | Show information about the environment. | false | `'true'` |
23+
| `ShowInit` | Show information about the initialization. | false | `'false'` |
2224
| `ShowOutput` | Show the script's output. | false | `'false'` |
2325
| `WorkingDirectory` | The working directory where the script runs. | false | `${{ github.workspace }}` |
2426

action.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ inputs:
3434
description: Allow prerelease versions if available.
3535
required: false
3636
default: 'false'
37+
ShowInfo:
38+
description: Show information about the environment.
39+
required: false
40+
default: 'true'
41+
ShowInit:
42+
description: Show information about the initialization.
43+
required: false
44+
default: 'false'
3745
ShowOutput:
3846
description: Show the output of the script.
3947
required: false
@@ -62,10 +70,13 @@ runs:
6270
GITHUB_ACTION_INPUT_Debug: ${{ inputs.Debug }}
6371
GITHUB_ACTION_INPUT_Verbose: ${{ inputs.Verbose }}
6472
GITHUB_ACTION_INPUT_Version: ${{ inputs.Version }}
73+
GITHUB_ACTION_INPUT_ShowInit: ${{ inputs.ShowInit }}
74+
GITHUB_ACTION_INPUT_ShowInfo: ${{ inputs.ShowInfo }}
6575
GITHUB_ACTION_INPUT_ShowOutput: ${{ inputs.ShowOutput }}
6676
GITHUB_ACTION_INPUT_Prerelease: ${{ inputs.Prerelease }}
6777
run: |
6878
# GitHub-Script
69-
. $(Join-Path -Path '${{ github.action_path }}' -ChildPath 'scripts\main.ps1')
79+
. ${{ github.action_path }}\scripts\init.ps1
80+
. ${{ github.action_path }}\scripts\info.ps1
7081
${{ inputs.Script }}
71-
. $(Join-Path -Path '${{ github.action_path }}' -ChildPath 'scripts\outputs.ps1')
82+
. ${{ github.action_path }}\scripts\outputs.ps1

scripts/info.ps1

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#Requires -Modules GitHub
2+
3+
[CmdletBinding()]
4+
param()
5+
6+
begin {
7+
$scriptName = $MyInvocation.MyCommand.Name
8+
Write-Debug "[$scriptName] - Start"
9+
}
10+
11+
process {
12+
try {
13+
$fenceTitle = 'GitHub-Script'
14+
15+
Write-Debug "[$scriptName] - ShowInfo: $env:GITHUB_ACTION_INPUT_ShowInfo"
16+
if ($env:GITHUB_ACTION_INPUT_ShowInfo -ne 'true') {
17+
return
18+
}
19+
20+
$fenceStart = "┏━━┫ $fenceTitle - Info ┣━━━━━━━━┓"
21+
Write-Output $fenceStart
22+
23+
LogGroup ' - Installed modules' {
24+
Get-InstalledPSResource | Select-Object Name, Version, Prerelease | Sort-Object -Property Name | Format-Table -AutoSize
25+
}
26+
27+
LogGroup ' - GitHub connection - Default' {
28+
Get-GitHubContext | Format-List
29+
}
30+
31+
LogGroup ' - GitHub connection - List' {
32+
Get-GitHubContext -ListAvailable | Format-Table
33+
}
34+
35+
LogGroup ' - Configuration' {
36+
Get-GitHubConfig | Format-List
37+
}
38+
39+
$fenceEnd = '' + ('' * ($fenceStart.Length - 2)) + ''
40+
Write-Output $fenceEnd
41+
} catch {
42+
throw $_
43+
}
44+
}
45+
46+
end {
47+
Write-Debug "[$scriptName] - End"
48+
$DebugPreference = $env:GITHUB_ACTION_INPUT_Debug -eq 'true' ? 'Continue' : 'SilentlyContinue'
49+
$VerbosePreference = $env:GITHUB_ACTION_INPUT_Verbose -eq 'true' ? 'Continue' : 'SilentlyContinue'
50+
}
Lines changed: 112 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,112 @@
1-
[CmdletBinding()]
2-
param()
3-
4-
begin {
5-
Write-Debug '[main] - Start'
6-
}
7-
8-
process {
9-
try {
10-
$env:PSMODULE_GITHUB_SCRIPT = $true
11-
Write-Output '┏━━━━━┫ GitHub-Script ┣━━━━━┓'
12-
Write-Output '::group:: - Setup GitHub PowerShell'
13-
14-
$Name = 'GitHub'
15-
$Version = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Version) ? $null : $env:GITHUB_ACTION_INPUT_Version
16-
$Prerelease = $env:GITHUB_ACTION_INPUT_Prerelease -eq 'true'
17-
18-
$alreadyInstalled = Get-InstalledPSResource -Name $Name -ErrorAction SilentlyContinue
19-
if ($Version) {
20-
Write-Verbose "Filtering by version: $Version"
21-
$alreadyInstalled = $alreadyInstalled | Where-Object Version -EQ $Version
22-
}
23-
if ($Prerelease) {
24-
Write-Verbose 'Filtering by prerelease'
25-
$alreadyInstalled = $alreadyInstalled | Where-Object Prerelease -EQ $Prerelease
26-
}
27-
Write-Verbose 'Already installed:'
28-
$alreadyInstalled | Format-Table
29-
if (-not $alreadyInstalled) {
30-
$params = @{
31-
Name = $Name
32-
Repository = 'PSGallery'
33-
TrustRepository = $true
34-
Prerelease = $Prerelease
35-
}
36-
if ($Version) {
37-
$params['Version'] = $Version
38-
}
39-
$Count = 5
40-
$Delay = 10
41-
for ($i = 1; $i -le $Count; $i++) {
42-
try {
43-
Install-PSResource @params -ErrorAction Stop
44-
break
45-
} catch {
46-
Write-Warning $_.Exception.Message
47-
if ($i -eq $Count) {
48-
throw $_
49-
}
50-
Start-Sleep -Seconds $Delay
51-
}
52-
}
53-
}
54-
55-
$alreadyImported = Get-Module -Name $Name
56-
Write-Verbose 'Already imported:'
57-
$alreadyImported | Format-Table
58-
if (-not $alreadyImported) {
59-
Write-Verbose "Importing module: $Name"
60-
Import-Module -Name $Name
61-
}
62-
63-
$providedToken = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Token)
64-
$providedClientID = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_ClientID)
65-
$providedPrivateKey = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_PrivateKey)
66-
[pscustomobject]@{
67-
Name = $Name
68-
Version = [string]::IsNullOrEmpty($Version) ? 'latest' : $Version
69-
Prerelease = $Prerelease
70-
'Already installed' = $null -ne $alreadyInstalled
71-
'Already imported' = $null -ne $alreadyImported
72-
'Provided Token' = $providedToken
73-
'Provided ClientID' = $providedClientID
74-
'Provided PrivateKey' = $providedPrivateKey
75-
} | Format-List
76-
Write-Output '::endgroup::'
77-
78-
LogGroup ' - Installed modules' {
79-
Get-InstalledPSResource | Select-Object Name, Version, Prerelease | Sort-Object -Property Name | Format-Table -AutoSize
80-
}
81-
82-
LogGroup ' - GitHub connection' {
83-
if ($providedClientID -and $providedPrivateKey) {
84-
Connect-GitHub -ClientID $env:GITHUB_ACTION_INPUT_ClientID -PrivateKey $env:GITHUB_ACTION_INPUT_PrivateKey -Silent -PassThru |
85-
Select-Object * | Format-List
86-
} elseif ($providedToken) {
87-
Connect-GitHub -Token $env:GITHUB_ACTION_INPUT_Token -Silent -PassThru |
88-
Select-Object * | Format-List
89-
} else {
90-
Write-Output 'No connection provided'
91-
}
92-
}
93-
94-
LogGroup ' - Configuration' {
95-
Get-GitHubConfig | Format-List
96-
}
97-
98-
Write-Output '┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛'
99-
} catch {
100-
throw $_
101-
}
102-
}
103-
104-
end {
105-
Write-Debug '[main] - End'
106-
$DebugPreference = $env:GITHUB_ACTION_INPUT_Debug -eq 'true' ? 'Continue' : 'SilentlyContinue'
107-
$VerbosePreference = $env:GITHUB_ACTION_INPUT_Verbose -eq 'true' ? 'Continue' : 'SilentlyContinue'
108-
}
1+
[CmdletBinding()]
2+
param()
3+
4+
begin {
5+
$scriptName = $MyInvocation.MyCommand.Name
6+
Write-Debug "[$scriptName] - Start"
7+
}
8+
9+
process {
10+
try {
11+
$env:PSMODULE_GITHUB_SCRIPT = $true
12+
$fenceTitle = 'GitHub-Script'
13+
$showInit = $env:GITHUB_ACTION_INPUT_ShowInit -eq 'true'
14+
15+
Write-Debug "[$scriptName] - ShowInit: $env:GITHUB_ACTION_INPUT_ShowInit"
16+
17+
if ($showInit) {
18+
$fenceStart = "┏━━┫ $fenceTitle - Init ┣━━━━━━━━┓"
19+
Write-Output $fenceStart
20+
Write-Output '::group:: - Install GitHub PowerShell module'
21+
}
22+
$Name = 'GitHub'
23+
$Version = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Version) ? $null : $env:GITHUB_ACTION_INPUT_Version
24+
$Prerelease = $env:GITHUB_ACTION_INPUT_Prerelease -eq 'true'
25+
26+
$alreadyInstalled = Get-InstalledPSResource -Name $Name -ErrorAction SilentlyContinue
27+
if ($Version) {
28+
Write-Verbose "Filtering by version: $Version"
29+
$alreadyInstalled = $alreadyInstalled | Where-Object Version -EQ $Version
30+
}
31+
if ($Prerelease) {
32+
Write-Verbose 'Filtering by prerelease'
33+
$alreadyInstalled = $alreadyInstalled | Where-Object Prerelease -EQ $Prerelease
34+
}
35+
36+
if ($showInit) {
37+
Write-Output 'Already installed:'
38+
$alreadyInstalled | Format-List
39+
}
40+
if (-not $alreadyInstalled) {
41+
$params = @{
42+
Name = $Name
43+
Repository = 'PSGallery'
44+
TrustRepository = $true
45+
Prerelease = $Prerelease
46+
}
47+
if ($Version) {
48+
$params['Version'] = $Version
49+
}
50+
$Count = 5
51+
$Delay = 10
52+
for ($i = 1; $i -le $Count; $i++) {
53+
try {
54+
Install-PSResource @params -ErrorAction Stop
55+
break
56+
} catch {
57+
Write-Warning $_.Exception.Message
58+
if ($i -eq $Count) {
59+
throw $_
60+
}
61+
Start-Sleep -Seconds $Delay
62+
}
63+
}
64+
}
65+
66+
$alreadyImported = Get-Module -Name $Name
67+
if ($showInit) {
68+
Write-Output 'Already imported:'
69+
$alreadyImported | Format-List
70+
}
71+
if (-not $alreadyImported) {
72+
Write-Verbose "Importing module: $Name"
73+
Import-Module -Name $Name
74+
}
75+
76+
$providedToken = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Token)
77+
$providedClientID = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_ClientID)
78+
$providedPrivateKey = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_PrivateKey)
79+
$moduleStatus = [pscustomobject]@{
80+
Name = $Name
81+
Version = [string]::IsNullOrEmpty($Version) ? 'latest' : $Version
82+
Prerelease = $Prerelease
83+
'Already installed' = $null -ne $alreadyInstalled
84+
'Already imported' = $null -ne $alreadyImported
85+
'Provided Token' = $providedToken
86+
'Provided ClientID' = $providedClientID
87+
'Provided PrivateKey' = $providedPrivateKey
88+
}
89+
if ($showInit) {
90+
Write-Output 'Module status:'
91+
$moduleStatus | Format-List
92+
Write-Output '::endgroup::'
93+
Write-Output '::group:: - Connect to GitHub'
94+
}
95+
if ($providedClientID -and $providedPrivateKey) {
96+
Connect-GitHub -ClientID $env:GITHUB_ACTION_INPUT_ClientID -PrivateKey $env:GITHUB_ACTION_INPUT_PrivateKey -Silent:(-not $showInit)
97+
} elseif ($providedToken) {
98+
Connect-GitHub -Token $env:GITHUB_ACTION_INPUT_Token -Silent:(-not $showInit)
99+
}
100+
if ($showInit) {
101+
Write-Output '::endgroup::'
102+
$fenceEnd = '' + ('' * ($fenceStart.Length - 2)) + ''
103+
Write-Output $fenceEnd
104+
}
105+
} catch {
106+
throw $_
107+
}
108+
}
109+
110+
end {
111+
Write-Debug "[$scriptName] - End"
112+
}

0 commit comments

Comments
 (0)