Commit c97501e2 by Michael Roytman

This fixes the bug in the _get_role_name method; Travis's environment is at…

This fixes the bug in the _get_role_name method; Travis's environment is at "/home/travis/build/edx/configuration/...", so identifying the Docker image/play name by grabbing the next token after the first instance of the word "build" is incorrect, as it resolves to "edx", instead of the name of the Docker image. Instead, we look for the first token after "docker/build". This also address the duplicate output bug, where, if docker_plays and modified_docker_files have images in common, they would be printed twice.
parent b0662956
...@@ -343,24 +343,34 @@ def _get_modified_dockerfiles(files, git_dir): ...@@ -343,24 +343,34 @@ def _get_modified_dockerfiles(files, git_dir):
for f in files: for f in files:
file_path = pathlib2.Path(git_dir, f) file_path = pathlib2.Path(git_dir, f)
if file_path in candidate_files: if file_path in candidate_files:
items.add(_get_play_name(file_path)) play = items.add(_get_play_name(file_path))
if play is not None:
items.add(play)
return items return items
def _get_play_name(path): def _get_play_name(path):
""" """
Gets name of play from the filepath, which is Gets name of play from the filepath, which is the token
the directory following occurence of the word "build". after either "docker/build" in the file path.
Input: Input:
path: A path to the changed file under docker/build dir path: A path to the changed file under docker/build dir
""" """
# get individual parts of a file path
dirs = path.parts
# name of play
return dirs[dirs.index("build")+1]
# attempt to extract Docker image name from file path; splits the path of a file over
# "docker/build/", because the first token after "docker/build/" is the image name
suffix = (str(path)).split(str(os.path.join('docker', 'build', '')))
# if file path contains "docker/build/"
if len(suffix) > 1:
# split suffix over separators to file path components separately
suffix_parts = suffix[1].split(os.sep)
# first token will be image name; <repo>/docker/build/<image>/...
return suffix_parts[0]
return None
def arg_parse(): def arg_parse():
...@@ -422,8 +432,5 @@ if __name__ == '__main__': ...@@ -422,8 +432,5 @@ if __name__ == '__main__':
# Add playbooks to the list whose docker file has been modified # Add playbooks to the list whose docker file has been modified
modified_docker_files = _get_modified_dockerfiles(change_set, TRAVIS_BUILD_DIR) modified_docker_files = _get_modified_dockerfiles(change_set, TRAVIS_BUILD_DIR)
all_plays = set(set(docker_plays) | set( modified_docker_files))
# prints Docker plays print " ".join(all_plays)
print " ".join(str(play) for play in docker_plays),
print " ".join(str(dock) for dock in modified_docker_files)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment