diff --git a/.github/workflows/TestWorkflow.yml b/.github/workflows/TestWorkflow.yml index b6e1105..37f20c3 100644 --- a/.github/workflows/TestWorkflow.yml +++ b/.github/workflows/TestWorkflow.yml @@ -130,6 +130,8 @@ jobs: ActionTestCommands: name: Commands + Outputs runs-on: ${{ inputs.runs-on }} + outputs: + MatrixTest: ${{ fromJson(steps.test.outputs.result).MatrixTest }} steps: # Need to check out as part of the test, as its a local action - name: Checkout repo @@ -171,18 +173,187 @@ jobs: Set-GitHubOutput -Name 'Zen2' -Value $zen } + LogGroup 'Set array outputs' { + $complexArray = @( + [pscustomobject]@{ + Name = 'Test' + Value = 'Value' + Cars = @( + @{ + Make = 'Toyota' + Model = 'Corolla' + }, + @{ + Make = 'Ford' + Model = 'Fiesta' + } + ) + }, + [pscustomobject]@{ + Name = 'Test2' + Value = 'Value2' + Cars = @( + @{ + Make = 'Toyota' + Model = 'Corolla' + }, + @{ + Make = 'Ford' + Model = 'Fiesta' + } + ) + } + ) + Set-GitHubOutput -Name 'ComplexArray' -Value $complexArray + } + + LogGroup 'Set array outputs - JSON' { + $compexJson = $complexArray | ConvertTo-Json -Depth 10 + Set-GitHubOutput -Name 'ComplexArrayJson' -Value $compexJson + } + + LogGroup 'Set summary' { + Get-Content $env:GITHUB_OUTPUT -Raw | Set-GitHubStepSummary + } + + - name: Run-test shell: pwsh env: result: ${{ steps.test.outputs.result }} WISECAT: ${{ fromJson(steps.test.outputs.result).WISECAT }} + Zen: ${{ fromJson(steps.test.outputs.result).Zen }} + Zen2: ${{ fromJson(steps.test.outputs.result).Zen2 }} + Context: ${{ fromJson(steps.test.outputs.result).Context }} + GitConfig: ${{ fromJson(steps.test.outputs.result).GitConfig }} + ComplexArray: ${{ fromJson(steps.test.outputs.result).ComplexArray }} + ComplexArrayJson: ${{ fromJson(steps.test.outputs.result).ComplexArrayJson }} run: | $result = $env:result | ConvertFrom-Json - Set-GitHubStepSummary -Summary $env:WISECAT - Write-GitHubNotice -Message $result.Zen -Title 'GitHub Zen' - Write-Host ($result.Zen2) - $result.Context | Format-List - $result.GitConfig | Format-List + + LogGroup 'Result - Json' { + $env:result + } + + LogGroup 'Result - Object' { + $result + } + + LogGroup "WISECAT" { + Write-Host $env:WISECAT + } + + LogGroup "Zen" { + Write-Host $env:Zen + } + + LogGroup "Context" { + $env:Context + } + + LogGroup "GitConfig" { + $env:GitConfig + } + + LogGroup "Zen2" { + Write-Host $env:Zen2 + } + + LogGroup "ComplexArray" { + $env:ComplexArray + if (-not (Test-Json -Json $env:ComplexArray)) { + Write-Host "Item is not a JSON object" + exit 1 + } + } + + LogGroup "ComplexArrayJson" { + $env:ComplexArrayJson + if (-not (Test-Json -Json $env:ComplexArrayJson)) { + Write-Host "Item is not a JSON object" + exit 1 + } + } + + LogGroup "Other" { + Set-GitHubStepSummary -Summary $env:WISECAT + Write-GitHubNotice -Message $result.Zen -Title 'GitHub Zen' + Write-Host ($result.Zen2) + $result.Context | Format-List + $result.Context.GetType().Name + if ($result.GitConfig -isnot [String]) { + throw "GitConfig is not a PSCustomObject" + } + + $result.GitConfig | Format-List + $result.GitConfig.GetType().Name + if ($result.GitConfig -isnot [String]) { + throw "GitConfig is a PSCustomObject" + } + } + + MatrixCreator: + name: Matrix Creator + runs-on: ubuntu-latest + outputs: + MatrixTest: ${{ fromJson(steps.test.outputs.result).MatrixTest }} + steps: + # Need to check out as part of the test, as its a local action + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Action-Test + uses: ./ + id: test + with: + Debug: true + Verbose: true + Prerelease: true + ShowInit: true + ShowOutput: true + Script: | + LogGroup 'MatrixTest' { + $matrixTest = @{ + Path = @('tests/srcTestRepo', 'tests/srcWithManifestTestRepo') + RunsOn = @('ubuntu-latest', 'windows-latest', 'macos-latest') + } + Set-GitHubOutput -Name 'MatrixTest' -Value $matrixTest + } + + MatrixTest: + needs: MatrixCreator + strategy: + matrix: ${{ fromJson(needs.MatrixCreator.outputs.MatrixTest) }} + name: Matrix Test [${{ matrix.RunsOn }}] + runs-on: ${{ matrix.RunsOn }} + steps: + - name: Matrix Test + shell: pwsh + id: test + env: + Path: ${{ matrix.Path }} + run: | + Install-PSResource -Name GitHub -TrustRepository -Prerelease + if ($PSMODULE_GITHUB_SCRIPT) { + throw "Is not running in GitHub-Script aciton! Failing" + } + $item = [pscustomobject]@{ + Path = $env:Path + Exists = Test-Path -Path $env:Path + } + Set-GithubOutput -Name 'Item' -Value $item + + - name: Matrix Test [Show] + shell: pwsh + env: + Item: ${{ steps.test.outputs.item }} + run: | + $env:Item + $env:Item | ConvertFrom-Json + + if (-not (Test-Json -Json $env:Item)) { + throw "Item is not a JSON object" + } ActionTestWithoutToken: name: WithoutToken diff --git a/scripts/info.ps1 b/scripts/info.ps1 index d794019..2ccdd73 100644 --- a/scripts/info.ps1 +++ b/scripts/info.ps1 @@ -28,10 +28,18 @@ process { $context = Get-GitHubContext $context | Format-List - if ($context.AuthType -ne 'APP') { + Write-Verbose "Token? [$([string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Token))]" + Write-Verbose "AuthType? [$($context.AuthType)] - [$($context.AuthType -ne 'APP')]" + Write-Verbose "gh auth? [$($context.AuthType -ne 'APP' -and -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Token))]" + + if ($context.AuthType -ne 'APP' -and -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Token)) { Write-Output 'GitHub CLI status:' + $before = $LASTEXITCODE gh auth status - $LASTEXITCODE = 0 + if ($LASTEXITCODE -ne $before) { + Write-Warning "LASTEXITCODE has changed [$LASTEXITCODE]" + $global:LASTEXITCODE = $before + } } }