nix-flake-outputs-size/compare.jq
Jalil David Salamé Messina 46291fc850
feat!(report): generate JSON instead of markdown
This allows us to analyze the report more easily. There is experimental
support for comparing against a base report, but we don't expose that
functionality to the action.
2024-12-17 23:17:48 +01:00

20 lines
889 B
Text

# Calculate the change in percentage of a nummeric key
#
# Where .[0] is the new value, and .[1] is the old value
def calc_change($key):
. as $input | $input[1][$key] - $input[0][$key];
# Calculate the change in percentage for multiple keys
#
# Returns an array of {"key": $key, "value": change%}
def keys_change_perc($keys):
. as $input | $keys | map(. as $key | $input | {"key": $key, "value": . | calc_change($key)});
# For a set of keys, calculate the change percentage and return it as
# "\($key)Change" = $value in the original object.
def set_change_perc($keys):
. as $input | reduce keys_change_perc($keys)[] as $change ($input[0]; .["\($change.key)Change"] = $change.value);
# Bring everything together
reduce .[] as $x ({}; . as $acc | reduce ($x | keys[]) as $key ($acc; .[$key] |= . + $x[$key])) |
map_values(group_by(.name) | map(set_change_perc(["size", "narSize"])))