Przeglądaj źródła

Don't verify baselines in CodeCheck when not in a PR build (#30462)

John Luo 5 lat temu
rodzic
commit
8aa4da4db3
1 zmienionych plików z 26 dodań i 23 usunięć
  1. 26 23
      eng/scripts/CodeCheck.ps1

+ 26 - 23
eng/scripts/CodeCheck.ps1

@@ -192,36 +192,39 @@ try {
     }
 
     $targetBranch = $env:SYSTEM_PULLREQUEST_TARGETBRANCH
-    if ($targetBranch.StartsWith('refs/heads/')) {
-        $targetBranch = $targetBranch.Replace('refs/heads/','')
-    }
 
-    # Retrieve the set of changed files compared to main
-    Write-Host "Checking for changes to API baseline files $targetBranch"
+    if (![string]::IsNullOrEmpty($targetBranch)) {
+        if ($targetBranch.StartsWith('refs/heads/')) {
+            $targetBranch = $targetBranch.Replace('refs/heads/','')
+        }
+
+        # Retrieve the set of changed files compared to main
+        Write-Host "Checking for changes to API baseline files $targetBranch"
 
-    $changedFilesFromTarget = git --no-pager diff origin/$targetBranch --ignore-space-change --name-only --diff-filter=ar
-    $changedAPIBaselines = [System.Collections.Generic.List[string]]::new()
+        $changedFilesFromTarget = git --no-pager diff origin/$targetBranch --ignore-space-change --name-only --diff-filter=ar
+        $changedAPIBaselines = [System.Collections.Generic.List[string]]::new()
 
-    if ($changedFilesFromTarget) {
-        foreach ($file in $changedFilesFromTarget) {
-            # Check for changes in Shipped in all branches
-            if ($file -like '*PublicAPI.Shipped.txt') {
-                $changedAPIBaselines.Add($file)
-            }
-            # Check for changes in Unshipped in servicing branches
-            if ($targetBranch -like 'release*' -and $file -like '*PublicAPI.Unshipped.txt') {
-                $changedAPIBaselines.Add($file)
+        if ($changedFilesFromTarget) {
+            foreach ($file in $changedFilesFromTarget) {
+                # Check for changes in Shipped in all branches
+                if ($file -like '*PublicAPI.Shipped.txt') {
+                    $changedAPIBaselines.Add($file)
+                }
+                # Check for changes in Unshipped in servicing branches
+                if ($targetBranch -like 'release*' -and $file -like '*PublicAPI.Unshipped.txt') {
+                    $changedAPIBaselines.Add($file)
+                }
             }
         }
-    }
 
-    Write-Host "Found changes in $($changedAPIBaselines.count) API baseline files"
+        Write-Host "Found changes in $($changedAPIBaselines.count) API baseline files"
 
-    if ($changedAPIBaselines.count -gt 0) {
-        LogError "Detected modification to baseline API files. PublicAPI.Shipped.txt files should only be updated after a major release. See /docs/APIBaselines.md for more information."
-        LogError "Modified API baseline files:"
-        foreach ($file in $changedAPIBaselines) {
-            LogError $file
+        if ($changedAPIBaselines.count -gt 0) {
+            LogError "Detected modification to baseline API files. PublicAPI.Shipped.txt files should only be updated after a major release. See /docs/APIBaselines.md for more information."
+            LogError "Modified API baseline files:"
+            foreach ($file in $changedAPIBaselines) {
+                LogError $file
+            }
         }
     }
 }