blob: cf888080bc0f14aa39708a3dbad9079432beac9b [file] [log] [blame]
Fatih Degirmencie4628f62020-04-19 17:58:00 +00001#!/bin/bash
2
3# ============LICENSE_START=======================================================
4# Copyright (C) 2019 The Nordix Foundation. All rights reserved.
5# ================================================================================
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18# SPDX-License-Identifier: Apache-2.0
19# ============LICENSE_END=========================================================
20
21# NOTE (fdegir): we do not need to do anything for the changes coming to infra/engine repo
22if [[ "$GERRIT_PROJECT" == "infra/engine" ]]; then
23 exit 0
24fi
25
26echo "Info : Cloning infra/engine repository"
27cd "$HOME" && /bin/rm -rf "$WORKSPACE"
28git clone -q "$ENGINE_REPO_URL" "$WORKSPACE"
29
30export SDF_ORIGINAL="$WORKSPACE/engine/inventory/group_vars/all/sdf.yaml"
31export SDF_PATCHSET="/tmp/sdf.yaml.$GERRIT_CHANGE_NUMBER"
32
33/bin/rm -rf "$SDF_PATCHSET"
34
35export TOOL_TYPE="${GERRIT_PROJECT//*\//}"
36export TOOL_MATCH="false"
37echo "Info : Tool type is $TOOL_TYPE"
38echo "Info : Updating SDF with change SHA and refspec"
39while IFS= read -r line; do
40 if [[ "$TOOL_MATCH" == "true" && "$line" =~ "version" ]]; then
41 echo "$line" | sed "s#version:.*#version: $GERRIT_PATCHSET_REVISION\n refspec: $GERRIT_REFSPEC#g" >> "$SDF_PATCHSET"
42 export TOOL_MATCH="false"
43 continue
44 fi
45 if [[ "$line" =~ "$TOOL_TYPE:" && "$TOOL_MATCH" == "false" ]]; then
46 export TOOL_MATCH="true"
47 fi
48 echo "$line" >> "$SDF_PATCHSET"
49done < "$SDF_ORIGINAL"
50# NOTE (fdegir): log the diff for possible troubleshooting
51echo
52echo "Info : Diff between original SDF and SDF generated for the change"
53echo "-------------------------------------------------------------------------"
54diff "$SDF_ORIGINAL" "$SDF_PATCHSET"
55echo "-------------------------------------------------------------------------"
56echo
57
58# NOTE (fdegir): move SDF generated for the change into the original SDF
59/bin/mv -f "$SDF_PATCHSET" "$SDF_ORIGINAL"
60
61# NOTE (fdegir): log the final SDF
62echo
63echo "Info : Generated SDF content"
64echo "-------------------------------------------------------------------------"
65cat "$SDF_ORIGINAL"
66echo "-------------------------------------------------------------------------"
67echo