Skip to content

Commit 6d34fa6

Browse files
Add validation script for output help text format
Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
1 parent 6c69c9d commit 6d34fa6

File tree

2 files changed

+157
-0
lines changed

2 files changed

+157
-0
lines changed

.github/workflows/TestWorkflow.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,13 @@ jobs:
399399
Write-Host "✅ Both access patterns work correctly"
400400
}
401401
402+
# Test 4: Validate output help text format
403+
- name: Validate Output Help Text Format
404+
shell: pwsh
405+
run: |
406+
& ./tests/validate-output-help-text.ps1
407+
408+
402409
MatrixCreator:
403410
name: Matrix Creator
404411
runs-on: ubuntu-latest
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
#!/usr/bin/env pwsh
2+
#Requires -Version 7.0
3+
4+
<#
5+
.SYNOPSIS
6+
Validates that the output help text suggestions are correct for both direct and nested usage.
7+
8+
.DESCRIPTION
9+
This script tests the logic that generates help text in outputs.ps1 to ensure:
10+
1. Direct usage shows the correct step ID
11+
2. Nested usage shows the placeholder text for user's step ID
12+
3. The format is correct for both scenarios
13+
#>
14+
15+
[CmdletBinding()]
16+
param()
17+
18+
$ErrorActionPreference = 'Stop'
19+
20+
function Test-OutputHelpText {
21+
param(
22+
[string]$StepId,
23+
[string]$OutputName,
24+
[bool]$HasStepId
25+
)
26+
27+
$blue = $PSStyle.Foreground.Blue
28+
$reset = $PSStyle.Reset
29+
30+
Write-Host "`n=== Testing Output Help Text ===" -ForegroundColor Cyan
31+
Write-Host "Step ID: $StepId" -ForegroundColor Yellow
32+
Write-Host "Output Name: $OutputName" -ForegroundColor Yellow
33+
Write-Host "Has Step ID: $HasStepId" -ForegroundColor Yellow
34+
35+
if ($HasStepId -and -not [string]::IsNullOrEmpty($StepId)) {
36+
# Simulate what outputs.ps1 does for direct usage
37+
$directUsage = "Direct usage: [$blue`${{ fromJson(steps.$StepId.outputs.result).$OutputName }}$reset]"
38+
$nestedUsage = "Nested usage: [$blue`${{ fromJson(steps.<your-step-id>.outputs.result).$OutputName }}$reset]"
39+
40+
Write-Host "`nGenerated help text:" -ForegroundColor Green
41+
Write-Host $directUsage
42+
Write-Host $nestedUsage
43+
44+
# Remove ANSI codes for validation
45+
$directUsageClean = $directUsage -replace '\x1b\[[0-9;]*m', ''
46+
$nestedUsageClean = $nestedUsage -replace '\x1b\[[0-9;]*m', ''
47+
48+
# Validate the format
49+
$expectedDirectPattern = "\$\{\{ fromJson\(steps\.$StepId\.outputs\.result\)\.$OutputName \}\}"
50+
$expectedNestedPattern = "\$\{\{ fromJson\(steps\.<your-step-id>\.outputs\.result\)\.$OutputName \}\}"
51+
52+
if ($directUsageClean -match $expectedDirectPattern) {
53+
Write-Host "✅ Direct usage pattern is correct" -ForegroundColor Green
54+
} else {
55+
Write-Error "❌ Direct usage pattern is incorrect"
56+
return $false
57+
}
58+
59+
if ($nestedUsageClean -match $expectedNestedPattern) {
60+
Write-Host "✅ Nested usage pattern is correct" -ForegroundColor Green
61+
} else {
62+
Write-Error "❌ Nested usage pattern is incorrect"
63+
return $false
64+
}
65+
66+
# Verify both lines are present
67+
if ($directUsage -match "Direct usage:") {
68+
Write-Host "✅ Direct usage label is present" -ForegroundColor Green
69+
} else {
70+
Write-Error "❌ Direct usage label is missing"
71+
return $false
72+
}
73+
74+
if ($nestedUsage -match "Nested usage:") {
75+
Write-Host "✅ Nested usage label is present" -ForegroundColor Green
76+
} else {
77+
Write-Error "❌ Nested usage label is missing"
78+
return $false
79+
}
80+
81+
} else {
82+
# Simulate what outputs.ps1 does when step ID is not available
83+
$genericUsage = "Accessible via: [$blue`${{ fromJson(steps.<step-id>.outputs.result).$OutputName }}$reset]"
84+
85+
Write-Host "`nGenerated help text:" -ForegroundColor Green
86+
Write-Host $genericUsage
87+
88+
# Remove ANSI codes for validation
89+
$genericUsageClean = $genericUsage -replace '\x1b\[[0-9;]*m', ''
90+
91+
$expectedGenericPattern = "\$\{\{ fromJson\(steps\.<step-id>\.outputs\.result\)\.$OutputName \}\}"
92+
93+
if ($genericUsageClean -match $expectedGenericPattern) {
94+
Write-Host "✅ Generic usage pattern is correct" -ForegroundColor Green
95+
} else {
96+
Write-Error "❌ Generic usage pattern is incorrect"
97+
return $false
98+
}
99+
}
100+
101+
return $true
102+
}
103+
104+
# Test scenarios
105+
$testsPassed = 0
106+
$testsFailed = 0
107+
108+
Write-Host "`n========================================" -ForegroundColor Magenta
109+
Write-Host "Testing Direct Usage Scenario" -ForegroundColor Magenta
110+
Write-Host "========================================" -ForegroundColor Magenta
111+
112+
if (Test-OutputHelpText -StepId "direct-test" -OutputName "DirectOutput" -HasStepId $true) {
113+
$testsPassed++
114+
} else {
115+
$testsFailed++
116+
}
117+
118+
Write-Host "`n========================================" -ForegroundColor Magenta
119+
Write-Host "Testing Composite Action Usage Scenario" -ForegroundColor Magenta
120+
Write-Host "========================================" -ForegroundColor Magenta
121+
122+
if (Test-OutputHelpText -StepId "composite-test" -OutputName "TestOutput1" -HasStepId $true) {
123+
$testsPassed++
124+
} else {
125+
$testsFailed++
126+
}
127+
128+
Write-Host "`n========================================" -ForegroundColor Magenta
129+
Write-Host "Testing Scenario Without Step ID" -ForegroundColor Magenta
130+
Write-Host "========================================" -ForegroundColor Magenta
131+
132+
if (Test-OutputHelpText -StepId "" -OutputName "SomeOutput" -HasStepId $false) {
133+
$testsPassed++
134+
} else {
135+
$testsFailed++
136+
}
137+
138+
Write-Host "`n========================================" -ForegroundColor Magenta
139+
Write-Host "Test Summary" -ForegroundColor Magenta
140+
Write-Host "========================================" -ForegroundColor Magenta
141+
Write-Host "Tests Passed: $testsPassed" -ForegroundColor Green
142+
Write-Host "Tests Failed: $testsFailed" -ForegroundColor $(if ($testsFailed -gt 0) { 'Red' } else { 'Green' })
143+
144+
if ($testsFailed -gt 0) {
145+
Write-Error "Some tests failed!"
146+
exit 1
147+
}
148+
149+
Write-Host "`n✅ All validation tests passed!" -ForegroundColor Green
150+
exit 0

0 commit comments

Comments
 (0)