From 6e803d72784abb20d559dcb729e7217b48c0fe4f Mon Sep 17 00:00:00 2001 From: Noon van der Silk Date: Tue, 15 Oct 2024 15:13:40 +0100 Subject: [PATCH] Ensure there is at least some difference before printing the tables --- .github/workflows/cost-differences/diff.py | 50 +++++++++++++--------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/.github/workflows/cost-differences/diff.py b/.github/workflows/cost-differences/diff.py index c4f18c17233..5780b1f7732 100755 --- a/.github/workflows/cost-differences/diff.py +++ b/.github/workflows/cost-differences/diff.py @@ -24,7 +24,7 @@ def parties(df): def utxo(df): return df.set_index("UTxO") -def compare_to_md(f, old, new): +def compare(f, old, new): # New should be better, so we compare to that. df = f(new) - f(old) @@ -34,6 +34,9 @@ def compare_to_md(f, old, new): # Round everything to 2 decimals df = df.round(2) + return df + +def to_markdown(df): # Add colour def update_colour(x): if x == 0: @@ -51,30 +54,37 @@ def update_colour(x): return df.to_markdown() -print("Transaction cost differences") -# First is the script size +# We ignore the first table, namely the metadata, that's why the base/branch +# index starts at 1. + +diffs = [ + # First is the script size + (headers[0], compare( script_size, base[1], branch[1])) + # Then Init, + , (headers[1], compare( parties, base[2], branch[2])) + # Then Commit is different; it doesn't have a "Parties" column + , (headers[2], compare( utxo, base[3], branch[3])) + ] -print(f"## {headers[0]}") -print("") -print( compare_to_md( script_size, base[1], branch[1]) ) +# Then the remaining are all the same. +for i in range(4, 9 + 1): + diffs.append(( headers[i - 1] + , compare( parties, base[i], branch[i] ) + )) -# Then Init, -print("") -print(f"## {headers[1]}") -print("") -print( compare_to_md(parties, base[2], branch[2]) ) +# Check that ther was _some_ difference, at least. +some_change = any( df.to_numpy().sum() != 0 for _, df in diffs ) -# Then Commit is different; it doesn't have a "Parties" column +print("# Transaction cost differences") -print("") -print(f"## {headers[2]}") -print("") -print( compare_to_md(utxo, base[3], branch[3]) ) +if not (some_change): + print("No cost or size differences found") + exit(0) -# The remaining are all the same as Init. -for i in range(4, 9 + 1): +for (header, df) in diffs: print("") - print(f"## {headers[i - 1]}") + print(f"## {header}") print("") - print( compare_to_md(parties, base[i], branch[i]) ) + diff = to_markdown(df) + print(diff)