Skip to content

Commit 6e803d7

Browse files
committed
Ensure there is at least some difference before printing the tables
1 parent a393a2d commit 6e803d7

File tree

1 file changed

+30
-20
lines changed
  • .github/workflows/cost-differences

1 file changed

+30
-20
lines changed

.github/workflows/cost-differences/diff.py

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def parties(df):
2424
def utxo(df):
2525
return df.set_index("UTxO")
2626

27-
def compare_to_md(f, old, new):
27+
def compare(f, old, new):
2828
# New should be better, so we compare to that.
2929
df = f(new) - f(old)
3030

@@ -34,6 +34,9 @@ def compare_to_md(f, old, new):
3434
# Round everything to 2 decimals
3535
df = df.round(2)
3636

37+
return df
38+
39+
def to_markdown(df):
3740
# Add colour
3841
def update_colour(x):
3942
if x == 0:
@@ -51,30 +54,37 @@ def update_colour(x):
5154

5255
return df.to_markdown()
5356

54-
print("Transaction cost differences")
5557

56-
# First is the script size
58+
# We ignore the first table, namely the metadata, that's why the base/branch
59+
# index starts at 1.
60+
61+
diffs = [
62+
# First is the script size
63+
(headers[0], compare( script_size, base[1], branch[1]))
64+
# Then Init,
65+
, (headers[1], compare( parties, base[2], branch[2]))
66+
# Then Commit is different; it doesn't have a "Parties" column
67+
, (headers[2], compare( utxo, base[3], branch[3]))
68+
]
5769

58-
print(f"## {headers[0]}")
59-
print("")
60-
print( compare_to_md( script_size, base[1], branch[1]) )
70+
# Then the remaining are all the same.
71+
for i in range(4, 9 + 1):
72+
diffs.append(( headers[i - 1]
73+
, compare( parties, base[i], branch[i] )
74+
))
6175

62-
# Then Init,
63-
print("")
64-
print(f"## {headers[1]}")
65-
print("")
66-
print( compare_to_md(parties, base[2], branch[2]) )
76+
# Check that ther was _some_ difference, at least.
77+
some_change = any( df.to_numpy().sum() != 0 for _, df in diffs )
6778

68-
# Then Commit is different; it doesn't have a "Parties" column
79+
print("# Transaction cost differences")
6980

70-
print("")
71-
print(f"## {headers[2]}")
72-
print("")
73-
print( compare_to_md(utxo, base[3], branch[3]) )
81+
if not (some_change):
82+
print("No cost or size differences found")
83+
exit(0)
7484

75-
# The remaining are all the same as Init.
76-
for i in range(4, 9 + 1):
85+
for (header, df) in diffs:
7786
print("")
78-
print(f"## {headers[i - 1]}")
87+
print(f"## {header}")
7988
print("")
80-
print( compare_to_md(parties, base[i], branch[i]) )
89+
diff = to_markdown(df)
90+
print(diff)

0 commit comments

Comments
 (0)