-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelm-diff.sh
executable file
·106 lines (88 loc) · 2.61 KB
/
helm-diff.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env bash
set -e
## Compare the helm output difference between the current branch and the production branch
## All the files must be commited to have an effect
##
## Usage:
## From the base directory of the helm chart, launch:
## ./test.sh
CONTEXT_SIZE=10
MAIN_BRANCH=production
APP=${1-swh}
BRANCH="$(git symbolic-ref --quiet HEAD | sed 's|refs/heads/||')"
DIFF_COMMAND_TO_USE=${2-auto}
LEGACY_DIFF_COMMAND="diff -U${CONTEXT_SIZE}"
DIFF_COMMAND=""
case $DIFF_COMMAND_TO_USE in
dyff)
if command -v dyff >/dev/null; then
if [ -n "$DYFF_OPTS" ]; then
DYFF_OPTS="-s -c on"
fi
DIFF_COMMAND="dyff between ${DYFF_OPTS}"
USE_DYFF=true
fi
;;
diff)
DIFF_COMMAND="${LEGACY_DIFF_COMMAND}"
USE_DYFF=false
;;
autodetect|auto|*)
# do nothing, legacy behavior to auto-detect diff command
;;
esac
if [ -z "$DIFF_COMMAND" ]; then
if command -v dyff >/dev/null; then
if [ -n "$DYFF_OPTS" ]; then
DYFF_OPTS="-s -c on"
fi
DIFF_COMMAND="dyff between ${DYFF_OPTS}"
USE_DYFF=true
else
DIFF_COMMAND="${LEGACY_DIFF_COMMAND}"
USE_DYFF=false
fi
fi
TMPDIR=$(mktemp -d /tmp/swh-chart.$APP.XXXXXXXX)
function cleanup {
rm -rf $TMPDIR
}
trap cleanup EXIT
echo "[$APP] Comparing changes between branches $MAIN_BRANCH and $BRANCH..."
files=$(ls $APP/values/*.yaml)
EXTRA_CMD=""
[ -f $APP/values/default.yaml ] && EXTRA_CMD="--values $APP/values/default.yaml"
HELM_CMD="helm template test $APP --values values-swh-application-versions.yaml --values $APP/values.yaml $EXTRA_CMD --values"
# git stash
git checkout $MAIN_BRANCH
for f in $files; do
echo "[$APP] Generate config in $MAIN_BRANCH branch for $f..."
output="$TMPDIR/$(basename $f).before"
$HELM_CMD $f > $output
done
# git stash pop
git checkout $BRANCH
for f in $files; do
echo "[$APP] Generate config in ${BRANCH} branch for $f..."
output="$TMPDIR/$(basename $f).after"
$HELM_CMD $f > $output
done
for f in $files; do
output="$TMPDIR/$(basename $f)"
echo
echo
echo "------------- diff for $f -------------"
echo
diff_retval=0
$DIFF_COMMAND "$output.before" "$output.after" || diff_retval=$?
if [ "$USE_DYFF" = "true" ]; then
if [ "$diff_retval" -eq 255 ]; then
echo "dyff failed, falling back to the legacy diff command"
$LEGACY_DIFF_COMMAND "$output.before" "$output.after" || echo "No differences"
fi
else
if [ "$diff_retval" -eq 0 ]; then
echo "No differences"
fi
fi
done