Skip to content

Commit 6c69c9d

Browse files
Add composite action test for nested output suggestions
Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
1 parent 4903704 commit 6c69c9d

2 files changed

Lines changed: 120 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Test Composite Action
2+
description: >-
3+
A composite action that wraps GitHub-Script for testing nested output
4+
suggestions
5+
author: PSModule
6+
7+
inputs:
8+
Prerelease:
9+
description: Allow prerelease versions if available.
10+
required: false
11+
default: 'false'
12+
13+
outputs:
14+
result:
15+
description: The output of the script as a JSON object
16+
value: ${{ steps.internal-github-script.outputs.result }}
17+
18+
runs:
19+
using: composite
20+
steps:
21+
- name: Run GitHub-Script internally
22+
id: internal-github-script
23+
uses: ./
24+
with:
25+
Name: Test-Composite-Internal
26+
Prerelease: ${{ inputs.Prerelease }}
27+
Debug: true
28+
Verbose: true
29+
ShowOutput: true
30+
Script: |
31+
LogGroup 'Set test outputs' {
32+
$value = 'Value from composite action'
33+
Set-GitHubOutput -Name 'TestOutput1' -Value $value
34+
Set-GitHubOutput -Name 'TestOutput2' -Value @{
35+
Key1 = 'Value1'
36+
Key2 = 'Value2'
37+
}
38+
$msg = 'This output is from a nested composite action'
39+
Set-GitHubOutput -Name 'CompositeMessage' -Value $msg
40+
}

.github/workflows/TestWorkflow.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,86 @@ jobs:
319319
}
320320
}
321321
322+
ActionTestCompositeOutputs:
323+
name: Composite Action Outputs Test
324+
runs-on: ${{ inputs.runs-on }}
325+
steps:
326+
# Need to check out as part of the test, as its a local action
327+
- name: Checkout repo
328+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
329+
with:
330+
persist-credentials: false
331+
332+
# Test 1: Direct usage of GitHub-Script action
333+
- name: Direct GitHub-Script Usage
334+
id: direct-test
335+
uses: ./
336+
with:
337+
Name: Direct-Usage-Test
338+
Prerelease: ${{ inputs.Prerelease }}
339+
ShowOutput: true
340+
Script: |
341+
Set-GitHubOutput -Name 'DirectOutput' -Value 'This is from direct usage'
342+
343+
# Test 2: Nested usage via composite action
344+
- name: Composite Action Usage
345+
id: composite-test
346+
uses: ./.github/actions/test-composite
347+
with:
348+
Prerelease: ${{ inputs.Prerelease }}
349+
350+
# Test 3: Verify outputs work correctly
351+
- name: Verify Outputs
352+
shell: pwsh
353+
env:
354+
DIRECT_OUTPUT: >-
355+
${{ fromJson(steps.direct-test.outputs.result).DirectOutput }}
356+
COMPOSITE_OUTPUT1: >-
357+
${{ fromJson(steps.composite-test.outputs.result).TestOutput1 }}
358+
COMPOSITE_OUTPUT2: >-
359+
${{ fromJson(steps.composite-test.outputs.result).TestOutput2 }}
360+
COMPOSITE_MESSAGE: >-
361+
${{ fromJson(steps.composite-test.outputs.result).CompositeMessage
362+
}}
363+
run: |
364+
$PSStyle.OutputRendering = 'Ansi'
365+
366+
LogGroup 'Verify Direct Output' {
367+
Write-Host "Direct Output: $env:DIRECT_OUTPUT"
368+
if ($env:DIRECT_OUTPUT -ne 'This is from direct usage') {
369+
throw "Direct output verification failed"
370+
}
371+
Write-Host "✅ Direct output is correct"
372+
}
373+
374+
LogGroup 'Verify Composite Outputs' {
375+
Write-Host "Composite Output 1: $env:COMPOSITE_OUTPUT1"
376+
Write-Host "Composite Output 2: $env:COMPOSITE_OUTPUT2"
377+
Write-Host "Composite Message: $env:COMPOSITE_MESSAGE"
378+
379+
if ($env:COMPOSITE_OUTPUT1 -ne 'Value from composite action') {
380+
throw "Composite output 1 verification failed"
381+
}
382+
$expectedMsg = 'This output is from a nested composite action'
383+
if ($env:COMPOSITE_MESSAGE -ne $expectedMsg) {
384+
throw "Composite message verification failed"
385+
}
386+
Write-Host "✅ Composite outputs are correct"
387+
}
388+
389+
LogGroup 'Test output access patterns' {
390+
# Verify the patterns shown in help text work
391+
$directPattern = @'
392+
${{ fromJson(steps.direct-test.outputs.result).DirectOutput }}
393+
'@
394+
$compositePattern = @'
395+
${{ fromJson(steps.composite-test.outputs.result).TestOutput1 }}
396+
'@
397+
Write-Host "Direct pattern used: $directPattern"
398+
Write-Host "Composite pattern used: $compositePattern"
399+
Write-Host "✅ Both access patterns work correctly"
400+
}
401+
322402
MatrixCreator:
323403
name: Matrix Creator
324404
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)