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