Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: enhance readability of compare_default_params.sh script output #218

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ bridge-deposits.json
claimable-txs.json
proof.json

# default parameters
input-parser-args.yml
kurtosis-args.yml
params-args.yml
# compare default parameters
.input_parser.star
.kurtosis.yml
.params.yml

# docs
.vscode
Expand Down
71 changes: 61 additions & 10 deletions scripts/compare_default_params.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,67 @@
#!/bin/bash

# This script compares default parameters specified in main.star, kurtosis.yml, and params.yml.
# The true reference for default parameters is params.yml.
# This script compares default parameters specified in three files: `input_parser.star`,
# `kurtosis.yml` and `params.yml` where `params.yml` is the source of truth for default parameters.
# The script outputs the differences between the specified parameters in each file compared to `params.yml`.

echo "Dumping default parameters..."
sed -n '/DEFAULT_ARGS = {/,/}/ { s/DEFAULT_ARGS = //; s/}/}/; p; }' input_parser.star | yq --yaml-output > input-parser-args.yml
# Extracting default parameters from the different files.
echo "Extracting default parameters from input_parser.star..."
if ! sed -n '/DEFAULT_ARGS = {/,/}/ { s/DEFAULT_ARGS = //; s/}/}/; p; }' input_parser.star | yq --yaml-output >.input_parser.star; then
echo "Error: Failed to extract parameters from input_parser.star."
exit 1
fi

echo "Extracting default parameters from kurtosis.yml..."
# shellcheck disable=SC2016
sed -n '/```yml/,/```/ { /```yml/d; /```/d; p;}' kurtosis.yml | yq --yaml-output > kurtosis-args.yml
yq --yaml-output .args params.yml > params-args.yml
if ! sed -n '/```yml/,/```/ { /```yml/d; /```/d; p;}' kurtosis.yml | yq --yaml-output >.kurtosis.yml; then
echo "Error: Failed to extract parameters from kurtosis.yml."
exit 1
fi

echo "Extracting default parameters from params.yml..."
if ! yq --yaml-output .args params.yml >.params.yml; then
echo "Error: Failed to extract parameters from params.yml."
exit 1
fi

# Function to compare files and output differences in a structured format
compare_with_source_of_truth() {
local file1=.params.yml
local file2=$1

echo
echo "🔍 Comparing $file1 and $file2..."
differences=$(diff "$file1" "$file2" | grep -E '^[<>]')
if [ -z "$differences" ]; then
echo "No differences found."
else
diff_count=$(echo "$differences" | grep -c '^<')
echo
echo "$diff_count differences found:"
echo

# Print differences for file1
echo "📄 $file1 (source of truth)"
echo "--------------------------------------------------------------------------------"
while IFS= read -r line; do
if [[ $line == "<"* ]]; then
echo "${line:2}"
fi
done <<<"$differences"

echo; echo "Diff input-parser-args.yml <> params-args.yml"
diff input-parser-args.yml params-args.yml
echo
# Print differences for file
echo "📄 $file2 (🚨 to be updated 🚨)"
echo "--------------------------------------------------------------------------------"
while IFS= read -r line; do
if [[ $line == ">"* ]]; then
echo "${line:2}"
fi
done <<<"$differences"
fi
}

echo; echo "Diff kurtosis-args.yml <> params-args.yml"
diff kurtosis-args.yml params-args.yml
echo
compare_with_source_of_truth .input_parser.star
echo
compare_with_source_of_truth .kurtosis.yml