Skip to content

Commit

Permalink
fix: correctly guess tool comparison (#1516)
Browse files Browse the repository at this point in the history
Signed-off-by: Will Murphy <will.murphy@anchore.com>
  • Loading branch information
willmurphyscode authored Sep 25, 2023
1 parent 79c130b commit d94c384
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions test/quality/gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,32 @@ def passed(self):
return len(self.reasons) == 0

def guess_tool_orientation(tools: list[str]):
"""
Given a pair of tools, guess which is latest version, and which is the one
being compared to the latest version.
Returns (latest_tool, current_tool)
"""
if len(tools) != 2:
raise RuntimeError("expected 2 tools, got %s" % tools)
tool_a, tool_b = sorted(tools)
if tool_a == tool_b:
raise ValueError("latest release tool and current tool are the same")
if tool_a.endswith("latest"):
return tool_a, tool_b
elif tool_b.endswith("latest"):
return tool_b, tool_a

if "@path:" in tool_a and "@path:" not in tool_b:
# tool_a is a local build, so compare it against tool_b
return tool_b, tool_a

if "@path:" in tool_b and "@path:" not in tool_a:
# tool_b is a local build, so compare it against tool_a
return tool_a, tool_b

return tool_a, tool_b


current_tool = None
latest_release_tool = None
for tool in tools:
if tool.endswith("latest"):
latest_release_tool = tool
continue
current_tool = tool

if latest_release_tool is None:
for tool in tools:
if "@path:" in tool:
current_tool = tool
continue
latest_release_tool = tool

if latest_release_tool is None:
# "latest" value isn't accessible, so we do a best guess at which version is latest
latest_release_tool, current_tool = sorted(tools)

if current_tool is None:
raise ValueError("current tool not found")
return latest_release_tool, current_tool

class bcolors:
HEADER = '\033[95m'
Expand Down

0 comments on commit d94c384

Please sign in to comment.