Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions .github/workflows/TestWorkflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ jobs:
Debug: true
Verbose: true

- name: Action-Test [ShowInit]
uses: ./
with:
Debug: true
Verbose: true
ShowInit: true

ActionTestWithScript:
name: WithScript
runs-on: ${{ inputs.runs-on }}
Expand Down Expand Up @@ -121,6 +128,7 @@ jobs:
Debug: true
Verbose: true
Prerelease: true
ShowInit: true
ShowOutput: true
Script: |
LogGroup 'Get-GitHubZen' {
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ For more information on available functions and automatically loaded variables,
| `Verbose` | Enable verbose output. | false | `'false'` |
| `Version` | Specifies the exact version of the GitHub module to install. | false | |
| `Prerelease` | Allow prerelease versions if available. | false | `'false'` |
| `ShowInfo` | Show information about the environment. | false | `'true'` |
| `ShowInit` | Show information about the initialization. | false | `'false'` |
| `ShowOutput` | Show the script's output. | false | `'false'` |
| `WorkingDirectory` | The working directory where the script runs. | false | `${{ github.workspace }}` |

Expand Down
15 changes: 13 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ inputs:
description: Allow prerelease versions if available.
required: false
default: 'false'
ShowInfo:
description: Show information about the environment.
required: false
default: 'true'
ShowInit:
description: Show information about the initialization.
required: false
default: 'false'
ShowOutput:
description: Show the output of the script.
required: false
Expand Down Expand Up @@ -62,10 +70,13 @@ runs:
GITHUB_ACTION_INPUT_Debug: ${{ inputs.Debug }}
GITHUB_ACTION_INPUT_Verbose: ${{ inputs.Verbose }}
GITHUB_ACTION_INPUT_Version: ${{ inputs.Version }}
GITHUB_ACTION_INPUT_ShowInit: ${{ inputs.ShowInit }}
GITHUB_ACTION_INPUT_ShowInfo: ${{ inputs.ShowInfo }}
GITHUB_ACTION_INPUT_ShowOutput: ${{ inputs.ShowOutput }}
GITHUB_ACTION_INPUT_Prerelease: ${{ inputs.Prerelease }}
run: |
# GitHub-Script
. $(Join-Path -Path '${{ github.action_path }}' -ChildPath 'scripts\main.ps1')
. ${{ github.action_path }}\scripts\init.ps1
. ${{ github.action_path }}\scripts\info.ps1
${{ inputs.Script }}
. $(Join-Path -Path '${{ github.action_path }}' -ChildPath 'scripts\outputs.ps1')
. ${{ github.action_path }}\scripts\outputs.ps1
50 changes: 50 additions & 0 deletions scripts/info.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#Requires -Modules GitHub

[CmdletBinding()]
param()

begin {
$scriptName = $MyInvocation.MyCommand.Name
Write-Debug "[$scriptName] - Start"
}

process {
try {
$fenceTitle = 'GitHub-Script'

Write-Debug "[$scriptName] - ShowInfo: $env:GITHUB_ACTION_INPUT_ShowInfo"
if ($env:GITHUB_ACTION_INPUT_ShowInfo -ne 'true') {
return
}

$fenceStart = "┏━━┫ $fenceTitle - Info ┣━━━━━━━━┓"
Write-Output $fenceStart

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

LogGroup ' - GitHub connection - Default' {
Get-GitHubContext | Format-List
}

LogGroup ' - GitHub connection - List' {
Get-GitHubContext -ListAvailable | Format-Table
}

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

$fenceEnd = '┗' + ('━' * ($fenceStart.Length - 2)) + '┛'
Write-Output $fenceEnd
} catch {
throw $_
}
}

end {
Write-Debug "[$scriptName] - End"
$DebugPreference = $env:GITHUB_ACTION_INPUT_Debug -eq 'true' ? 'Continue' : 'SilentlyContinue'
$VerbosePreference = $env:GITHUB_ACTION_INPUT_Verbose -eq 'true' ? 'Continue' : 'SilentlyContinue'
}
220 changes: 112 additions & 108 deletions scripts/main.ps1 → scripts/init.ps1
Original file line number Diff line number Diff line change
@@ -1,108 +1,112 @@
[CmdletBinding()]
param()

begin {
Write-Debug '[main] - Start'
}

process {
try {
$env:PSMODULE_GITHUB_SCRIPT = $true
Write-Output '┏━━━━━┫ GitHub-Script ┣━━━━━┓'
Write-Output '::group:: - Setup GitHub PowerShell'

$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
}
}
}

$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-Output '::endgroup::'

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

LogGroup ' - GitHub connection' {
if ($providedClientID -and $providedPrivateKey) {
Connect-GitHub -ClientID $env:GITHUB_ACTION_INPUT_ClientID -PrivateKey $env:GITHUB_ACTION_INPUT_PrivateKey -Silent -PassThru |
Select-Object * | Format-List
} elseif ($providedToken) {
Connect-GitHub -Token $env:GITHUB_ACTION_INPUT_Token -Silent -PassThru |
Select-Object * | Format-List
} else {
Write-Output 'No connection provided'
}
}

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

Write-Output '┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛'
} catch {
throw $_
}
}

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'
}
[CmdletBinding()]
param()

begin {
$scriptName = $MyInvocation.MyCommand.Name
Write-Debug "[$scriptName] - Start"
}

process {
try {
$env:PSMODULE_GITHUB_SCRIPT = $true
$fenceTitle = 'GitHub-Script'
$showInit = $env:GITHUB_ACTION_INPUT_ShowInit -eq 'true'

Write-Debug "[$scriptName] - ShowInit: $env:GITHUB_ACTION_INPUT_ShowInit"

if ($showInit) {
$fenceStart = "┏━━┫ $fenceTitle - Init ┣━━━━━━━━┓"
Write-Output $fenceStart
Write-Output '::group:: - Install GitHub PowerShell module'
}
$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
}

if ($showInit) {
Write-Output 'Already installed:'
$alreadyInstalled | Format-List
}
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
}
}
}

$alreadyImported = Get-Module -Name $Name
if ($showInit) {
Write-Output 'Already imported:'
$alreadyImported | Format-List
}
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)
$moduleStatus = [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
}
if ($showInit) {
Write-Output 'Module status:'
$moduleStatus | Format-List
Write-Output '::endgroup::'
Write-Output '::group:: - Connect to GitHub'
}
if ($providedClientID -and $providedPrivateKey) {
Connect-GitHub -ClientID $env:GITHUB_ACTION_INPUT_ClientID -PrivateKey $env:GITHUB_ACTION_INPUT_PrivateKey -Silent:(-not $showInit)
} elseif ($providedToken) {
Connect-GitHub -Token $env:GITHUB_ACTION_INPUT_Token -Silent:(-not $showInit)
}
if ($showInit) {
Write-Output '::endgroup::'
$fenceEnd = '┗' + ('━' * ($fenceStart.Length - 2)) + '┛'
Write-Output $fenceEnd
}
} catch {
throw $_
}
}

end {
Write-Debug "[$scriptName] - End"
}
Loading