Skip to content

🩹 [Patch]: Fix gh auth status issue + add complex and actual use-case for Set-GitHubOutput #41

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 48 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
0a07b99
🩹 [Patch]: Add complex array output and JSON conversion to TestWorkflow
MariusStorhaug Feb 24, 2025
94a0a4a
🩹 [Patch]: Add logging for JSON and object results in TestWorkflow
MariusStorhaug Feb 24, 2025
5c022f0
🩹 [Patch]: Add additional environment variables for Zen and ComplexAr…
MariusStorhaug Feb 24, 2025
cd0b45e
🩹 [Patch]: Add push trigger to Action-Test workflow and comment out u…
MariusStorhaug Feb 24, 2025
a584050
```
MariusStorhaug Feb 24, 2025
e91ef7d
🩹 [Patch]: Uncomment output variables for Context, GitConfig, and Zen…
MariusStorhaug Feb 24, 2025
b7418bd
🩹 [Patch]: Update authentication check in info.ps1 to include provide…
MariusStorhaug Feb 24, 2025
61ae7cb
🩹 [Patch]: Refactor logging in TestWorkflow to enhance output clarity…
MariusStorhaug Feb 24, 2025
a37995d
🩹 [Patch]: Enhance TestWorkflow by adding summary logging and adjusti…
MariusStorhaug Feb 24, 2025
3598962
🩹 [Patch]: Uncomment Context output variable in TestWorkflow for impr…
MariusStorhaug Feb 24, 2025
d1cd0ea
🩹 [Patch]: Update Context output variable in TestWorkflow to include …
MariusStorhaug Feb 24, 2025
c61cf5e
🩹 [Patch]: Update Context output variable in TestWorkflow to correctl…
MariusStorhaug Feb 24, 2025
c377933
Fix authentication check in info.ps1 to correctly handle LASTEXITCODE…
MariusStorhaug Feb 24, 2025
af99a36
🩹 [Patch]: Improve authentication check in info.ps1 to enhance token …
MariusStorhaug Feb 24, 2025
800ef85
🩹 [Patch]: Update Context output variable in TestWorkflow to use toJs…
MariusStorhaug Feb 24, 2025
4387446
🩹 [Patch]: Update GitConfig output variable in TestWorkflow to use to…
MariusStorhaug Feb 24, 2025
4391f50
🩹 [Patch]: Update ComplexArray output variable in TestWorkflow to use…
MariusStorhaug Feb 24, 2025
8b1b8d9
🩹 [Patch]: Refactor TestWorkflow to remove unnecessary toJson calls a…
MariusStorhaug Feb 24, 2025
1cef44a
🩹 [Patch]: Comment out unused output variables in TestWorkflow for cl…
MariusStorhaug Feb 24, 2025
eb5d894
🩹 [Patch]: Fix logic in info.ps1 for accurate GitHub CLI authenticati…
MariusStorhaug Feb 24, 2025
22afc77
🩹 [Patch]: Uncomment ComplexArray output variable in TestWorkflow for…
MariusStorhaug Feb 24, 2025
efec0dc
🩹 [Patch]: Add MatrixTest output to ActionTestCommands and implement …
MariusStorhaug Feb 24, 2025
2d4b8bb
🩹 [Patch]: Simplify MatrixTest configuration in TestWorkflow by remov…
MariusStorhaug Feb 24, 2025
5566dc1
🩹 [Patch]: Refactor MatrixTest configuration in TestWorkflow to use a…
MariusStorhaug Feb 24, 2025
bdca73a
🩹 [Patch]: Correct casing of 'Include' to 'include' in MatrixTest con…
MariusStorhaug Feb 24, 2025
64103ac
🩹 [Patch]: Update Action-Test workflow to implement matrix strategy f…
MariusStorhaug Feb 24, 2025
a5989b0
🩹 [Patch]: Update Action-Test workflow to set Prerelease to true and …
MariusStorhaug Feb 24, 2025
d7ceb86
🩹 [Patch]: Update Action-Test workflow to change MatrixTest environme…
MariusStorhaug Feb 24, 2025
ab7b8a2
🩹 [Patch]: Simplify MatrixTest strategy configuration in Action-Test …
MariusStorhaug Feb 24, 2025
9204ce3
🩹 [Patch]: Remove redundant 'Path' assignment in MatrixTest configura…
MariusStorhaug Feb 24, 2025
48dd028
🩹 [Patch]: Add 'Path' assignment to MatrixTest configuration for test…
MariusStorhaug Feb 24, 2025
21f53ca
🩹 [Patch]: Update MatrixTest configuration to use specific test direc…
MariusStorhaug Feb 24, 2025
6b4cb14
🩹 [Patch]: Refactor MatrixTest configuration to consolidate 'RunsOn' …
MariusStorhaug Feb 24, 2025
3a572eb
Refactor MatrixTest output assignment to improve clarity and consiste…
MariusStorhaug Feb 24, 2025
0c42071
🩹 [Patch]: Refactor Action-Test workflow to streamline matrix creatio…
MariusStorhaug Feb 24, 2025
ca43399
🩹 [Patch]: Enhance Matrix Test step to capture and display created di…
MariusStorhaug Feb 25, 2025
82809ac
🩹 [Patch]: Add installation of GitHub PSResource in TestWorkflow for …
MariusStorhaug Feb 25, 2025
38b2b22
🩹 [Patch]: Update Matrix Test to create a custom object for directory…
MariusStorhaug Feb 25, 2025
8b2e62b
🩹 [Patch]: Add logging for PSMODULE_GITHUB_SCRIPT in TestWorkflow to …
MariusStorhaug Feb 25, 2025
e5e0103
🩹 [Patch]: Add verbose and debug output to Set-GithubOutput in TestWo…
MariusStorhaug Feb 25, 2025
23ab417
🩹 [Patch]: Update TestWorkflow to install GitHub PSResource with -Pre…
MariusStorhaug Feb 25, 2025
cb71a50
🩹 [Patch]: Enhance TestWorkflow logging and validation for environmen…
MariusStorhaug Feb 25, 2025
3fa9ff2
🩹 [Patch]: Refactor JSON validation checks in TestWorkflow for improv…
MariusStorhaug Feb 25, 2025
1bb1917
🩹 [Patch]: Add type checks for GitConfig and Context in TestWorkflow …
MariusStorhaug Feb 25, 2025
a4bc0c8
🩹 [Patch]: Add JSON conversion and validation for Item in TestWorkflo…
MariusStorhaug Feb 25, 2025
69b1b72
🩹 [Patch]: Update GitConfig type check in TestWorkflow to ensure it i…
MariusStorhaug Feb 25, 2025
d8e4338
🩹 [Patch]: Change Write-Output to Write-Verbose for improved logging …
MariusStorhaug Feb 25, 2025
d227f36
🩹 [Patch]: Remove push trigger from Action-Test-Prerelease workflow f…
MariusStorhaug Feb 25, 2025
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
181 changes: 176 additions & 5 deletions .github/workflows/TestWorkflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions scripts/info.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down