Skip to content

Commit

Permalink
Fix python code (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjreed121 authored Nov 14, 2023
1 parent 1e89c3d commit 27171a5
Showing 1 changed file with 41 additions and 4 deletions.
45 changes: 41 additions & 4 deletions bin/generate_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,33 @@
hash_after = sys.argv[4]

# Get list of all changed files between 2 commits
output = subprocess.check_output(["git", "--no-pager", "diff", "--name-only", hash_before, hash_after])
output = subprocess.check_output(["git", "--no-pager", "diff", "--name-only", "--diff-filter=d", hash_before, hash_after])
paths_updated = output.decode("utf-8").splitlines()

image_set = set()
image_tag_set = set()

for path in paths_updated:
parts = Path(path).parts
# Only rebuild if modified files were in dockerfiles
if parts[0] != "dockerfiles":
continue

if len(parts) < 3:
continue

if not os.path.isdir(Path(parts[0], parts[1], parts[2])):
continue

if f"{parts[1]}:{parts[2]}" in image_tag_set:
continue

metadata = json.loads(open(Path(parts[0]) / parts[1] / "metadata.json").read())

push_latest = False

if metadata["pushLatest"]:
if metadata["latestImage"] == parts[2]:
if metadata["latestTag"] == parts[2]:
push_latest = True

tags = f"{username}/{parts[1]}:{parts[2]}"
Expand All @@ -51,6 +63,32 @@
"context": str(os.path.dirname(path))
}
)
image_set.add(parts[1])
image_tag_set.add(f"{parts[1]}:{parts[2]}")

# search for any metadata.json edits
for path in paths_updated:
parts = Path(path).parts
if parts[0] != "dockerfiles":
continue
if len(parts) < 3:
continue
if parts[2] != "metadata.json":
continue
metadata = json.loads(open(Path(parts[0]) / parts[1] / "metadata.json").read())
if not metadata["pushLatest"]:
continue # there is no latest so nothing to rebuild
tag = metadata["latestTag"]
if parts[1] in image_set:
continue # already being rebuilt
tags = f"{username}/{parts[1]}:{tag},{username}/{parts[1]}:latest"
to_build.append(
{
"tags": tags,
"context": str(Path(parts[0]) / parts[1] / tag)
}
)

elif build_all == "true":
images = os.listdir("dockerfiles")
for image in images:
Expand All @@ -68,7 +106,7 @@

push_latest = False
if metadata["pushLatest"]:
if metadata["latestImage"] == tag:
if metadata["latestTag"] == tag:
push_latest = True

tags = f"{username}/{image}:{tag}"
Expand All @@ -81,7 +119,6 @@
}
)


finobj = {"include": to_build}

print(json.dumps(finobj))

0 comments on commit 27171a5

Please sign in to comment.