prototypes: xci: update-osa-version-files: Add support for updating bifrost SHAs
[releng.git] / prototypes / xci / scripts / update-osa-version-files.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2017 SUSE LINUX GmbH and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 # This script is used to pin the SHAs for the various roles in the
12 # ansible-role-requirements file. It will also update the SHAs for
13 # OSA and bifrost.
14
15 set -e
16
17 # NOTE(hwoarang) This could break if files are re-arranged in the future
18 releng_xci_base="$(dirname $(readlink -f $0))/.."
19
20 usage() {
21     echo """
22     ${0} <openstack-ansible commit SHA> [<bifrost commit SHA>]
23     """
24     exit 0
25 }
26
27 cleanup() {
28     [[ -d $tempdir ]] && rm -rf $tempdir
29 }
30
31 printme() {
32     echo "===> $1"
33 }
34
35 # Only need a single argument
36 [[ $# -lt 1 || $# -gt 2 ]] && echo "Invalid number of arguments!" && usage
37
38 tempdir="$(mktemp -d)"
39
40 trap cleanup EXIT
41
42 pushd $tempdir &> /dev/null
43
44 printme "Downloading the sources-branch-updater-lib.sh library"
45
46 printme "Cloning the openstack-ansible repository"
47 (
48     git clone -q git://git.openstack.org/openstack/openstack-ansible && cd openstack-ansible && git checkout -q $1
49 )
50
51 popd &> /dev/null
52
53 pushd $tempdir/openstack-ansible &> /dev/null
54 source scripts/sources-branch-updater-lib.sh
55 printme "Synchronize roles and packages"
56 update_ansible_role_requirements "master" "true" "true"
57
58 # Construct the ansible-role-requirements-file
59 echo """---
60 # SPDX-license-identifier: Apache-2.0
61 ##############################################################################
62 # Copyright (c) 2017 Ericsson AB and others.
63 # All rights reserved. This program and the accompanying materials
64 # are made available under the terms of the Apache License, Version 2.0
65 # which accompanies this distribution, and is available at
66 # http://www.apache.org/licenses/LICENSE-2.0
67 ##############################################################################
68 # these versions are extracted based on the osa commit ${1} on $(git --no-pager log -1 --format=%cI $1)
69 # https://review.openstack.org/gitweb?p=openstack/openstack-ansible.git;a=commit;h=$1""" > $releng_xci_base/file/ansible-role-requirements.yml
70 cat $tempdir/openstack-ansible/ansible-role-requirements.yml >> $releng_xci_base/file/ansible-role-requirements.yml
71
72 # Update the pinned OSA version
73 sed -i "/^export OPENSTACK_OSA_VERSION/s@:-\"[a-z0-9]*@:-\"${1}@" $releng_xci_base/config/pinned-versions
74
75 # Update the pinned bifrost version
76 [[ -n ${2:-} ]] && \
77     sed -i "/^export OPENSTACK_BIFROST_VERSION/s@:-\"[a-z0-9]*@:-\"${2}@" $releng_xci_base/config/pinned-versions
78
79 popd &> /dev/null
80
81 printme ""
82 printme "======================= Report ============================"
83 printme ""
84 printme "The $releng_xci_base/file/ansible-role-requirements.yml and"
85 printme "$releng_xci_base/config/pinned-versions files have been"
86 printme "updated. Please make sure you test the end result before"
87 printme "committing it!"
88 printme ""
89 printme "==========================================================="