Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions azuredevops-pihole-pester-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,34 @@ steps:
foreach ($file in $changedFiles) {
if ($runFullSuite) { break }

if ($file -match '^PiHoleShell/Private/' -or
$file -eq 'PiHoleShell/PiHoleShell.psm1' -or
if ($file -eq 'PiHoleShell/PiHoleShell.psm1') {
# A pure addition to the export list can't break any existing, already-
# passing test, so only fall back to the full suite when an existing
# export was actually removed. Comparing whole diff lines doesn't work
# here since several exports share one line - adding a new function to
# an existing category's line shows as that whole line being removed
# and re-added, even though nothing already there was dropped. Instead,
# extract the quoted names from just the removed lines and just the
# added lines and compare those sets: a name that reappears in the
# added lines was only reformatted, not actually removed.
$manifestDiff = git diff "origin/$targetBranch...HEAD" -- $file
if ($LASTEXITCODE -ne 0) { throw "git diff failed for '$file'" }

$removedLines = ($manifestDiff | Where-Object { $_ -match '^-' -and $_ -notmatch '^---' }) -join "`n"
$addedLines = ($manifestDiff | Where-Object { $_ -match '^\+' -and $_ -notmatch '^\+\+\+' }) -join "`n"
$removedNames = [regex]::Matches($removedLines, "'([A-Za-z0-9-]+)'") | ForEach-Object { $_.Groups[1].Value }
$addedNames = [regex]::Matches($addedLines, "'([A-Za-z0-9-]+)'") | ForEach-Object { $_.Groups[1].Value }

$trulyRemoved = $removedNames | Where-Object { $_ -notin $addedNames }
if ($trulyRemoved) {
Write-Host "Export(s) removed from $file ($($trulyRemoved -join ', ')) - running the full suite"
$runFullSuite = $true
}
else {
Write-Host "Only additions in $file - no full-suite fallback needed"
}
}
elseif ($file -match '^PiHoleShell/Private/' -or
$file -eq 'PiHoleShell/PiHoleShell.psd1' -or
$file -eq 'PiHoleShell/Public/Authentication/Request-PiHoleAuth.ps1' -or
$file -eq 'tests/Initialize-PiHoleTestData.ps1' -or
Expand Down
Loading