-
Notifications
You must be signed in to change notification settings - Fork 1
/
diff-bitte.sh
134 lines (119 loc) · 2.76 KB
/
diff-bitte.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#! /usr/env bash
set -o errtrace
set -o pipefail
set -o nounset
set -o errexit
PACKAGE="diff-bitte"
function show_help() {
echo "$PACKAGE - what happens if this project would use bitte commit XYZ"
echo " "
echo "$PACKAGE -c BITTE_COMMIT [-n NODE [-n NODE ] ... ] [-t TFTARGET [-t TFTARGET ] ... ]"
echo ' '
echo 'options:'
echo '-h, --help show help'
echo '-c, --commit BITTE_COMMIT diffs against BITTE_COMMIT'
echo '-n, --node NODE add nodes to diff'
echo '-t, --terraform TFTARGET add terraform targets to diff'
echo ' '
echo 'BITTE_COMMIT a commit rev from the bitte repository and the future'
echo ' right-hand side of the comparision'
echo ' '
echo "nix-diff binary path: $(which nix-diff)"
echo "nix version: $(nix --version)"
}
test $# -eq 0 && (show_help && exit 1)
BITTE_REPO="input-output-hk/bitte"
NODES=()
TFTARGET=()
while test $# -gt 0; do
case "$1" in
-h | --help)
show_help
exit 0
;;
-c | --commit)
shift
if test $# -gt 0; then
export BITTE_COMMIT=$1
else
echo "no BITTE_COMMIT specified"
exit 1
fi
shift
;;
-n | --node)
shift
if test $# -gt 0; then
NODES+=("$1")
else
echo "no NODE specified"
exit 1
fi
shift
;;
-t | --terraform)
shift
if test $# -gt 0; then
TFTARGET+=("$1")
else
echo "no TFTARGET specified"
exit 1
fi
shift
;;
*)
show_help
exit 1
;;
esac
done
swap_bitte=(--override-input bitte "github:$BITTE_REPO/$BITTE_COMMIT" --update-input bitte)
function cmd {
local cmd
cmd="$*"
echo >&2 ">>> $cmd"
if $cmd 2>/dev/null; then
echo >&2 "$(
tput setaf 2
tput bold
)OK$(tput sgr 0)"
else
echo >&2 "$(
tput setaf 1
tput bold
)COMMAND FAILED$(tput sgr 0)" && exit 1
fi
}
function diff {
local attrpath="$1"
local left
local right
echo
echo "$(tput bold)------------ DIFFING ${attrpath} ...$(tput sgr 0)"
left=$(cmd nix eval --raw "$PRJ_ROOT#$attrpath.drvPath")
right=$(cmd nix eval "${swap_bitte[@]}" --raw "$PRJ_ROOT#$attrpath.drvPath")
echo
echo "$(
tput setaf 1
tput bold
)- left=$left$(tput sgr 0)"
echo "$(
tput setaf 2
tput bold
)+ right=$right$(tput sgr 0)"
echo
echo "$(tput bold)------------ NIX-DIFF ------------$(tput sgr 0)"
cmd nix-diff --character-oriented "$left" "$right"
echo "$(tput bold)------------ DIFF-CLOSURES ------------$(tput sgr 0)"
cmd nix store diff-closures "$left" "$right"
echo
echo
}
for i in "${NODES[@]}"; do
attrpath="nixosConfigurations.$BITTE_CLUSTER-$i.config.system.build.toplevel"
diff "$attrpath"
done
for i in "${TFTARGET[@]}"; do
attrpath="clusters.$BITTE_CLUSTER.tf.$i.config"
diff "$attrpath"
done