@@ -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,21 @@ 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
+ # We don't accept PRs for GoB repos.
1659
+ return pr_repo and not pr_repo .startswith ("https://github.com/bazelbuild/" )
1639
1660
1640
1661
1641
1662
def print_bazel_version_info (bazel_binary , platform ):
@@ -1817,7 +1838,9 @@ def clone_git_repository(git_repository, platform, git_commit=None):
1817
1838
return clone_path
1818
1839
1819
1840
1820
- def execute_batch_commands (commands , print_group = True , group_message = ":batch: Setup (Batch Commands)" ):
1841
+ def execute_batch_commands (
1842
+ commands , print_group = True , group_message = ":batch: Setup (Batch Commands)"
1843
+ ):
1821
1844
if not commands :
1822
1845
return
1823
1846
@@ -1828,7 +1851,9 @@ def execute_batch_commands(commands, print_group=True, group_message=":batch: Se
1828
1851
return subprocess .run (batch_commands , shell = True , check = True , env = os .environ ).returncode
1829
1852
1830
1853
1831
- def execute_shell_commands (commands , print_group = True , group_message = ":bash: Setup (Shell Commands)" ):
1854
+ def execute_shell_commands (
1855
+ commands , print_group = True , group_message = ":bash: Setup (Shell Commands)"
1856
+ ):
1832
1857
if not commands :
1833
1858
return
1834
1859
@@ -2181,7 +2206,9 @@ def calculate_targets(
2181
2206
2182
2207
build_targets = [] if test_only else list (task_config .get ("build_targets" , []))
2183
2208
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" , []))
2209
+ coverage_targets = (
2210
+ [] if (build_only or test_only ) else list (task_config .get ("coverage_targets" , []))
2211
+ )
2185
2212
index_targets = [] if (build_only or test_only ) else list (task_config .get ("index_targets" , []))
2186
2213
2187
2214
index_targets_query = (
@@ -2767,6 +2794,19 @@ def print_project_pipeline(
2767
2794
if is_git_on_borg_repo (buildkite_repo ):
2768
2795
show_gerrit_review_link (buildkite_repo , pipeline_steps )
2769
2796
2797
+ # Only run presubmits from third-party forks after getting approval from someone with "Build & Read" permissions.
2798
+ if is_pull_request () and is_third_party_fork ():
2799
+ pipeline_steps .append (
2800
+ {
2801
+ "block" : ":cop: Authorize third-party presubmit run?" ,
2802
+ "prompt" : (
2803
+ ":rotating_light: :warning: This is an untrusted pull request from a third-party fork. "
2804
+ "Only unblock the build if the code is not malicious."
2805
+ ),
2806
+ "blocked_state" : "running" ,
2807
+ }
2808
+ )
2809
+
2770
2810
task_configs = filter_tasks_that_should_be_skipped (task_configs , pipeline_steps )
2771
2811
2772
2812
# In Bazel Downstream Project pipelines, git_repository and project_name must be specified.
0 commit comments