Skip to content

Commit b19f29e

Browse files
🚀 [Feature]: Add an option to output the outputs (#18)
## Description ### New functionality * Added a new input parameter `ShowOutput` to display the script's output in the logs. (`.github/workflows/Action-Test.yml`, `action.yml`, `scripts/outputs.ps1`) [[1]](diffhunk://#diff-a12ae5c885b0673c0ff6f70c2670886907590d624626e07da4c52e01aeaf56a4R71) [[2]](diffhunk://#diff-1243c5424efaaa19bd8e813c5e6f6da46316e63761421b3e5f5c8ced9a36e6b6R37-R40) [[3]](diffhunk://#diff-ee715ca93229232e95883bf00629fd14e3bf174cdc17b723c4cc5d70e6a60a58R1-R31) ### Bug fixes * Corrected a typo in the `action.yml` file from `RunGitGubScript` to `RunGitHubScript`. (`action.yml`) ### Documentation improvements * Updated the `README.md` to include the new `ShowOutput` parameter and improved formatting. (`README.md`) [[1]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L5-R6) [[2]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R22) ### Other changes * Adjusted the PowerShell script to set the window and buffer size for better output readability. (`scripts/main.ps1`) ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [x] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent d9a8681 commit b19f29e

File tree

5 files changed

+49
-5
lines changed

5 files changed

+49
-5
lines changed

.github/workflows/Action-Test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ jobs:
6868
Debug: true
6969
Verbose: true
7070
Prerelease: true
71+
ShowOutput: true
7172
Script: |
7273
$cat = Get-GitHubOctocat
7374
$zen = Get-GitHubZen
@@ -79,9 +80,10 @@ jobs:
7980
shell: pwsh
8081
env:
8182
result: ${{ steps.test.outputs.result }}
83+
WISECAT: ${{ fromJson(steps.test.outputs.result).WISECAT }}
8284
run: |
8385
$result = $env:result | ConvertFrom-Json
84-
Set-GitHubStepSummary -Summary $result.WISECAT
86+
Set-GitHubStepSummary -Summary $env:WISECAT
8587
Write-GitHubNotice -Message $result.Zen -Title 'GitHub Zen'
8688
8789
ActionTestWithoutToken:

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

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

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

78
## Usage
89

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

2325
### Outputs

action.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ inputs:
3434
description: Allow prerelease versions if available.
3535
required: false
3636
default: 'false'
37+
ShowOutput:
38+
description: Show the output of the script.
39+
required: false
40+
default: 'false'
3741
WorkingDirectory:
3842
description: The working directory where the script will run from.
3943
required: false
@@ -42,14 +46,14 @@ inputs:
4246
outputs:
4347
result:
4448
description: The output of the script as a JSON object. To add outputs to `result`, use `Set-GitHubOutput`.
45-
value: ${{ steps.RunGitGubScript.outputs.result }}
49+
value: ${{ steps.RunGitHubScript.outputs.result }}
4650

4751
runs:
4852
using: composite
4953
steps:
5054
- name: Install GitHub
5155
shell: pwsh
52-
id: RunGitGubScript
56+
id: RunGitHubScript
5357
working-directory: ${{ inputs.WorkingDirectory }}
5458
env:
5559
GITHUB_ACTION_INPUT_Token: ${{ inputs.Token }}
@@ -58,8 +62,10 @@ runs:
5862
GITHUB_ACTION_INPUT_Debug: ${{ inputs.Debug }}
5963
GITHUB_ACTION_INPUT_Verbose: ${{ inputs.Verbose }}
6064
GITHUB_ACTION_INPUT_Version: ${{ inputs.Version }}
65+
GITHUB_ACTION_INPUT_ShowOutput: ${{ inputs.ShowOutput }}
6166
GITHUB_ACTION_INPUT_Prerelease: ${{ inputs.Prerelease }}
6267
run: |
6368
# GitHub-Script
64-
. "${{ github.action_path }}\scripts\main.ps1"
69+
. $(Join-Path -Path '${{ github.action_path }}' -ChildPath 'scripts\main.ps1')
6570
${{ inputs.Script }}
71+
. $(Join-Path -Path '${{ github.action_path }}' -ChildPath 'scripts\outputs.ps1')

scripts/main.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
[CmdletBinding()]
22
param()
33

4+
$Host.UI.RawUI.WindowSize.Width = 500
5+
$Host.UI.RawUI.BufferSize.Width = 500
6+
47
$env:PSMODULE_GITHUB_SCRIPT = $true
58
Write-Host "┏━━━━━┫ GitHub-Script ┣━━━━━┓"
69
Write-Host '::group:: - Setup GitHub PowerShell'

scripts/outputs.ps1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[CmdletBinding()]
2+
param()
3+
4+
$DebugPreference = 'SilentlyContinue'
5+
$VerbosePreference = 'SilentlyContinue'
6+
7+
if ($env:GITHUB_ACTION_INPUT_ShowOutput -ne 'true') {
8+
return
9+
}
10+
11+
$result = (Get-GitHubOutput).result
12+
if (-not $result) {
13+
return
14+
}
15+
16+
Write-Host '┏━━━━━┫ GitHub-Script ┣━━━━━┓'
17+
18+
LogGroup ' - Outputs' {
19+
if ([string]::IsNullOrEmpty($env:GITHUB_ACTION)) {
20+
Write-GitHubWarning 'Outputs cannot be accessed as the step has no ID.'
21+
}
22+
23+
if (-not (Test-Path -Path $env:GITHUB_OUTPUT)) {
24+
Write-Warning "File not found: $env:GITHUB_OUTPUT"
25+
}
26+
27+
$result | Format-List
28+
Write-Host "Access outputs using `${{ fromJson(steps.$env:GITHUB_ACTION.outputs.result).<output-name> }}"
29+
}
30+
31+
Write-Host '┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛'

0 commit comments

Comments
 (0)