Skip to content

Commit 3fc50c5

Browse files
authored
test: manifest compare utilities (#1664)
1 parent e9cf4ab commit 3fc50c5

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ workflow/
1717
.envrc
1818
otomi.cpuprofile
1919
/.idea/
20+
tmp

bin/compare.sh

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
set -ue
3+
4+
# Usage: bin/compare.sh -l name=loki
5+
6+
export ENV_DIR=$PWD/tests/fixtures
7+
8+
readonly templateArgs="$@"
9+
readonly currentBranch=$(git rev-parse --abbrev-ref HEAD)
10+
readonly compareBranch='main'
11+
12+
targetDirA="tmp/${currentBranch}"
13+
targetDirB="tmp/${compareBranch}"
14+
15+
export NODE_ENV=test
16+
helmfile template $templateArgs --output-dir-template="../$targetDirA/{{.Release.Namespace}}-{{.Release.Name }}"
17+
18+
git checkout $compareBranch
19+
helmfile template $templateArgs --output-dir-template="../$targetDirB/{{.Release.Namespace}}-{{.Release.Name}}"
20+
git checkout $currentBranch
21+
22+
set +e
23+
diff_output=$(diff -q -r $targetDirA $targetDirB)
24+
set -e
25+
# Process each line of diff output
26+
27+
echo "$diff_output" | while read -r line; do
28+
# Check if the line indicates a difference
29+
if [[ $line == *" and "* ]]; then
30+
# Extract the paths using cut
31+
first_path=$(echo $line | cut -d' ' -f2)
32+
second_path=$(echo $line | cut -d' ' -f4)
33+
34+
# Use dyff to compare the files
35+
dyff between "$first_path" "$second_path"
36+
fi
37+
done
38+
39+
echo "#########################################################"
40+
echo "#"
41+
echo "# Above YAML documents diff produced by dyff tool."
42+
echo "# You can also select two directories in VSCode $targetDirA and $targetDirB and right click and select the 'Compare selected folders' option"
43+
echo "#"
44+
echo "#########################################################"

0 commit comments

Comments
 (0)