Skip to content

Commit

Permalink
test: improve the compare.sh script (#1683)
Browse files Browse the repository at this point in the history
  • Loading branch information
j-zimnowoda committed Aug 30, 2024
1 parent 329bace commit ebf7635
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 25 deletions.
39 changes: 14 additions & 25 deletions bin/compare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "#########################################################"
27 changes: 27 additions & 0 deletions bin/dyff.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ebf7635

Please sign in to comment.