Skip to content

🚀 [Feature]: Add an option to output the outputs #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 5, 2025
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
4 changes: 3 additions & 1 deletion .github/workflows/Action-Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ jobs:
Debug: true
Verbose: true
Prerelease: true
ShowOutput: true
Script: |
$cat = Get-GitHubOctocat
$zen = Get-GitHubZen
Expand All @@ -79,9 +80,10 @@ jobs:
shell: pwsh
env:
result: ${{ steps.test.outputs.result }}
WISECAT: ${{ fromJson(steps.test.outputs.result).WISECAT }}
run: |
$result = $env:result | ConvertFrom-Json
Set-GitHubStepSummary -Summary $result.WISECAT
Set-GitHubStepSummary -Summary $env:WISECAT
Write-GitHubNotice -Message $result.Zen -Title 'GitHub Zen'

ActionTestWithoutToken:
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

A GitHub Action used for running a PowerShell Script that uses the GitHub PowerShell module.

For more information on the available functions and automatic loaded variables, see the [GitHub PowerShell module documentation](https://psmodule.io/GitHub)
For more information on the available functions and automatic loaded variables, see the
[GitHub PowerShell module documentation](https://psmodule.io/GitHub)

## Usage

Expand All @@ -18,6 +19,7 @@ For more information on the available functions and automatic loaded variables,
| `Verbose` | Enable verbose output. | false | `'false'` |
| `Version` | Specifies the version of the GitHub module to be installed. The value must be an exact version. | false | |
| `Prerelease` | Allow prerelease versions if available. | false | `'false'` |
| `ShowOutput` | Show the output of the script. | false | `'false'` |
| `WorkingDirectory` | The working directory where the script will run from. | false | `${{ github.workspace }}` |

### Outputs
Expand Down
12 changes: 9 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ inputs:
description: Allow prerelease versions if available.
required: false
default: 'false'
ShowOutput:
description: Show the output of the script.
required: false
default: 'false'
WorkingDirectory:
description: The working directory where the script will run from.
required: false
Expand All @@ -42,14 +46,14 @@ inputs:
outputs:
result:
description: The output of the script as a JSON object. To add outputs to `result`, use `Set-GitHubOutput`.
value: ${{ steps.RunGitGubScript.outputs.result }}
value: ${{ steps.RunGitHubScript.outputs.result }}

runs:
using: composite
steps:
- name: Install GitHub
shell: pwsh
id: RunGitGubScript
id: RunGitHubScript
working-directory: ${{ inputs.WorkingDirectory }}
env:
GITHUB_ACTION_INPUT_Token: ${{ inputs.Token }}
Expand All @@ -58,8 +62,10 @@ runs:
GITHUB_ACTION_INPUT_Debug: ${{ inputs.Debug }}
GITHUB_ACTION_INPUT_Verbose: ${{ inputs.Verbose }}
GITHUB_ACTION_INPUT_Version: ${{ inputs.Version }}
GITHUB_ACTION_INPUT_ShowOutput: ${{ inputs.ShowOutput }}
GITHUB_ACTION_INPUT_Prerelease: ${{ inputs.Prerelease }}
run: |
# GitHub-Script
. "${{ github.action_path }}\scripts\main.ps1"
. $(Join-Path -Path '${{ github.action_path }}' -ChildPath 'scripts\main.ps1')
${{ inputs.Script }}
. $(Join-Path -Path '${{ github.action_path }}' -ChildPath 'scripts\outputs.ps1')
3 changes: 3 additions & 0 deletions scripts/main.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[CmdletBinding()]
param()

$Host.UI.RawUI.WindowSize.Width = 500
$Host.UI.RawUI.BufferSize.Width = 500

$env:PSMODULE_GITHUB_SCRIPT = $true
Write-Host "┏━━━━━┫ GitHub-Script ┣━━━━━┓"
Write-Host '::group:: - Setup GitHub PowerShell'
Expand Down
31 changes: 31 additions & 0 deletions scripts/outputs.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[CmdletBinding()]
param()

$DebugPreference = 'SilentlyContinue'
$VerbosePreference = 'SilentlyContinue'

if ($env:GITHUB_ACTION_INPUT_ShowOutput -ne 'true') {
return
}

$result = (Get-GitHubOutput).result
if (-not $result) {
return
}

Write-Host '┏━━━━━┫ GitHub-Script ┣━━━━━┓'

LogGroup ' - Outputs' {
if ([string]::IsNullOrEmpty($env:GITHUB_ACTION)) {
Write-GitHubWarning 'Outputs cannot be accessed as the step has no ID.'
}

if (-not (Test-Path -Path $env:GITHUB_OUTPUT)) {
Write-Warning "File not found: $env:GITHUB_OUTPUT"
}

$result | Format-List
Write-Host "Access outputs using `${{ fromJson(steps.$env:GITHUB_ACTION.outputs.result).<output-name> }}"
}

Write-Host '┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛'
Loading