-
Notifications
You must be signed in to change notification settings - Fork 19
/
add-new-release-single
executable file
·223 lines (183 loc) · 7.14 KB
/
add-new-release-single
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/bin/bash -e
#
# Add new release support including new bundles, updates to config.yaml,
# charmcraft.yaml, tests.yaml, osci.yaml, and .zuul.yaml.
prev_series_bundle=$1
prev_uca_bundle=$2
new_series_bundle=$3
new_uca_bundle=$4
prev_ubuntu_version=$5
new_ubuntu_version=$6
prev_ubuntu_series=$7
new_ubuntu_series=$8
charmcraft_yaml=$(find . -name charmcraft.yaml)
config_yaml=$(find . -name config.yaml)
metadata_yaml=$(find . -name metadata.yaml)
osci_yaml=$(find . -name osci.yaml)
tests_yaml=$(find . -name tests.yaml)
zuul_yaml=$(find . -name .zuul.yaml)
usage="usage: add-new-release-batch prev-series-bundle prev-uca-bundle
new-series-bundle new-uca-bundle prev-ubuntu-version new-ubuntu-version
prev-ubuntu-series new-ubuntu-series"
example="example: add-new-release-batch lunar-antelope.yaml jammy-antelope.yaml
mantic-bobcat.yaml jammy-bobcat.yaml 23.04 23.10 lunar mantic"
if [[ -z "$prev_series_bundle" || -z "$prev_uca_bundle" || \
-z "$new_series_bundle" || -z "$new_uca_bundle" || \
-z "$prev_ubuntu_version" || -z "$new_ubuntu_version" || \
-z "$prev_ubuntu_series" || -z "$new_ubuntu_series" ]]; then
echo $usage
echo $example
exit 1
fi
function get_series {
local bundle_path=$1
echo $bundle_path | sed 's/.*\/tests\/bundles\/\(.*\)\-.*.yaml/\1/1'
}
function get_release {
local bundle_path=$1
echo $bundle_path | sed 's/.*\/tests\/bundles\/\(.*\).yaml/\1/1'
}
function get_os_codename {
local bundle=$1
echo $bundle | sed 's/.*\-\(.*\)\.yaml/\1/1'
}
function create_new_bundle {
local prev_bundle=$1
local new_bundle=$2
local tests_yaml=$3
local prev_bundle_path=$(find . -name ${prev_bundle})
if [ -z $prev_bundle_path ]; then
echo "Bundle doesn't exist: ${prev_bundle}"
return
fi
local prev_series=$(get_series $prev_bundle_path)
local prev_release=$(get_release $prev_bundle_path)
local new_bundle_path=$(dirname $prev_bundle_path)/${new_bundle}
if [ -f $new_bundle_path ]; then
echo "Bundle already exists: ${new_bundle_path}"
return
fi
local new_series=$(get_series $new_bundle_path)
local new_release=$(get_release $new_bundle_path)
cp $prev_bundle_path $new_bundle_path
sed -i "s/${prev_release}/${new_release}/1" $new_bundle_path
sed -i "s/${prev_series}/${new_series}/1" $new_bundle_path
sed -i "s/\(.*\)${prev_release}\(.*\)/\1${prev_release}\2\n\1${new_release}\2/g" $tests_yaml
git add $new_bundle_path
}
function add_new_osci_job {
local osci_yaml=$1
local prev_os_codename=$2
local new_os_codename=$3
local prev_unit_job="charm-${prev_os_codename}-unit-jobs"
local new_unit_job="charm-${new_os_codename}-unit-jobs"
local prev_func_job="charm-${prev_os_codename}-functional-jobs"
local new_func_job="charm-${new_os_codename}-functional-jobs"
if grep -Fq "$new_unit_job" "$osci_yaml"; then
echo "Job $new_unit_job already exists in $osci_yaml"
return
fi
if grep -Fq "$new_func_job" "$osci_yaml"; then
echo "Job $new_func_job already exists in $osci_yaml"
return
fi
if grep -Fq "$prev_unit_job" "$osci_yaml"; then
sed -i "s/\(.*\)${prev_unit_job}\(.*\)/\1${prev_unit_job}\2\n\1${new_unit_job}\2/1" $osci_yaml
else
echo "Job $prev_unit_job doesn't exists in $osci_yaml"
fi
if grep -Fq "$prev_func_job" "$osci_yaml"; then
sed -i "s/\(.*\)${prev_func_job}\(.*\)/\1${prev_func_job}\2\n\1${new_func_job}\2/1" $osci_yaml
else
echo "Job $prev_func_job doesn't exists in $osci_yaml"
fi
}
function add_new_zuul_job {
local zuul_yaml=$1
local prev_os_codename=$2
local new_os_codename=$3
local prev_job="openstack-python3-charm-${prev_os_codename}-jobs"
local new_job="openstack-python3-charm-${new_os_codename}-jobs"
if grep -Fq "$new_job" "$zuul_yaml"; then
echo "Job $new_job already exists in $zuul_yaml"
return
fi
if grep -Fq "$prev_job" "$zuul_yaml"; then
sed -i "s/\(.*\)${prev_job}\(.*\)/\1${prev_job}\2\n\1${new_job}\2/1" $zuul_yaml
else
echo "Job $prev_job doesn't exists in $zuul_yaml"
fi
}
function add_new_config_default {
local config_yaml=$1
local prev_os_codename=$2
local new_os_codename=$3
if [ ! -f $config_yaml ]; then
echo "File doesn't exist: ${config_yaml}"
return
fi
if grep -Fq "$new_os_codename" "$config_yaml"; then
echo "$new_os_codename already exists in $config_yaml"
return
fi
if grep -Fq "$prev_os_codename" "$config_yaml"; then
sed -i "s/default: ${prev_os_codename}/default: ${new_os_codename}/1" $config_yaml
else
echo "Job $prev_os_codename doesn't exists in $config_yaml"
fi
}
function create_run_on_base {
local channel=$1
local arch=$2
local run_on=" \- name\: ubuntu\n channel: \\\""${channel}"\\\"\n architectures\: \[${arch}\]"
echo "$run_on"
}
function add_new_run_on_bases {
local charmcraft_yaml=$1
local prev_ubuntu_version=$2
local new_ubuntu_version=$3
if grep -Fq "$new_ubuntu_version" "$charmcraft_yaml"; then
echo "Version $new_ubuntu_version already exists in $charmcraft_yaml"
return
fi
local all_arches="amd64, s390x, ppc64el, arm64"
if grep "\[${all_arches}\]" "$charmcraft_yaml"; then
local prev_run_on=$(create_run_on_base "$prev_ubuntu_version" "$all_arches")
local new_run_on=$(create_run_on_base "$new_ubuntu_version" "$all_arches")
sed -i -z "s/\(${prev_run_on}\)/\1\n${new_run_on}/1" $charmcraft_yaml
else
for arch in "amd64" "arm64" "ppc64el" "s390x"; do
local prev_run_on=$(create_run_on_base "$prev_ubuntu_version" "$arch")
local new_run_on=$(create_run_on_base "$new_ubuntu_version" "$arch")
sed -i -z "s/\(${prev_run_on}\)/\1\n${new_run_on}/1" $charmcraft_yaml
done
fi
}
function add_new_metadata_series {
local prev_ubuntu_series=$1
local new_ubuntu_series=$2
local metadata_yaml=$3
if [ ! -f $metadata_yaml ]; then
echo "File doesn't exist: ${metadata_yaml}"
return
fi
if grep -Fq "$new_ubuntu_series" "$metadata_yaml"; then
echo "$new_ubuntu_series already exists in $metadata_yaml"
return
fi
if grep -Fq "$prev_ubuntu_series" "$metadata_yaml"; then
echo $metadata_yaml
sed -i "s/\(.*\)${prev_ubuntu_series}\(.*\)/\1${prev_ubuntu_series}\2\n\1${new_ubuntu_series}\2/g" $metadata_yaml
else
echo "Series ${prev_series} does not exist in $metadata_yaml"
fi
}
prev_os_codename=$(get_os_codename "$prev_series_bundle")
new_os_codename=$(get_os_codename "$new_series_bundle")
create_new_bundle $prev_series_bundle $new_series_bundle $tests_yaml
create_new_bundle $prev_uca_bundle $new_uca_bundle $tests_yaml
add_new_osci_job $osci_yaml $prev_os_codename $new_os_codename
add_new_zuul_job $zuul_yaml $prev_os_codename $new_os_codename
add_new_config_default $config_yaml $prev_os_codename $new_os_codename
add_new_run_on_bases $charmcraft_yaml $prev_ubuntu_version $new_ubuntu_version
add_new_metadata_series $prev_ubuntu_series $new_ubuntu_series $metadata_yaml