Skip to content

Commit 6d8bea6

Browse files
committed
Refactor to not assume individual changed components when non-component changes aren't found, returning 'all' instead of empty component list.
1 parent d794325 commit 6d8bea6

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

Get-Changed-Components.ps1

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,40 @@ if (-not $ToSha) {
3232

3333
git fetch origin main
3434

35-
$changedComponentFiles = Invoke-Expression "git diff --name-only $($FromSha)...$($ToSha) -- components/"
36-
$otherChanges = Invoke-Expression "git diff --name-only $($FromSha)...$($ToSha) | Select-String -NotMatch '^components/'"
35+
$changedComponentFiles = Invoke-Expression "git diff --name-only $($FromSha)...$($ToSha) -- components/" -ErrorAction Stop
36+
$otherChanges = Invoke-Expression "git diff --name-only $($FromSha)...$($ToSha) | Select-String -NotMatch '^components/'" -ErrorAction Stop
3737

38-
if (-not $otherChanges) {
38+
# If one or more components is changed, return them in a list.
39+
$retChangedComponents = -not [string]::IsNullOrWhiteSpace($changedComponentFiles);
40+
41+
# Return 'all' components when either:
42+
# - One or more files *outside* of a component folder is changed
43+
# - All files *inside* of component folders are unchanged
44+
# Both of these:
45+
# - Can happen when any non-component file is changed
46+
# - May indicate (but not guarantee) a build configuration change.
47+
# - Are a fallback to ensure that the script doesn't return an empty list of components.
48+
$retAllComponents = [string]::IsNullOrWhiteSpace($changedComponentFiles) -or -not [string]::IsNullOrWhiteSpace($otherChanges);
49+
50+
Write-Output "Relevant vars: "
51+
Write-Output "`$fromSha: $FromSha"
52+
Write-Output "`$toSha: $ToSha"
53+
Write-Output "`$changedComponentFiles: $changedComponentFiles"
54+
Write-Output "`$otherChanges: $otherChanges"
55+
Write-Output "`$retChangedComponents: $retChangedComponents"
56+
Write-Output "`$retAllComponents: $retAllComponents"
57+
58+
if ($retAllComponents) {
59+
return 'all';
60+
}
61+
62+
if ($retChangedComponents) {
3963
$names = $changedComponentFiles | ForEach-Object { ($_ -replace '^components/', '') -replace '/.*$', '' }
4064
$uniqueNames = $names | Sort-Object -Unique
4165
$quotedNames = $uniqueNames | ForEach-Object { "'$_'" }
4266
$changedComponentsList = $quotedNames -join ','
4367
return $changedComponentsList
4468
}
45-
else {
46-
return 'all';
47-
}
69+
70+
Write-Error "Unhandled code path."
71+
Write-Error "Please report this error to the author of this script."

0 commit comments

Comments
 (0)