aboutsummaryrefslogtreecommitdiffhomepage
path: root/infra/ci
diff options
context:
space:
mode:
authorGravatar Abhishek Arya <inferno@chromium.org>2021-01-27 16:06:04 -0800
committerGravatar GitHub <noreply@github.com>2021-01-28 11:06:04 +1100
commitaeb1be4b6ef51bdc9dc0b42c67b4aba055ea89b6 (patch)
tree10fe8bd68044255c17093dcb3d31f90fe479bdf8 /infra/ci
parent23e24a4bac8c5014450038d583f535947f93f052 (diff)
Fix get_changed_files in infra/ci. (#5055)
Diffstat (limited to 'infra/ci')
-rwxr-xr-xinfra/ci/build.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/infra/ci/build.py b/infra/ci/build.py
index 30ff4ea4..9a1ed623 100755
--- a/infra/ci/build.py
+++ b/infra/ci/build.py
@@ -35,16 +35,21 @@ DEFAULT_SANITIZERS = ['address', 'undefined']
LANGUAGES_WITH_COVERAGE_SUPPORT = ['c', 'c++', 'go']
-def get_changed_files():
+def get_changed_files_output():
"""Returns the output of a git command that discovers changed files."""
- return subprocess.check_output(['git', 'diff', '--name-only',
- 'FETCH_HEAD']).decode()
+ main_branch = subprocess.check_output(
+ ['git', 'rev-parse', '--abbrev-ref', 'origin/HEAD']).strip().decode()
+ branch_commit_hash = subprocess.check_output(
+ ['git', 'merge-base', 'FETCH_HEAD', main_branch]).strip().decode()
+
+ return subprocess.check_output(
+ ['git', 'diff', '--name-only', branch_commit_hash + '..']).decode()
def get_modified_buildable_projects():
"""Returns a list of all the projects modified in this commit that have a
build.sh file."""
- git_output = get_changed_files()
+ git_output = get_changed_files_output()
projects_regex = '.*projects/(?P<name>.*)/.*\n'
modified_projects = set(re.findall(projects_regex, git_output))
projects_dir = os.path.join(get_oss_fuzz_root(), 'projects')
@@ -196,7 +201,7 @@ def build_modified_projects():
def is_infra_changed():
"""Returns True if the infra directory was changed."""
- git_output = get_changed_files()
+ git_output = get_changed_files_output()
infra_code_regex = '.*infra/.*\n'
return re.search(infra_code_regex, git_output) is not None