@@ -1525,9 +1525,17 @@ def PrepareRepoInCwd(print_cmd_groups, initial_setup=False):
15251525 upload_corrupted_outputs (capture_corrupted_outputs_dir_index , tmpdir )
15261526
15271527 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+ )
15291533 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+ )
15311539
15321540 finally :
15331541 terminate_background_process (sc_process )
@@ -1634,8 +1642,20 @@ def get_release_name_from_branch_name():
16341642
16351643
16361644def 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/" )
16391659
16401660
16411661def print_bazel_version_info (bazel_binary , platform ):
@@ -1817,7 +1837,9 @@ def clone_git_repository(git_repository, platform, git_commit=None):
18171837 return clone_path
18181838
18191839
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+ ):
18211843 if not commands :
18221844 return
18231845
@@ -1828,7 +1850,9 @@ def execute_batch_commands(commands, print_group=True, group_message=":batch: Se
18281850 return subprocess .run (batch_commands , shell = True , check = True , env = os .environ ).returncode
18291851
18301852
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+ ):
18321856 if not commands :
18331857 return
18341858
@@ -2181,7 +2205,9 @@ def calculate_targets(
21812205
21822206 build_targets = [] if test_only else list (task_config .get ("build_targets" , []))
21832207 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+ )
21852211 index_targets = [] if (build_only or test_only ) else list (task_config .get ("index_targets" , []))
21862212
21872213 index_targets_query = (
@@ -2767,6 +2793,16 @@ def print_project_pipeline(
27672793 if is_git_on_borg_repo (buildkite_repo ):
27682794 show_gerrit_review_link (buildkite_repo , pipeline_steps )
27692795
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+
27702806 task_configs = filter_tasks_that_should_be_skipped (task_configs , pipeline_steps )
27712807
27722808 # In Bazel Downstream Project pipelines, git_repository and project_name must be specified.
0 commit comments