|
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