From ebf7635afd9e7d9af5bfea6e71584ec4be51a1e5 Mon Sep 17 00:00:00 2001 From: jeho <17126497+j-zimnowoda@users.noreply.github.com> Date: Fri, 30 Aug 2024 12:29:31 +0200 Subject: [PATCH] test: improve the compare.sh script (#1683) --- bin/compare.sh | 39 ++++++++++++++------------------------- bin/dyff.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 25 deletions(-) create mode 100755 bin/dyff.sh diff --git a/bin/compare.sh b/bin/compare.sh index 711a6ba5ed..8a3be9e661 100755 --- a/bin/compare.sh +++ b/bin/compare.sh @@ -6,39 +6,28 @@ set -ue export ENV_DIR=$PWD/tests/fixtures readonly templateArgs="$@" -readonly currentBranch=$(git rev-parse --abbrev-ref HEAD) -readonly compareBranch='main' +readonly branchA='main' +# branchB current branch +readonly branchB=$(git rev-parse --abbrev-ref HEAD) -targetDirA="tmp/${currentBranch}" -targetDirB="tmp/${compareBranch}" +targetDirA="tmp/${branchA}" +targetDirB="tmp/${branchB}" export NODE_ENV=test -helmfile template $templateArgs --output-dir-template="../$targetDirA/{{.Release.Namespace}}-{{.Release.Name }}" +helmfile template $templateArgs --output-dir-template="../$targetDirB/{{.Release.Namespace}}-{{.Release.Name }}" -git checkout $compareBranch -helmfile template $templateArgs --output-dir-template="../$targetDirB/{{.Release.Namespace}}-{{.Release.Name}}" -git checkout $currentBranch +git checkout $branchA +# we remove previously rendered manifests so they are not mixed up with newly rendered +rm -rf $targetDirA +helmfile template $templateArgs --output-dir-template="../$targetDirA/{{.Release.Namespace}}-{{.Release.Name}}" +git checkout $branchB -set +e -diff_output=$(diff -q -r $targetDirA $targetDirB) -set -e -# Process each line of diff output - -echo "$diff_output" | while read -r line; do - # Check if the line indicates a difference - if [[ $line == *" and "* ]]; then - # Extract the paths using cut - first_path=$(echo $line | cut -d' ' -f2) - second_path=$(echo $line | cut -d' ' -f4) - - # Use dyff to compare the files - dyff between "$first_path" "$second_path" - fi -done +# order of arguments matters so new chanages are green color +bin/dyff.sh $targetDirA $targetDirB echo "#########################################################" echo "#" echo "# Above YAML documents diff produced by dyff tool." -echo "# You can also select two directories in VSCode $targetDirA and $targetDirB and right click and select the 'Compare selected folders' option" +echo "# You can also select two directories in VSCode $targetDirB and $targetDirA and right click and select the 'Compare selected folders' option" echo "#" echo "#########################################################" diff --git a/bin/dyff.sh b/bin/dyff.sh new file mode 100755 index 0000000000..9701a8fc16 --- /dev/null +++ b/bin/dyff.sh @@ -0,0 +1,27 @@ +#!/bin/bash +set -ue + +targetDirA=$1 +targetDirB=$2 + +set +e +diff_output=$(diff -q -r $targetDirA $targetDirB) +set -e +# Process each line of diff output + +echo "$diff_output" | while read -r line; do + # Check if the line indicates a difference + if [[ $line == *" and "* ]]; then + # Extract the paths using cut + first_path=$(echo $line | cut -d' ' -f2) + second_path=$(echo $line | cut -d' ' -f4) + + [ ! -f $second_path ] && echo "New file added: $first_path" && continue + [ ! -f $first_path ] && echo "Old file deleted: $second_path" && continue + + # Use dyff to compare the files + dyff between "$second_path" "$first_path" --omit-header \ + --exclude "data.tls.key" --exclude "/data/ca.crt" --exclude "/data/tls.crt" --exclude "/data/tls.key" \ + --exclude-regexp "/checksum" --exclude-regexp "/webhooks.*" + fi +done