diff --git a/images/tf_operator/build_and_push.py b/images/tf_operator/build_and_push.py index ba84960e2b..c76042947d 100755 --- a/images/tf_operator/build_and_push.py +++ b/images/tf_operator/build_and_push.py @@ -14,7 +14,7 @@ def GetGitHash(): # The image tag is based on the githash. git_hash = subprocess.check_output(["git", "rev-parse", "--short", "HEAD"]) - git_hash=git_hash.strip() + git_hash = git_hash.strip() modified_files = subprocess.check_output(["git", "ls-files", "--modified"]) untracked_files = subprocess.check_output( ["git", "ls-files", "--others", "--exclude-standard"]) diff --git a/test-infra/image/bootstrap.py b/test-infra/image/bootstrap.py index 144b0c15d7..5dbd07f80d 100644 --- a/test-infra/image/bootstrap.py +++ b/test-infra/image/bootstrap.py @@ -35,7 +35,7 @@ def run(command, cwd=None): """Run the command as a subprocess""" logging.info("Running: %s", " ".join(command)) - subprocess.check_call(command, cwd=cwd) + return subprocess.check_output(command, cwd=cwd).decode("utf-8") def clone_repo(): @@ -70,15 +70,27 @@ def clone_repo(): # If this is a presubmit PULL_PULL_SHA will be set see: # https://github.com/kubernetes/test-infra/tree/master/prow#job-evironment-variables - sha = os.getenv('PULL_PULL_SHA') - - if not sha: - # For postsubmits PULL_BASE_SHA will be set. - sha = os.getenv('PULL_BASE_SHA') + sha = "" + pull_number = os.getenv("PULL_NUMBER", "") + + if pull_number: + sha = os.getenv("PULL_PULL_SHA", "") + # Its a presubmit job sob since we are testing a Pull request. + run(["git", "fetch", "origin", + "pull/{0}/head:pr".format(pull_number)], + cwd=dest) + else: + # For postsubmits PULL_BASE_SHA will be set + sha = os.getenv("PULL_BASE_SHA", "") if sha: run(["git", "checkout", sha], cwd=dest) + # Get the actual git hash. + # This ensures even for periodic jobs which don't set the sha we know + # the version of the code tested. + sha = run(["git", "rev-parse", "HEAD"], cwd=dest) + # Install dependencies run(["glide", "install"], cwd=dest) @@ -101,6 +113,15 @@ def main(): else: logging.warn("Could not find file: %s", version_file) + # Print environment variables. + # This is useful for debugging and understanding the information set by prow. + names = os.environ.keys() + names.sort() + logging.info("Environment Variables") + for n in names: + logging.info("%s=%s", n, os.environ[n]) + logging.info("End Environment Variables") + src_dir, sha = clone_repo() # Execute the runner. diff --git a/test-infra/runner.py b/test-infra/runner.py index c4fb41b5b7..29f981e1f6 100644 --- a/test-infra/runner.py +++ b/test-infra/runner.py @@ -348,7 +348,7 @@ def upload_outputs(gcs_client, output_dir, test_dir): if __name__ == "__main__": logging.getLogger().setLevel(logging.INFO) - + logging.info("Starting runner.py") parser = argparse.ArgumentParser( description="Run E2E tests for the TfJob CRD.") @@ -406,15 +406,6 @@ def upload_outputs(gcs_client, output_dir, test_dir): src_dir = args.src_dir sha = args.sha - # Print environment variables. - # This is useful for debugging and understanding the information set by prow. - names = os.environ.keys() - names.sort() - logging.info("Environment Variables") - for n in names: - logging.info("%s=%s", n, os.environ[n]) - logging.info("End Environment Variables") - test_dir = tempfile.mkdtemp(prefix="tmpTfCrdTest") logging.info("test_dir: %s", test_dir)