-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset-z.sh
More file actions
executable file
·200 lines (176 loc) · 5.86 KB
/
Copy pathset-z.sh
File metadata and controls
executable file
·200 lines (176 loc) · 5.86 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/bash
############################################################
# Help #
############################################################
show_help()
{
echo "Set the z-stream version after a release. Switch tekton from ystream to zstream if necessary."
echo
echo "Syntax: set-z.sh [-h|-y] VERSION"
echo "Options:"
echo " -h Print this help."
echo " -y Yes-mode (non-interactive: proceed without asking)."
echo
echo "Arguments:"
echo " VERSION Version to set for the next z-stream."
echo
echo "Example:"
echo " ./set-z.sh 2.0.1"
echo
}
# Reset in case getopts has been used previously in the shell.
OPTIND=1
yes_mode=0
repos=(operator ebpf-agent flowlogs-pipeline console-plugin cli)
tekton_all_cpnt=("network-observability-operator" "netobserv-ebpf-agent" "flowlogs-pipeline" "network-observability-console-plugin" "network-observability-cli")
cp_variants=(pf4 pf5)
while getopts "h?y" opt; do
case "$opt" in
h|\?)
show_help
exit 0
;;
y)
yes_mode=1
;;
esac
done
shift $((OPTIND-1))
[ "${1:-}" = "--" ] && shift
if [[ "$#" == "0" ]]; then
echo "Missing arguments"
show_help
exit 1
fi
if [ "$#" != "1" ]; then
echo "Too many arguments: $@"
show_help
exit 1
fi
version="$1"
x=`echo ${version} | cut -d . -f1`
y=`echo ${version} | cut -d . -f2`
z=`echo ${version} | cut -d . -f3`
target="release-${x}.${y}"
# Sanity checks
for repo in "${repos[@]}"; do
echo -e "\n\033[1mSanity check on $repo\033[0m"
pushd $repo
git fetch downstream
git ls-remote --exit-code --heads downstream refs/heads/$target
if [[ "$?" != "0" ]]; then
echo "Branch downstream/$target not found. Stopping here."
exit 1
fi
git diff HEAD --exit-code
if [[ "$?" != "0" ]]; then
echo "There are uncommited changes in $repo, commit or reset manually before running this script. Stopping here."
exit 1
fi
if [[ "$repo" == "console-plugin" ]]; then
for variant in "${cp_variants[@]}"; do
echo -e "\n\033[1mVariant: $variant\033[0m"
git ls-remote --exit-code --heads downstream refs/heads/$target-$variant
if [[ "$?" != "0" ]]; then
echo "Branch downstream/$target-$variant not found. Stopping here."
exit 1
fi
done
fi
popd
done
echo ""
echo "Bump branches \"downstream/$target\" to $x.$y.$z"
if [[ $yes_mode != 1 ]]; then
read -p "Continue? [yN] " yn
echo
if [[ ! $yn =~ ^[Yy]$ ]] ; then
exit 1
fi
fi
warnings=()
print_warnings() {
for warning in "${warnings[@]}"; do
echo "WARNING: $warning"
done
}
check_tekton_file_names() {
local tekton_y=$1
local tekton_z=$2
if [[ -f ${tekton_y} ]]; then
if [[ -f ${tekton_z} ]]; then
echo " WARNING: both ystream and zstream tekton files found; deleting ystream."
rm ${tekton_y}
else
echo " Moving tekton ystream to zstream."
mv ${tekton_y} ${tekton_z}
fi
fi
}
bump_and_push() {
local repo=$1
local target_branch=$2
local tekton_component=$3
local tmp_branch="tmp-$target_branch"
git checkout -B $tmp_branch downstream/$target_branch
if [[ "$?" != "0" ]]; then
echo "Could not check out, please make sure all repos are in a clean state without uncommited changes. Stopping here."
exit 1
fi
git reset --hard downstream/$target_branch
local dockerfile_args_path="./Dockerfile-args.downstream"
if [[ "$repo" == "flowlogs-pipeline" ]]; then
dockerfile_args_path="./contrib/docker/Dockerfile-args.downstream"
fi
old=`cat ${dockerfile_args_path} | grep "BUILDVERSION=" | sed -r 's/BUILDVERSION=(.+)/\1/'`
oldx=`echo ${old} | cut -d . -f1`
oldy=`echo ${old} | cut -d . -f2`
oldz=`echo ${old} | cut -d . -f3`
nextz="$((oldz+1))"
if [[ "$oldx" == "$x" && "$oldy" == "$y" && "$oldz" == "$z" ]]; then
echo "${repo}: same version detected; assuming you're just re-running the script? That's ok."
elif [[ "$oldx" != "$x" || "$oldy" != "$y" || "$nextz" != "$z" ]]; then
warnings+=("Skipping ${repo}: it doesn't look like a z-stream bump (old version: ${old}, new version: ${version}). Please check manually.")
return
fi
echo " Updating ${dockerfile_args_path}..."
sed -i -r "s/^BUILDVERSION=.+/BUILDVERSION=${x}.${y}.${z}/" ${dockerfile_args_path}
echo " Checking ./tekton files..."
find .tekton -type f -exec sed -i -e "s/ystream/zstream/g" {} \;
check_tekton_file_names "./.tekton/${tekton_component}-ystream-pull-request.yaml" "./.tekton/${tekton_component}-zstream-pull-request.yaml"
check_tekton_file_names "./.tekton/${tekton_component}-ystream-push.yaml" "./.tekton/${tekton_component}-zstream-push.yaml"
if [[ "$repo" == "operator" ]]; then
# Operator also has the bundle component
check_tekton_file_names "./.tekton/${tekton_component}-bundle-ystream-pull-request.yaml" "./.tekton/${tekton_component}-bundle-zstream-pull-request.yaml"
check_tekton_file_names "./.tekton/${tekton_component}-bundle-ystream-push.yaml" "./.tekton/${tekton_component}-bundle-zstream-push.yaml"
fi
echo " Displaying diff..."
git add -A
git diff HEAD
if [[ $yes_mode != 1 ]]; then
read -p "Looks good to you, and proceed to commit and push ${target_branch}? (you can bring manual changes before answering) [yN] " yn
echo
if [[ ! $yn =~ ^[Yy]$ ]] ; then
return
fi
fi
echo " Commit and push to ${target_branch}..."
git commit --allow-empty -m "Prepare ${x}.${y}.${z}"
git push downstream HEAD:${target_branch}
}
i_cpnt=0
for repo in "${repos[@]}"; do
echo -e "\n\033[1mProcessing $repo\033[0m"
pushd $repo
tekton_cpnt=${tekton_all_cpnt[$i_cpnt]}
bump_and_push $repo $target $tekton_cpnt
if [[ "$repo" == "console-plugin" ]]; then
for variant in "${cp_variants[@]}"; do
echo -e "\n\033[1mVariant: $variant\033[0m"
bump_and_push $repo $target-$variant $tekton_cpnt-$variant
done
fi
popd
i_cpnt="$((i_cpnt+1))"
done
print_warnings