diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index d60f839..72445dd 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -68,6 +68,7 @@ jobs: Debug: true Verbose: true Prerelease: true + ShowOutput: true Script: | $cat = Get-GitHubOctocat $zen = Get-GitHubZen @@ -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: diff --git a/README.md b/README.md index 4bb7d83..a6a7a9e 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/action.yml b/action.yml index 26a4163..5935e46 100644 --- a/action.yml +++ b/action.yml @@ -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 @@ -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 }} @@ -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') diff --git a/scripts/main.ps1 b/scripts/main.ps1 index db873ff..95b46bf 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -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' diff --git a/scripts/outputs.ps1 b/scripts/outputs.ps1 new file mode 100644 index 0000000..f067d6a --- /dev/null +++ b/scripts/outputs.ps1 @@ -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). }}" +} + +Write-Host '┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛'