-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprepare_release.sh
executable file
·147 lines (123 loc) · 2.84 KB
/
prepare_release.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
135
136
137
138
139
140
141
142
143
144
145
146
147
#! /bin/bash
fix_key="fix"
if [[ "$1" = "help" || "$1" = "--help" || "$1" = "-h" ]]
then
echo "'$0 $fix_key' to fix (in place replace). Otherwise lint (return non-zero if fails)."
exit 0
fi
if [[ "$1" = "$fix_key" ]]
then
fix_flag="1"
fi
version=$(cat VERSION)
error=""
# check image.spec is correct
check_spec() {
filepath=$1
filename=$2
if [[ "$filepath" = *"/prod/"* ]]
then
deploy_target="prod"
fi
if [[ "$filepath" = *"/rc/"* ]]
then
deploy_target="rc"
fi
if [[ "$deploy_target" != "prod" ]]
then
return 0
fi
if [[ "$filename" = "worker-"* ]]
then
expected_spec=$version-worker
fi
if [[ "$filename" = "server" ]]
then
expected_spec=$version-server
fi
if [[ "$filename" = "worker-v4" ]]
then
expected_spec=$version-worker-v4
fi
if [[ -z "$expected_spec" ]]
then
echo expected spec cannot be found: $filepath $filename
exit 1
fi
if [[ "$fix_flag" = "1" ]]
then
expected_spec=$expected_spec yq -i '.image.spec=strenv(expected_spec)' $filepath
return 0
fi
curr_spec=$(yq '.image.spec' $filepath)
if [[ "$expected_spec" != "$curr_spec" ]]
then
error="$f : .image.spec : $curr_spec\n$error"
fi
return 0
}
# check sapi.queue is correct
check_queue() {
filepath=$1
filename=$2
if [[ "$filename" != "worker-"* ]]
then
# not worker, do not fix
return 0
fi
if [[ "$filename" = *"v4" ]]
then
# _is_ worker-v4, do not fix
return 0
fi
queue=${filename#worker-}
expected_q=$version.$dir.$queue
if [[ "$fix_flag" = "1" ]]
then
expected_q=$expected_q yq -i '.sapi.queue=strenv(expected_q)' $filepath
return 0
fi
curr_q=$(yq '.sapi.queue' $filepath)
if [[ "$expected_q" != "$curr_q" ]]
then
error="$f : .sapi.queue : $curr_q\n$error"
fi
return 0
}
# iterate and check
for dir in rc prod
do
for f in $( find .helm/deployments/$dir -name "*.yaml" )
do
filename=$f
filename=${filename%.yaml}
filename=${filename#.helm/deployments/$dir/}
check_queue $f $filename
check_spec $f $filename
if [[ "$fix_flag" = "1" ]]
then
version=$version yq -i '.sapi.version=strenv(version)' $f
continue
fi
curr_version=$(yq '.sapi.version' $f)
if [[ "$curr_version" != "$version" ]]
then
error="$f sapi.veresion $curr_version\n$error"
continue
fi
done
done
if [[ "$fix_flag" = "1" ]]
then
echo "fixed all if needed"
exit 0
fi
if [[ -z "$error" ]]
then
echo "validation success!"
exit 0
fi
echo "validation failed!"
echo "expected version: $version"
echo -e "$error"
exit 1