Skip to content

Commit 988ea7a

Browse files
feat: enhance action validation and output schema checks in workflows
1 parent 41ca109 commit 988ea7a

3 files changed

Lines changed: 49 additions & 41 deletions

File tree

.github/workflows/Action-Test.yml

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,25 @@ jobs:
3333
with:
3434
SettingsPath: './tests/scenarios/valid/PSModule.yml'
3535

36-
- name: Validate Settings Output
36+
- name: Verify Action Succeeded
3737
shell: pwsh
3838
env:
3939
SETTINGS_JSON: ${{ steps.get-settings.outputs.Settings }}
40-
run: ./tests/Validate-Settings.ps1
40+
run: |
41+
if ([string]::IsNullOrEmpty($env:SETTINGS_JSON)) {
42+
Write-Error 'Action failed to produce settings output'
43+
exit 1
44+
}
45+
Write-Host '✓ Action executed successfully and produced valid output'
46+
47+
# Verify the output is valid JSON
48+
try {
49+
$settings = $env:SETTINGS_JSON | ConvertFrom-Json
50+
Write-Host "✓ Settings output is valid JSON with Name: $($settings.Name)"
51+
} catch {
52+
Write-Error "Settings output is not valid JSON: $_"
53+
exit 1
54+
}
4155
4256
ActionTestInvalidMissingTestConfig:
4357
name: Action-Test - [Invalid - Missing Test Config]
@@ -49,21 +63,18 @@ jobs:
4963
with:
5064
persist-credentials: false
5165

52-
- name: Action-Test
66+
- name: Action-Test (Expect Failure)
5367
id: get-settings
68+
continue-on-error: true
5469
uses: ./
5570
with:
5671
SettingsPath: './tests/scenarios/invalid-missing-test-config/PSModule.yml'
5772

58-
- name: Validate Settings Output (Expect Failure)
73+
- name: Verify Action Failed as Expected
5974
shell: pwsh
60-
env:
61-
SETTINGS_JSON: ${{ steps.get-settings.outputs.Settings }}
6275
run: |
63-
$ErrorActionPreference = 'Continue'
64-
./tests/Validate-Settings.ps1
65-
if ($LASTEXITCODE -eq 0) {
66-
Write-Error 'Expected validation to fail for invalid configuration, but it succeeded'
76+
if ('${{ steps.get-settings.outcome }}' -eq 'success') {
77+
Write-Error 'Expected action to fail for invalid configuration, but it succeeded'
6778
exit 1
6879
}
69-
Write-Host '✓ Validation failed as expected for invalid configuration'
80+
Write-Host '✓ Action failed as expected for invalid configuration'

scripts/main.ps1

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ if (![string]::IsNullOrEmpty($settingsPath) -and (Test-Path -Path $settingsPath)
5858
} catch {
5959
Write-Error "Schema validation failed: $_"
6060
Write-Error 'Your settings file does not match the expected schema structure.'
61-
Write-Error 'Please refer to the schema documentation: https://github.com/PSModule/Get-PSModuleSettings#schema'
6261
throw
6362
}
6463
} else {
@@ -412,6 +411,32 @@ LogGroup 'Final settings' {
412411
Write-Host ($settings | ConvertTo-Json -Depth 5 | Out-String)
413412
}
414413
}
414+
Set-GitHubOutput -Name Settings -Value ($settings | ConvertTo-Json -Depth 10)
415415
}
416416

417-
Set-GitHubOutput -Name Settings -Value ($settings | ConvertTo-Json -Depth 10)
417+
LogGroup 'Validate output settings against schema' {
418+
$schemaPath = Join-Path $PSScriptRoot 'Settings.schema.json'
419+
if (Test-Path -Path $schemaPath) {
420+
Write-Host 'Validating output settings against schema...'
421+
$schema = Get-Content $schemaPath -Raw
422+
423+
# Convert output settings to JSON for validation
424+
$outputJson = $settings | ConvertTo-Json -Depth 10
425+
426+
try {
427+
$isValid = Test-Json -Json $outputJson -Schema $schema -ErrorAction Stop
428+
if ($isValid) {
429+
Write-Host '✓ Output settings conform to schema'
430+
} else {
431+
throw 'Output settings do not conform to the schema'
432+
}
433+
} catch {
434+
Write-Error "Output schema validation failed: $_"
435+
Write-Error 'The generated settings object does not match the expected schema structure.'
436+
Write-Error 'This indicates a bug in the action. Please report this issue.'
437+
throw
438+
}
439+
} else {
440+
Write-Warning "Schema file not found at [$schemaPath]. Skipping output validation."
441+
}
442+
}

tests/Validate-Settings.ps1

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)