Skip to content

Commit 1ee508d

Browse files
committed
Fail pipeline
1 parent 27e1bb4 commit 1ee508d

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

validations/Validate-EntraModule.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ param(
1313
$validator = [Validator]::new($ModuleName)
1414

1515
$validator.ValidateScriptSubFoldersMatchDocsSubFolders()
16-
$validator.ValidateScriptSubFolderFilesMatchDocsSubFolderFiles()
16+
$validator.ValidateScriptSubFolderFilesMatchDocsSubFolderFiles()
17+
18+
# Exit the pipeline with an error if any validation failed
19+
$validator.ExitPipeline()

validations/Validator.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Validator {
99
[string] $ScriptsFolderPath
1010
[string] $DocsFolderPath
1111
[string[]] $SubModules
12+
hidden [int] $ErrorCount
1213

1314
# Constructor to initialize the validation paths based on the module name
1415
Validator([string] $Module) {
@@ -26,25 +27,29 @@ class Validator {
2627

2728
$this.ScriptsFolderPath = (Join-Path $PSScriptRoot "../module/$Module/$($this.RootModuleName)")
2829
$this.DocsFolderPath = (Join-Path $PSScriptRoot "../module/docs/$($this.DocFolderName)")
30+
$this.ErrorCount = 0
2931
}
3032

3133
# Method to validate that script subfolders match docs subfolders
3234
ValidateScriptSubFoldersMatchDocsSubFolders() {
3335
$scriptSubModules = @(Get-ChildItem -Path $this.ScriptsFolderPath -Directory)
3436
$docSubModules = @(Get-ChildItem -Path $this.DocsFolderPath -Directory)
3537
if($scriptSubModules.Count -ne $docSubModules.Count){
38+
$this.ErrorCount++
3639
$this.WriteWarning("Script submodules folders count ($($scriptSubModules.Count)) does not match docs submodules folders count ($($docSubModules.Count)).")
3740
}
3841

3942
$missingScriptFolders = @()
4043
$missingDocFolders = @()
4144
foreach($scriptSubModule in $scriptSubModules){
4245
if($docSubModules.Name -notcontains $scriptSubModule.Name){
46+
$this.ErrorCount++
4347
$this.WriteWarning("Script submodule folder '$($scriptSubModule.Name)' does not have a corresponding docs submodule folder.")
4448
}
4549
}
4650
foreach($docSubModule in $docSubModules){
4751
if($scriptSubModules.Name -notcontains $docSubModule.Name){
52+
$this.ErrorCount++
4853
$this.WriteWarning("Doc submodule folder '$($docSubModule.Name)' does not have a corresponding script submodule folder.")
4954
}
5055
}
@@ -56,17 +61,20 @@ class Validator {
5661
$scriptFiles = @(Get-ChildItem -Path (Join-Path $this.ScriptsFolderPath $subModule) -Filter *.ps1 | Where-Object { $_.Name -ne "New-EntraCustomHeaders.ps1" -and $_.Name -ne "New-EntraBetaCustomHeaders.ps1" })
5762
$docFiles = @(Get-ChildItem -Path (Join-Path $this.DocsFolderPath $subModule) -File)
5863
if($scriptFiles.Count -ne $docFiles.Count){
64+
$this.ErrorCount++
5965
$this.WriteWarning("Script submodule folder '$subModule' files count ($($scriptFiles.Count)) does not match docs submodule folder '$subModule' files count ($($docFiles.Count)).")
6066
}
6167

6268
foreach($scriptFile in $scriptFiles){
6369
if($docFiles.BaseName -notcontains $scriptFile.BaseName){
70+
$this.ErrorCount++
6471
$this.WriteWarning("Script file '$($scriptFile.BaseName)' in subfolder '$subModule' does not have a corresponding doc file.")
6572
}
6673
}
6774

6875
foreach($docFile in $docFiles){
6976
if($scriptFiles.BaseName -notcontains $docFile.BaseName){
77+
$this.ErrorCount++
7078
$this.WriteWarning("Doc file '$($docFile.BaseName)' in subfolder '$subModule' does not have a corresponding script file.")
7179
}
7280
}
@@ -83,4 +91,13 @@ class Validator {
8391
Write-Host "ERROR: $message" -ForegroundColor Red
8492
throw $message
8593
}
94+
95+
ExitPipeline() {
96+
if($this.ErrorCount -gt 0){
97+
$this.WriteError("Validation failed with $($this.ErrorCount) errors.")
98+
}
99+
else {
100+
Write-Host "Validation completed successfully."
101+
}
102+
}
86103
}

0 commit comments

Comments
 (0)