|
1 | 1 | [CmdletBinding()] |
2 | | -param( |
3 | | - [string]$Name = 'GitHub-Script - Init' |
4 | | -) |
| 2 | +param() |
5 | 3 |
|
6 | | -$scriptName = $MyInvocation.MyCommand.Name |
7 | | -Write-Debug "[$scriptName] - Start" |
8 | | - |
9 | | -try { |
10 | | - $env:PSMODULE_GITHUB_SCRIPT = $true |
| 4 | +begin { |
| 5 | + $scriptName = $MyInvocation.MyCommand.Name |
| 6 | + Write-Debug "[$scriptName] - Start" |
| 7 | +} |
11 | 8 |
|
12 | | - if ($VerbosePreference -eq 'Continue') { |
13 | | - $title = "┏━━━━━┫ $Name ┣━━━━━┓" |
14 | | - Write-Output $title |
15 | | - Write-Output '::group:: - SetupGitHub PowerShell module' |
16 | | - } |
17 | | - $Name = 'GitHub' |
18 | | - $Version = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Version) ? $null : $env:GITHUB_ACTION_INPUT_Version |
19 | | - $Prerelease = $env:GITHUB_ACTION_INPUT_Prerelease -eq 'true' |
| 9 | +process { |
| 10 | + try { |
| 11 | + $env:PSMODULE_GITHUB_SCRIPT = $true |
20 | 12 |
|
21 | | - $alreadyInstalled = Get-InstalledPSResource -Name $Name -ErrorAction SilentlyContinue |
22 | | - if ($Version) { |
23 | | - Write-Verbose "Filtering by version: $Version" |
24 | | - $alreadyInstalled = $alreadyInstalled | Where-Object Version -EQ $Version |
25 | | - } |
26 | | - if ($Prerelease) { |
27 | | - Write-Verbose 'Filtering by prerelease' |
28 | | - $alreadyInstalled = $alreadyInstalled | Where-Object Prerelease -EQ $Prerelease |
29 | | - } |
30 | | - Write-Verbose 'Already installed:' |
31 | | - Write-Verbose "$($alreadyInstalled | Format-List)" |
32 | | - if (-not $alreadyInstalled) { |
33 | | - $params = @{ |
34 | | - Name = $Name |
35 | | - Repository = 'PSGallery' |
36 | | - TrustRepository = $true |
37 | | - Prerelease = $Prerelease |
| 13 | + if ($VerbosePreference -eq 'Continue') { |
| 14 | + $fenceStart = "┏━━━━━┫ $Name - Init ┣━━━━━┓" |
| 15 | + Write-Output $fenceStart |
| 16 | + Write-Output '::group:: - SetupGitHub PowerShell module' |
38 | 17 | } |
| 18 | + $Name = 'GitHub' |
| 19 | + $Version = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Version) ? $null : $env:GITHUB_ACTION_INPUT_Version |
| 20 | + $Prerelease = $env:GITHUB_ACTION_INPUT_Prerelease -eq 'true' |
| 21 | + |
| 22 | + $alreadyInstalled = Get-InstalledPSResource -Name $Name -ErrorAction SilentlyContinue |
39 | 23 | if ($Version) { |
40 | | - $params['Version'] = $Version |
| 24 | + Write-Verbose "Filtering by version: $Version" |
| 25 | + $alreadyInstalled = $alreadyInstalled | Where-Object Version -EQ $Version |
| 26 | + } |
| 27 | + if ($Prerelease) { |
| 28 | + Write-Verbose 'Filtering by prerelease' |
| 29 | + $alreadyInstalled = $alreadyInstalled | Where-Object Prerelease -EQ $Prerelease |
41 | 30 | } |
42 | | - $Count = 5 |
43 | | - $Delay = 10 |
44 | | - for ($i = 1; $i -le $Count; $i++) { |
45 | | - try { |
46 | | - Install-PSResource @params -ErrorAction Stop |
47 | | - break |
48 | | - } catch { |
49 | | - Write-Warning $_.Exception.Message |
50 | | - if ($i -eq $Count) { |
51 | | - throw $_ |
| 31 | + Write-Verbose 'Already installed:' |
| 32 | + Write-Verbose "$($alreadyInstalled | Format-List)" |
| 33 | + if (-not $alreadyInstalled) { |
| 34 | + $params = @{ |
| 35 | + Name = $Name |
| 36 | + Repository = 'PSGallery' |
| 37 | + TrustRepository = $true |
| 38 | + Prerelease = $Prerelease |
| 39 | + } |
| 40 | + if ($Version) { |
| 41 | + $params['Version'] = $Version |
| 42 | + } |
| 43 | + $Count = 5 |
| 44 | + $Delay = 10 |
| 45 | + for ($i = 1; $i -le $Count; $i++) { |
| 46 | + try { |
| 47 | + Install-PSResource @params -ErrorAction Stop |
| 48 | + break |
| 49 | + } catch { |
| 50 | + Write-Warning $_.Exception.Message |
| 51 | + if ($i -eq $Count) { |
| 52 | + throw $_ |
| 53 | + } |
| 54 | + Start-Sleep -Seconds $Delay |
52 | 55 | } |
53 | | - Start-Sleep -Seconds $Delay |
54 | 56 | } |
55 | 57 | } |
56 | | - } |
57 | 58 |
|
58 | | - $alreadyImported = Get-Module -Name $Name |
59 | | - Write-Verbose 'Already imported:' |
60 | | - Write-Verbose "$($alreadyImported | Format-Table)" |
61 | | - if (-not $alreadyImported) { |
62 | | - Write-Verbose "Importing module: $Name" |
63 | | - Import-Module -Name $Name |
64 | | - } |
| 59 | + $alreadyImported = Get-Module -Name $Name |
| 60 | + Write-Verbose 'Already imported:' |
| 61 | + Write-Verbose "$($alreadyImported | Format-Table)" |
| 62 | + if (-not $alreadyImported) { |
| 63 | + Write-Verbose "Importing module: $Name" |
| 64 | + Import-Module -Name $Name |
| 65 | + } |
65 | 66 |
|
66 | | - $providedToken = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Token) |
67 | | - $providedClientID = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_ClientID) |
68 | | - $providedPrivateKey = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_PrivateKey) |
69 | | - $moduleStatus = [pscustomobject]@{ |
70 | | - Name = $Name |
71 | | - Version = [string]::IsNullOrEmpty($Version) ? 'latest' : $Version |
72 | | - Prerelease = $Prerelease |
73 | | - 'Already installed' = $null -ne $alreadyInstalled |
74 | | - 'Already imported' = $null -ne $alreadyImported |
75 | | - 'Provided Token' = $providedToken |
76 | | - 'Provided ClientID' = $providedClientID |
77 | | - 'Provided PrivateKey' = $providedPrivateKey |
78 | | - } |
79 | | - Write-Verbose "$($moduleStatus | Format-List)" |
80 | | - if ($VerbosePreference -eq 'Continue') { |
81 | | - Write-Output '::endgroup::' |
82 | | - Write-Output '::group:: - GitHub connection' |
83 | | - } |
84 | | - if ($providedClientID -and $providedPrivateKey) { |
85 | | - Connect-GitHub -ClientID $env:GITHUB_ACTION_INPUT_ClientID -PrivateKey $env:GITHUB_ACTION_INPUT_PrivateKey -Silent |
86 | | - } elseif ($providedToken) { |
87 | | - Connect-GitHub -Token $env:GITHUB_ACTION_INPUT_Token -Silent |
88 | | - } |
89 | | - if ($VerbosePreference -eq 'Continue') { |
90 | | - Write-Output '::endgroup::' |
91 | | - $endingFence = '┗' + ('━' * ($title.Length - 2)) + '┛' |
92 | | - Write-Output $endingFence |
| 67 | + $providedToken = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Token) |
| 68 | + $providedClientID = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_ClientID) |
| 69 | + $providedPrivateKey = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_PrivateKey) |
| 70 | + $moduleStatus = [pscustomobject]@{ |
| 71 | + Name = $Name |
| 72 | + Version = [string]::IsNullOrEmpty($Version) ? 'latest' : $Version |
| 73 | + Prerelease = $Prerelease |
| 74 | + 'Already installed' = $null -ne $alreadyInstalled |
| 75 | + 'Already imported' = $null -ne $alreadyImported |
| 76 | + 'Provided Token' = $providedToken |
| 77 | + 'Provided ClientID' = $providedClientID |
| 78 | + 'Provided PrivateKey' = $providedPrivateKey |
| 79 | + } |
| 80 | + Write-Verbose "$($moduleStatus | Format-List)" |
| 81 | + if ($VerbosePreference -eq 'Continue') { |
| 82 | + Write-Output '::endgroup::' |
| 83 | + Write-Output '::group:: - GitHub connection' |
| 84 | + } |
| 85 | + if ($providedClientID -and $providedPrivateKey) { |
| 86 | + Connect-GitHub -ClientID $env:GITHUB_ACTION_INPUT_ClientID -PrivateKey $env:GITHUB_ACTION_INPUT_PrivateKey -Silent |
| 87 | + } elseif ($providedToken) { |
| 88 | + Connect-GitHub -Token $env:GITHUB_ACTION_INPUT_Token -Silent |
| 89 | + } |
| 90 | + if ($VerbosePreference -eq 'Continue') { |
| 91 | + Write-Output '::endgroup::' |
| 92 | + $fenceEnd = '┗' + ('━' * ($fenceStart.Length - 2)) + '┛' |
| 93 | + Write-Output $fenceEnd |
| 94 | + } |
| 95 | + } catch { |
| 96 | + throw $_ |
93 | 97 | } |
94 | | -} catch { |
95 | | - throw $_ |
96 | 98 | } |
97 | 99 |
|
98 | | -Write-Debug "[$scriptName] - End" |
| 100 | +end { |
| 101 | + Write-Debug "[$scriptName] - End" |
| 102 | +} |
0 commit comments