Skip to content

Commit c4d14dd

Browse files
feat: add JSON schema validation for settings and update README with action description
1 parent 441721c commit c4d14dd

4 files changed

Lines changed: 31 additions & 19 deletions

File tree

README.md

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
# Template-Action
1+
# Get-PSModuleSettings
22

3-
A template repository for GitHub Actions
4-
5-
## Usage
6-
7-
### Inputs
8-
9-
### Secrets
10-
11-
### Outputs
12-
13-
### Example
14-
15-
```yaml
16-
Example here
17-
```
3+
This GitHub Action is a part of the [PSModule framework](https://github.com/PSModule).

scripts/main.ps1

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,33 @@ if (![string]::IsNullOrEmpty($settingsPath) -and (Test-Path -Path $settingsPath)
3838
}
3939
}
4040
}
41+
42+
LogGroup 'Validate settings against schema' {
43+
$schemaPath = Join-Path $PSScriptRoot 'Settings.schema.json'
44+
if (Test-Path -Path $schemaPath) {
45+
Write-Host 'Validating settings against schema...'
46+
$schema = Get-Content $schemaPath -Raw
47+
48+
# Convert settings to JSON for validation
49+
$settingsJson = $settings | ConvertTo-Json -Depth 10
50+
51+
try {
52+
$isValid = Test-Json -Json $settingsJson -Schema $schema -ErrorAction Stop
53+
if ($isValid) {
54+
Write-Host '✓ Settings conform to schema'
55+
} else {
56+
throw 'Settings do not conform to the schema'
57+
}
58+
} catch {
59+
Write-Error "Schema validation failed: $_"
60+
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'
62+
throw
63+
}
64+
} else {
65+
Write-Warning "Schema file not found at [$schemaPath]. Skipping validation."
66+
}
67+
}
4168
} else {
4269
Write-Host 'No settings file present.'
4370
$settings = @{}
@@ -134,15 +161,14 @@ $settings = [pscustomobject]@{
134161
Skip = $settings.Publish.Module.Skip ?? $false
135162
AutoCleanup = $settings.Publish.Module.AutoCleanup ?? $true
136163
AutoPatching = $settings.Publish.Module.AutoPatching ?? $true
137-
IncrementalPrerelease = $settings.Publish.Module.IncrementalPrerelease ?? $true
164+
IncrementalPrerelease = $settings.Publish.Module.IncrementalPrerelease ?? $trueø
138165
DatePrereleaseFormat = $settings.Publish.Module.DatePrereleaseFormat ?? ''
139166
VersionPrefix = $settings.Publish.Module.VersionPrefix ?? 'v'
140167
MajorLabels = $settings.Publish.Module.MajorLabels ?? 'major, breaking'
141168
MinorLabels = $settings.Publish.Module.MinorLabels ?? 'minor, feature'
142169
PatchLabels = $settings.Publish.Module.PatchLabels ?? 'patch, fix'
143170
IgnoreLabels = $settings.Publish.Module.IgnoreLabels ?? 'NoRelease'
144171
}
145-
146172
}
147173
Linter = [pscustomobject]@{
148174
Skip = $settings.Linter.Skip ?? $false

tests/Validate-Settings.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Write-Host '=============================================='
3636

3737
# Validate against JSON schema
3838
Write-Host "`nValidating settings against JSON schema..."
39-
$schemaPath = Join-Path $PSScriptRoot 'Settings.schema.json'
39+
$schemaPath = Join-Path $PSScriptRoot '..' 'scripts' 'Settings.schema.json'
4040
$schema = Get-Content $schemaPath -Raw
4141
$isValid = Test-Json -Json $SettingsJson -Schema $schema
4242

0 commit comments

Comments
 (0)