-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.ps1
More file actions
77 lines (67 loc) · 2.79 KB
/
main.ps1
File metadata and controls
77 lines (67 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
[CmdletBinding()]
param()
if ($env:GITHUB_ACTION_INPUT_Debug -eq 'true') {
$DebugPreference = 'Continue'
}
if ($env:GITHUB_ACTION_INPUT_Verbose -eq 'true') {
$VerbosePreference = 'Continue'
}
'::group::Setting up GitHub PowerShell module'
$env:PSMODULE_GITHUB_SCRIPT = $true
$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 | Out-String)
if (-not $alreadyInstalled) {
Write-Verbose "Installing module. Name: [$Name], Version: [$Version], Prerelease: [$Prerelease]"
$params = @{
Name = $Name
Repository = 'PSGallery'
TrustRepository = $true
Prerelease = $Prerelease
}
if ($Version) {
$params['Version'] = $Version
}
Install-PSResource @params
}
$alreadyImported = Get-Module -Name $Name
Write-Verbose 'Already imported:'
Write-Verbose ($alreadyImported | Format-Table | Out-String)
if (-not $alreadyImported) {
Write-Verbose "Importing module: $Name"
Import-Module -Name $Name
}
Write-Output 'Installed modules:'
Get-InstalledPSResource | Select-Object Name, Version, Prerelease | Format-Table -AutoSize
Write-Output 'GitHub module configuration:'
Get-GitHubConfig | Select-Object Name, ID, RunEnv | Format-Table -AutoSize
'::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)
Write-Verbose 'Provided authentication info:'
Write-Verbose "Token: [$providedToken]"
Write-Verbose "ClientID: [$providedClientID]"
Write-Verbose "PrivateKey: [$providedPrivateKey]"
if ($providedClientID -and $providedPrivateKey) {
LogGroup 'Connecting using provided GitHub App' {
Connect-GitHub -ClientID $env:GITHUB_ACTION_INPUT_ClientID -PrivateKey $env:GITHUB_ACTION_INPUT_PrivateKey -Silent
Get-GitHubContext | Format-Table -AutoSize
}
} elseif ($providedToken) {
LogGroup 'Connecting using provided token' {
Connect-GitHub -Token $env:GITHUB_ACTION_INPUT_Token -Silent
Get-GitHubContext | Format-Table -AutoSize
}
}