Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block presubmit runs for PRs from 3rd-party forks. #1756

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 47 additions & 7 deletions buildkite/bazelci.py
Original file line number Diff line number Diff line change
Expand Up @@ -1525,9 +1525,17 @@ def PrepareRepoInCwd(print_cmd_groups, initial_setup=False):
upload_corrupted_outputs(capture_corrupted_outputs_dir_index, tmpdir)

if platform == "windows":
execute_batch_commands(task_config.get("post_batch_commands", None), True, ":batch: Post Processing (Batch Commands)")
execute_batch_commands(
task_config.get("post_batch_commands", None),
True,
":batch: Post Processing (Batch Commands)",
)
else:
execute_shell_commands(task_config.get("post_shell_commands", None), True, ":bash: Post Processing (Shell Commands)")
execute_shell_commands(
task_config.get("post_shell_commands", None),
True,
":bash: Post Processing (Shell Commands)",
)

finally:
terminate_background_process(sc_process)
Expand Down Expand Up @@ -1634,8 +1642,21 @@ def get_release_name_from_branch_name():


def is_pull_request():
third_party_repo = os.getenv("BUILDKITE_PULL_REQUEST_REPO", "")
return len(third_party_repo) > 0
try:
return int(os.getenv("BUILDKITE_PULL_REQUEST")) > 0
except:
return False


def is_third_party_fork():
if ":" in os.getenv(
"BUILDKITE_BRANCH", ""
): # Only works if "Prefix third-party fork branch names" is enabled
return True

pr_repo = os.getenv("BUILDKITE_PULL_REQUEST_REPO", "")
# We don't accept PRs for GoB repos.
return pr_repo and not pr_repo.startswith("https://github.com/bazelbuild/")


def print_bazel_version_info(bazel_binary, platform):
Expand Down Expand Up @@ -1817,7 +1838,9 @@ def clone_git_repository(git_repository, platform, git_commit=None):
return clone_path


def execute_batch_commands(commands, print_group=True, group_message=":batch: Setup (Batch Commands)"):
def execute_batch_commands(
commands, print_group=True, group_message=":batch: Setup (Batch Commands)"
):
if not commands:
return

Expand All @@ -1828,7 +1851,9 @@ def execute_batch_commands(commands, print_group=True, group_message=":batch: Se
return subprocess.run(batch_commands, shell=True, check=True, env=os.environ).returncode


def execute_shell_commands(commands, print_group=True, group_message=":bash: Setup (Shell Commands)"):
def execute_shell_commands(
commands, print_group=True, group_message=":bash: Setup (Shell Commands)"
):
if not commands:
return

Expand Down Expand Up @@ -2181,7 +2206,9 @@ def calculate_targets(

build_targets = [] if test_only else list(task_config.get("build_targets", []))
test_targets = [] if build_only else list(task_config.get("test_targets", []))
coverage_targets = [] if (build_only or test_only) else list(task_config.get("coverage_targets", []))
coverage_targets = (
[] if (build_only or test_only) else list(task_config.get("coverage_targets", []))
)
index_targets = [] if (build_only or test_only) else list(task_config.get("index_targets", []))

index_targets_query = (
Expand Down Expand Up @@ -2767,6 +2794,19 @@ def print_project_pipeline(
if is_git_on_borg_repo(buildkite_repo):
show_gerrit_review_link(buildkite_repo, pipeline_steps)

# Only run presubmits from third-party forks after getting approval from someone with "Build & Read" permissions.
if is_pull_request() and is_third_party_fork():
pipeline_steps.append(
{
"block": ":cop: Authorize third-party presubmit run?",
"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."
),
"blocked_state": "running",
}
)

task_configs = filter_tasks_that_should_be_skipped(task_configs, pipeline_steps)

# In Bazel Downstream Project pipelines, git_repository and project_name must be specified.
Expand Down