diff --git a/infra/build/functions/ci_trial_build.py b/infra/build/functions/ci_trial_build.py index 0359b2a7d..418528e33 100644 --- a/infra/build/functions/ci_trial_build.py +++ b/infra/build/functions/ci_trial_build.py @@ -27,6 +27,8 @@ import github import trial_build TRIGGER_COMMAND = '/gcbrun' +TRIAL_BUILD_COMMAND_STR = f'{TRIGGER_COMMAND} trial_build.py ' +SKIP_COMMAND_STR = f'{TRIGGER_COMMAND} skip' def get_comments(pull_request_number): @@ -48,12 +50,13 @@ def get_latest_gcbrun_command(comments): for comment in reversed(comments): # This seems to get comments on code too. body = comment.body - command_str = f'{TRIGGER_COMMAND} trial_build.py ' - if not body.startswith(command_str): - continue - if len(body) == len(command_str): + if body.startswith(SKIP_COMMAND_STR): return None - return body[len(command_str):].strip().split(' ') + if not body.startswith(TRIAL_BUILD_COMMAND_STR): + continue + if len(body) == len(TRIAL_BUILD_COMMAND_STR): + return None + return body[len(TRIAL_BUILD_COMMAND_STR):].strip().split(' ') return None @@ -62,11 +65,11 @@ def exec_command_from_github(pull_request_number, repo, branch): on |pull_request_number|.""" comments = get_comments(pull_request_number) command = get_latest_gcbrun_command(comments) - command.extend(['--repo', repo]) - logging.info('Command: %s.', command) if command is None: logging.info('Trial build not requested.') return None + command.extend(['--repo', repo]) + logging.info('Command: %s.', command) # Set the branch so that the trial_build builds the projects from the PR # branch. @@ -81,7 +84,8 @@ def main(): pull_request_number = int(os.environ['PULL_REQUEST_NUMBER']) branch = os.environ['BRANCH'] repo = os.environ['REPO'] - if exec_command_from_github(pull_request_number, repo, branch): + result = exec_command_from_github(pull_request_number, repo, branch) + if result or result is None: return 0 return 1