summaryrefslogtreecommitdiffstats
path: root/integration/src/release_scripts/updateRefs.sh
blob: ea67748734c74c3970f0f4e61e2f80c377a8e011 (plain)
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
#!/bin/bash

#
# ============LICENSE_START================================================
# ONAP
# =========================================================================
# Copyright (C) 2021-2022 Nordix Foundation.
# =========================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============LICENSE_END==================================================
#

set -e

SCRIPT_NAME=`basename $0`
repo_location="./"
release_data_file="./pf_release_data.csv"

# Use the bash internal OSTYPE variable to check for MacOS
if [[ "$OSTYPE" == "darwin"* ]]
then
    SED="gsed"
else
    SED="sed"
fi

usage()
{
    echo ""
    echo "$SCRIPT_NAME - updates the inter-repo references in Policy Framework POM files"
    echo ""
    echo "       usage:  $SCRIPT_NAME [-options]"
    echo ""
    echo "       options"
    echo "         -h           - this help message"
    echo "         -d data_file - the policy release data file to use, generated by the 'getReleaseData.sh' script,"
    echo "                        defaults to '$release_data_file'"
    echo "         -l location  - the location of the policy framework repos on the file system,"
    echo "                        defaults to '$repo_location'"
    echo "         -r repo      - the policy repo to update"
    echo "         -p           - update policy/parent references"
    echo "         -c           - update policy/common references"
    echo "         -m           - update policy/model references"
    echo "         -o           - update policy/drools-pdp references"
    echo "         -k           - update docker base images in Dockerfiles"
    echo "         -s           - update release references to snapshot references,"
    echo "                        if omitted, snapshot references are updated to release references"
    echo ""
    echo " examples:"
    echo "  $SCRIPT_NAME -pcm -r policy/pap"
    echo "              update the parent, common, and models references of policy/pap"
    echo "              to the current released version"
    echo ""
    echo "  $SCRIPT_NAME -c -m -s -r policy/api"
    echo "              update the common and models references of policy/api"
    echo "              to the current snapshot version"
    exit 255;
}

update_parent=false
update_common=false
update_models=false
update_drools_pdp=false
update_snapshot=false
update_docker=false

while getopts "hd:l:r:pcmoks" opt
do
    case $opt in
    h)
        usage
        ;;
    d)
        release_data_file=$OPTARG
        ;;
    l)
        repo_location=$OPTARG
        ;;
    r)
        specified_repo=$OPTARG
        ;;
    p)
        update_parent=true
        ;;
    c)
        update_common=true
        ;;
    m)
        update_models=true
        ;;
    o)
        update_drools_pdp=true
        ;;
    k)
        update_docker=true
        ;;
    s)
        update_snapshot=true
        ;;
    \?)
        usage
        exit 1
        ;;
    esac
done

if [ $OPTIND -eq 1 ]
then
    echo "no arguments were specified"
    usage
fi

if [[ -z "$repo_location" ]]
then
    echo "policy repo location not specified on -l flag"
    exit 1
fi

if ! [ -d "$repo_location" ]
then
    echo "policy repo location '$repo_location' not found"
    exit 1
fi

if [[ -z "$release_data_file" ]]
then
    echo "policy release data file not specified on -d flag"
    exit 1
fi

if ! [ -f "$release_data_file" ]
then
    echo "policy release data file '$release_data_file' not found"
    exit 1
fi

if [ -z "$specified_repo" ]
then
    echo "repo not specified on -r flag"
    exit 1
fi

read parent_repo \
     parent_latest_released_tag \
     parent_latest_snapshot_tag \
     parent_changed_files \
     parent_docker_images \
    <<< $( grep policy/parent $release_data_file | tr ',' ' ' )

read common_repo \
     common_latest_released_tag \
     common_latest_snapshot_tag \
     common_changed_files \
     common_docker_images \
    <<< $( grep policy/common $release_data_file | tr ',' ' ' )

read docker_repo \
     docker_latest_released_tag \
     docker_latest_snapshot_tag \
     docker_changed_files \
     docker_docker_images \
    <<< $( grep policy/docker $release_data_file | tr ',' ' ' )

read models_repo \
     models_latest_released_tag \
     models_latest_snapshot_tag \
     models_changed_files \
     models_docker_images \
    <<< $( grep policy/models $release_data_file | tr ',' ' ' )

read drools_pdp_repo \
     drools_pdp_latest_released_tag \
     drools_pdp_latest_snapshot_tag \
     drools_pdp_changed_files \
     drools_pdp_docker_images \
    <<< $( grep policy/drools-pdp $release_data_file | tr ',' ' ' )

read target_repo \
	 target_latest_released_tag \
	 target_latest_snapshot_tag \
	 target_changed_files \
	 target_docker_images \
	<<< $( grep $specified_repo $release_data_file | tr ',' ' ' )

if [ -z "$target_repo" ]
then
    echo "specified repo '$specified_repo' not found in policy release data file '$release_data_file'"
    exit 1
fi

if [ ! "$specified_repo" = "$target_repo" ]
then
    echo "specified repo '$specified_repo' does not match target repo '$target_repo'"
    exit 1
fi

if [ "$update_parent" = true ]
then
    if [ "$specified_repo" = "policy/parent" ]
    then
        if [ "$update_snapshot" = true ]
        then
            echo updating policy parent reference to $parent_latest_snapshot_tag on $repo_location/$target_repo . . .
            $SED -i \
                "s/<version.parent.resources>.*<\/version.parent.resources>/<version.parent.resources>$parent_latest_snapshot_tag<\/version.parent.resources>/" \
                 $repo_location/policy/parent/integration/pom.xml
            result_code=$?
        else
            next_release_version=${parent_latest_snapshot_tag%-*}

            echo updating policy parent reference to $next_release_version on $repo_location/$target_repo . . .
            $SED -i \
                "s/<version.parent.resources>.*<\/version.parent.resources>/<version.parent.resources>$next_release_version<\/version.parent.resources>/" \
                $repo_location/policy/parent/integration/pom.xml
            result_code=$?
        fi
    else
        if [ "$update_snapshot" = true ]
        then
            echo updating policy parent reference to $parent_latest_snapshot_tag on $repo_location/$target_repo . . .
            updateParentRef.sh \
                -f $repo_location/$target_repo/pom.xml \
                -g org.onap.policy.parent \
                -a integration \
                -v $parent_latest_snapshot_tag
            result_code=$?
        else
            echo updating policy parent reference to $parent_latest_released_tag on $repo_location/$target_repo . . .
            updateParentRef.sh \
                -f $repo_location/$target_repo/pom.xml \
                -g org.onap.policy.parent \
                -a integration \
                -v $parent_latest_released_tag
            result_code=$?
        fi
    fi
    if [[ "$result_code" -eq 0 ]]
    then
        echo policy parent reference updated on $repo_location/$target_repo
    else
        echo policy parent reference update failed on $repo_location/$target_repo
        exit 1
    fi
fi

if [ "$update_common" = true ]
then
    if [ "$update_snapshot" = true ]
    then
        echo updating policy common reference to $common_latest_snapshot_tag on $repo_location/$target_repo . . .
        $SED -i \
            -e "s/<policy.common.version>.*<\/policy.common.version>/<policy.common.version>$common_latest_snapshot_tag<\/policy.common.version>/" \
            -e "s/<version.policy.common>.*<\/version.policy.common>/<version.policy.common>$common_latest_snapshot_tag<\/version.policy.common>/" \
            $repo_location/$target_repo/pom.xml
        result_code=$?
    else
        echo updating policy common reference to $common_latest_released_tag on $repo_location/$target_repo . . .
        $SED -i \
            -e "s/<policy.common.version>.*<\/policy.common.version>/<policy.common.version>$common_latest_released_tag<\/policy.common.version>/" \
            -e "s/<version.policy.common>.*<\/version.policy.common>/<version.policy.common>$common_latest_released_tag<\/version.policy.common>/" \
            $repo_location/$target_repo/pom.xml
        result_code=$?
    fi
    if [[ "$result_code" -eq 0 ]]
    then
        echo policy common reference updated on $repo_location/$target_repo
    else
        echo policy common reference update failed on $repo_location/$target_repo
        exit 1
    fi
fi

if [ "$update_models" = true ]
then
    if [ "$update_snapshot" = true ]
    then
        echo updating policy models reference to $models_latest_snapshot_tag on $repo_location/$target_repo . . .
        $SED -i \
            -e "s/<policy.models.version>.*<\/policy.models.version>/<policy.models.version>$models_latest_snapshot_tag<\/policy.models.version>/" \
            -e "s/<version.policy.models>.*<\/version.policy.models>/<version.policy.models>$models_latest_snapshot_tag<\/version.policy.models>/" \
            $repo_location/$target_repo/pom.xml
        result_code=$?
    else
        echo updating policy models reference to $models_latest_released_tag on $repo_location/$target_repo . . .
        $SED -i \
            -e "s/<policy.models.version>.*<\/policy.models.version>/<policy.models.version>$models_latest_released_tag<\/policy.models.version>/" \
            -e "s/<version.policy.models>.*<\/version.policy.models>/<version.policy.models>$models_latest_released_tag<\/version.policy.models>/" \
            $repo_location/$target_repo/pom.xml
        result_code=$?
    fi
    if [[ "$result_code" -eq 0 ]]
    then
        echo policy models reference updated on $repo_location/$target_repo
    else
        echo policy models reference update failed on $repo_location/$target_repo
        exit 1
    fi
fi

if [ "$update_drools_pdp" = true ]
then
    if [ "$update_snapshot" = true ]
    then
        echo updating policy drools-pdp reference to $drools_pdp_latest_snapshot_tag on $repo_location/$target_repo . . .
        $SED -i \
            -e "s/<policy.drools-pdp.version>.*<\/policy.drools-pdp.version>/<policy.drools-pdp.version>$drools_pdp_latest_snapshot_tag<\/policy.drools-pdp.version>/" \
            -e "s/<version.policy.drools-pdp>.*<\/version.policy.drools-pdp>/<version.policy.drools-pdp>$drools_pdp_latest_snapshot_tag<\/version.policy.drools-pdp>/" \
            $repo_location/$target_repo/pom.xml
        result_code=$?
    else
        echo updating policy drools-pdp reference to $drools_pdp_latest_released_tag on $repo_location/$target_repo . . .
        $SED -i \
            -e "s/<policy.drools-pdp.version>.*<\/policy.drools-pdp.version>/<policy.drools-pdp.version>$drools_pdp_latest_released_tag<\/policy.drools-pdp.version>/" \
            -e "s/<version.policy.drools-pdp>.*<\/version.policy.drools-pdp>/<version.policy.drools-pdp>$drools_pdp_latest_released_tag<\/version.policy.drools-pdp>/" \
            $repo_location/$target_repo/pom.xml
        result_code=$?
    fi
    if [[ "$result_code" -eq 0 ]]
    then
        echo policy drools-pdp reference updated on $repo_location/$target_repo
    else
        echo policy drools-pdp reference update failed on $repo_location/$target_repo
        exit 1
    fi
fi

if [ "$update_docker" = true ] && [ "$target_docker_images" != "" ]
then
    echo updating docker base images to version $docker_latest_released_tag on repo $repo_location/$target_repo
    find $repo_location/$target_repo \
        -name '*Docker*' \
        -exec $SED -r -i "s/^(FROM onap\/policy-j[d|r][k|e]-alpine:)2.3.1$/\1$docker_latest_released_tag/" {} \;
    result_code=$?
    if [[ "$result_code" -eq 0 ]]
    then
        echo docker base images updated on $repo_location/$target_repo
    else
        echo docker base images update failed on $repo_location/$target_repo
        exit 1
    fi
fi