diff --git a/README.md b/README.md index 1c467a6..4bb7d83 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,30 @@ For more information on the available functions and automatic loaded variables, | - | - | | `result` | The output of the script as a JSON object. To add outputs to `result`, use `Set-GitHubOutput`. | +To use the outputs in a subsequent step, you can use the following syntax: + +```yaml +- uses: PSModule/GitHub-Script@v1 + id: set-output + with: + Script: | + Set-GitHubOutput -Name 'Octocat' -Value @{ + Name = 'Octocat' + Image = 'https://octodex.github.com/images/original.png' + } + +- name: Use outputs + shell: pwsh + env: + result: ${{ steps.set-output.outputs.result }} # = '{"Octocat":{"Name":"Octocat","Image":"https://octodex.github.com/images/original.png"}}' + name: ${{ fromJson(steps.set-output.outputs.result).Octocat.Name }} # = 'Octocat' + run: | + $result = $env:result | ConvertFrom-Json + Write-Output $env:name + Write-Output $result.Octocat.Image +``` + + ### Examples #### Example 1: Run a GitHub PowerShell script diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 905f225..db873ff 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -1,11 +1,9 @@ [CmdletBinding()] param() -$DebugPreference = $env:GITHUB_ACTION_INPUT_Debug -eq 'true' ? 'Continue' : 'SilentlyContinue' -$VerbosePreference = $env:GITHUB_ACTION_INPUT_Verbose -eq 'true' ? 'Continue' : 'SilentlyContinue' - -'::group::Setting up GitHub PowerShell module' $env:PSMODULE_GITHUB_SCRIPT = $true +Write-Host "┏━━━━━┫ GitHub-Script ┣━━━━━┓" +Write-Host '::group:: - Setup GitHub PowerShell' $Name = 'GitHub' $Version = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Version) ? $null : $env:GITHUB_ACTION_INPUT_Version @@ -21,9 +19,8 @@ if ($Prerelease) { $alreadyInstalled = $alreadyInstalled | Where-Object Prerelease -EQ $Prerelease } Write-Verbose 'Already installed:' -Write-Verbose ($alreadyInstalled | Format-Table | Out-String) +$alreadyInstalled | Format-Table if (-not $alreadyInstalled) { - Write-Verbose "Installing module. Name: [$Name], Version: [$Version], Prerelease: [$Prerelease]" $params = @{ Name = $Name Repository = 'PSGallery' @@ -38,36 +35,47 @@ if (-not $alreadyInstalled) { $alreadyImported = Get-Module -Name $Name Write-Verbose 'Already imported:' -Write-Verbose ($alreadyImported | Format-Table | Out-String) +$alreadyImported | Format-Table 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]" +[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-Host '::endgroup::' + +LogGroup ' - Installed modules' { + Get-InstalledPSResource | Select-Object Name, Version, Prerelease | Sort-Object -Property Name | Format-Table -AutoSize +} -if ($providedClientID -and $providedPrivateKey) { - LogGroup 'Connecting using provided GitHub App' { +LogGroup ' - GitHub connection' { + if ($providedClientID -and $providedPrivateKey) { + Write-Verbose 'Connected 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' { + } elseif ($providedToken) { + Write-Verbose 'Connected using provided token' Connect-GitHub -Token $env:GITHUB_ACTION_INPUT_Token -Silent - Get-GitHubContext | Format-Table -AutoSize } + Get-GitHubContext | Format-List +} + +LogGroup ' - Configuration' { + Get-GitHubConfig | Format-List } + +Write-Host '┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛' + +$DebugPreference = $env:GITHUB_ACTION_INPUT_Debug -eq 'true' ? 'Continue' : 'SilentlyContinue' +$VerbosePreference = $env:GITHUB_ACTION_INPUT_Verbose -eq 'true' ? 'Continue' : 'SilentlyContinue'