Skip to content

Commit 5a97591

Browse files
authored
ci: improve readability of chart diff output (#2894)
1 parent 39f20b2 commit 5a97591

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

.github/workflows/svcaplbot-run-dyff.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ jobs:
8181
run: |
8282
bin/compare.sh --diff-output tmp/diff-output.txt
8383
diff_text=$(cat tmp/diff-output.txt)
84-
format_code='```'
84+
format_code_start='```diff'
85+
format_code_end='```'
8586
comment_text="Comparison of Helm chart templating output:
86-
$format_code
87+
$format_code_start
8788
$diff_text
88-
$format_code"
89+
$format_code_end"
8990
gh pr comment ${{ github.event.pull_request.number }} --body "$comment_text"

bin/compare.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
set -ue
33

44
# Usage: bin/compare.sh -l name=loki
5+
# Optional: --diff-output <filename> writes the final diff to a file and skips common chart version information
56
# Deps: dyff, helmfile
67
# brew install homeport/tap/dyff
78
# brew install helmfile
@@ -48,7 +49,7 @@ git -c core.hooksPath=/dev/null checkout $branchB
4849
# order of arguments matters so new changes are green color
4950
echo "Comparing $targetDirB with $targetDirA"
5051
if [ -n "$diffOutput" ]; then
51-
"${script_dir}/dyff.sh" "$targetDirB" "$targetDirA" > "$diffOutput"
52+
"${script_dir}/dyff.sh" "$targetDirB" "$targetDirA" --exclude-chart-versions > "$diffOutput"
5253
cat "$diffOutput"
5354
else
5455
"${script_dir}/dyff.sh" "$targetDirB" "$targetDirA"

bin/dyff.sh

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,36 @@
11
#!/bin/bash
22
set -ue
33

4-
targetDirA=$1
5-
targetDirB=$2
4+
targetDirA=
5+
targetDirB=
6+
miscArgs=( --output github )
7+
8+
while [ $# -ne 0 ]
9+
do
10+
case "$1" in
11+
--exclude-chart-versions)
12+
miscArgs=( "${miscArgs[@]}" --exclude-regexp '.*metadata.labels.helm.sh/chart' --exclude-regexp '.*metadata.labels.app.kubernetes.io/version' )
13+
;;
14+
*)
15+
if [ -z "$targetDirA" ]; then
16+
targetDirA=$1
17+
elif [ -z "$targetDirB" ]; then
18+
targetDirB=$1
19+
else
20+
echo "Extra argument $1"
21+
return 1
22+
fi
23+
;;
24+
esac
25+
shift
26+
done
27+
if [ -z "$targetDirA" ]; then
28+
echo "Missing first argument"
29+
return 1
30+
elif [ -z "$targetDirB" ]; then
31+
echo "Missing second argument"
32+
return 1
33+
fi
634

735
set +e
836
diff_output=$(diff -q -r "$targetDirA" "$targetDirB")
@@ -22,6 +50,6 @@ echo "$diff_output" | while read -r line; do
2250
# Use dyff to compare the files
2351
dyff between "$second_path" "$first_path" --omit-header \
2452
--exclude "data.tls.key" --exclude "/data/ca.crt" --exclude "/data/tls.crt" --exclude "/data/tls.key" \
25-
--exclude-regexp "/checksum" --exclude-regexp "/webhooks.*" --ignore-order-changes
53+
--exclude-regexp "/checksum" --exclude-regexp "/webhooks.*" --ignore-order-changes "${miscArgs[@]}"
2654
fi
2755
done

0 commit comments

Comments
 (0)