@@ -1525,9 +1525,17 @@ def PrepareRepoInCwd(print_cmd_groups, initial_setup=False):
1525
1525
upload_corrupted_outputs (capture_corrupted_outputs_dir_index , tmpdir )
1526
1526
1527
1527
if platform == "windows" :
1528
- execute_batch_commands (task_config .get ("post_batch_commands" , None ), True , ":batch: Post Processing (Batch Commands)" )
1528
+ execute_batch_commands (
1529
+ task_config .get ("post_batch_commands" , None ),
1530
+ True ,
1531
+ ":batch: Post Processing (Batch Commands)" ,
1532
+ )
1529
1533
else :
1530
- execute_shell_commands (task_config .get ("post_shell_commands" , None ), True , ":bash: Post Processing (Shell Commands)" )
1534
+ execute_shell_commands (
1535
+ task_config .get ("post_shell_commands" , None ),
1536
+ True ,
1537
+ ":bash: Post Processing (Shell Commands)" ,
1538
+ )
1531
1539
1532
1540
finally :
1533
1541
terminate_background_process (sc_process )
@@ -1634,8 +1642,20 @@ def get_release_name_from_branch_name():
1634
1642
1635
1643
1636
1644
def is_pull_request ():
1637
- third_party_repo = os .getenv ("BUILDKITE_PULL_REQUEST_REPO" , "" )
1638
- return len (third_party_repo ) > 0
1645
+ try :
1646
+ return int (os .getenv ("BUILDKITE_PULL_REQUEST" )) > 0
1647
+ except :
1648
+ return False
1649
+
1650
+
1651
+ def is_third_party_fork ():
1652
+ if ":" in os .getenv (
1653
+ "BUILDKITE_BRANCH" , ""
1654
+ ): # Only works if "Prefix third-party fork branch names" is enabled
1655
+ return True
1656
+
1657
+ pr_repo = os .getenv ("BUILDKITE_PULL_REQUEST_REPO" , "" )
1658
+ return pr_repo and pr_repo .startswith ("https://github.com/bazelbuild/" )
1639
1659
1640
1660
1641
1661
def print_bazel_version_info (bazel_binary , platform ):
@@ -1817,7 +1837,9 @@ def clone_git_repository(git_repository, platform, git_commit=None):
1817
1837
return clone_path
1818
1838
1819
1839
1820
- def execute_batch_commands (commands , print_group = True , group_message = ":batch: Setup (Batch Commands)" ):
1840
+ def execute_batch_commands (
1841
+ commands , print_group = True , group_message = ":batch: Setup (Batch Commands)"
1842
+ ):
1821
1843
if not commands :
1822
1844
return
1823
1845
@@ -1828,7 +1850,9 @@ def execute_batch_commands(commands, print_group=True, group_message=":batch: Se
1828
1850
return subprocess .run (batch_commands , shell = True , check = True , env = os .environ ).returncode
1829
1851
1830
1852
1831
- def execute_shell_commands (commands , print_group = True , group_message = ":bash: Setup (Shell Commands)" ):
1853
+ def execute_shell_commands (
1854
+ commands , print_group = True , group_message = ":bash: Setup (Shell Commands)"
1855
+ ):
1832
1856
if not commands :
1833
1857
return
1834
1858
@@ -2181,7 +2205,9 @@ def calculate_targets(
2181
2205
2182
2206
build_targets = [] if test_only else list (task_config .get ("build_targets" , []))
2183
2207
test_targets = [] if build_only else list (task_config .get ("test_targets" , []))
2184
- coverage_targets = [] if (build_only or test_only ) else list (task_config .get ("coverage_targets" , []))
2208
+ coverage_targets = (
2209
+ [] if (build_only or test_only ) else list (task_config .get ("coverage_targets" , []))
2210
+ )
2185
2211
index_targets = [] if (build_only or test_only ) else list (task_config .get ("index_targets" , []))
2186
2212
2187
2213
index_targets_query = (
@@ -2767,6 +2793,16 @@ def print_project_pipeline(
2767
2793
if is_git_on_borg_repo (buildkite_repo ):
2768
2794
show_gerrit_review_link (buildkite_repo , pipeline_steps )
2769
2795
2796
+ # Only run presubmits from third-party forks after getting approval from someone with "Build & Read" permissions.
2797
+ if is_pull_request () and is_third_party_fork ():
2798
+ pipeline_steps .append (
2799
+ {
2800
+ "block" : ":cop: Authorize third-party presubmit run?" ,
2801
+ "prompt" : ":rotating_light: :warning: This is an untrusted pull request from a third-party fork. Only unblock the build if the code is not malicious." ,
2802
+ "blocked_state" : "running" ,
2803
+ }
2804
+ )
2805
+
2770
2806
task_configs = filter_tasks_that_should_be_skipped (task_configs , pipeline_steps )
2771
2807
2772
2808
# In Bazel Downstream Project pipelines, git_repository and project_name must be specified.
0 commit comments