blob: 73f889748eb8e892450a88d52c1eb01f911ddd19 [file] [log] [blame]
Fatih Degirmenci459c3482020-06-15 21:15:43 +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
Fatih Degirmenci459c3482020-06-15 21:15:43 +000022set -o nounset
23set -o errexit
24set -o pipefail
25
Fatih Degirmenci6cd44a72020-07-06 07:14:17 +000026# NOTE (fdegir): in case if a change depends on another open change in different repo
27# we determine it here and override the version and refspec for that repo
28function determine_dependency() {
29 echo "Info : Determining dependency"
30 echo "Info : Commit message is"
31 echo "-------------------------------------------------------------------------"
32 echo "$GERRIT_CHANGE_COMMIT_MESSAGE"
33 echo "-------------------------------------------------------------------------"
34
35 if ! echo "$GERRIT_CHANGE_COMMIT_MESSAGE" | grep -qs "^Depends-On:"; then
36 echo "Info : No dependency found"
37 return
38 else
39 echo "Info : Dependency found!"
40 DEPENDENT_CHANGE_ID=$(echo "$GERRIT_CHANGE_COMMIT_MESSAGE" | grep "^Depends-On:" | cut -d":" -f2 | sed 's/\s*//g')
41 fi
42
43 echo "Info : Processing change $DEPENDENT_CHANGE_ID"
44 declare -a DEPENDENT_CHANGE_METADATA
45 readarray -t DEPENDENT_CHANGE_METADATA < <(curl -s "https://gerrit.nordix.org/changes/?q=$DEPENDENT_CHANGE_ID&o=CURRENT_REVISION" 2>&1 \
46 | grep "project\|status\|current_revision\|ref.*," | sed -e 's/\s//g' -e 's/,//g' -e 's/"//g'| cut -d: -f2)
47
48 # NOTE (fdegir): check if the dependeny change exists
49 # and ignore if it doesn't
50 if [[ -z "${DEPENDENT_CHANGE_METADATA+x}" ]]; then
51 echo "Warn : Unable to determine dependent change. Ignoring dependency!"
52 return
53 fi
54
55 DEPENDENT_CHANGE_PROJECT="${DEPENDENT_CHANGE_METADATA[0]}"
56 DEPENDENT_CHANGE_STATUS="${DEPENDENT_CHANGE_METADATA[1]}"
57 DEPENDENT_CHANGE_REVISION="${DEPENDENT_CHANGE_METADATA[2]}"
58 DEPENDENT_CHANGE_REFSPEC="${DEPENDENT_CHANGE_METADATA[3]}"
59 echo "-------------------------------------------------------------------------"
60 echo " DEPENDENT_CHANGE_PROJECT=$DEPENDENT_CHANGE_PROJECT"
61 echo " DEPENDENT_CHANGE_STATUS=$DEPENDENT_CHANGE_STATUS"
62 echo " DEPENDENT_CHANGE_REVISION=$DEPENDENT_CHANGE_REVISION"
63 echo " DEPENDENT_CHANGE_REFSPEC=$DEPENDENT_CHANGE_REFSPEC"
64 echo "-------------------------------------------------------------------------"
65
66 # NOTE (fdegir): we only follow the dependency if the change status is NEW
67 if [[ "$DEPENDENT_CHANGE_STATUS" != "NEW" ]]; then
68 echo "Warn : Change is not open. Ignoring dependency!"
69 return
70 fi
71
72 # NOTE (fdegir): we do not accept dependency of a change that is sent to same project as the dependent change
73 if [[ "$DEPENDENT_CHANGE_PROJECT" == "$GERRIT_PROJECT" ]]; then
74 echo "Warn : Change is for the same project. Ignoring dependency!"
75 return
76 fi
77
78 DEPENDENT_COMPONENT="${DEPENDENT_CHANGE_PROJECT//*\//}"
79
80 echo "# dependent change" >> "$CHANGE_METADATA_FILE"
81
82 # NOTE (fdegir): if dependent change is on stack repo, we need to treat it
83 # differently
84 if [[ "$DEPENDENT_CHANGE_PROJECT" =~ /stack/ ]]; then
85 # set vars
86 echo "STACK_TYPE=$DEPENDENT_COMPONENT" >> "$CHANGE_METADATA_FILE"
87 echo "STACK_VERSION=$DEPENDENT_CHANGE_REVISION" >> "$CHANGE_METADATA_FILE"
88 echo "STACK_REFSPEC=$DEPENDENT_CHANGE_REFSPEC" >> "$CHANGE_METADATA_FILE"
89 else
90 echo "NORDIX_$(echo $DEPENDENT_COMPONENT | tr a-z A-Z)_VERSION=$DEPENDENT_CHANGE_REVISION" >> "$CHANGE_METADATA_FILE"
91 echo "NORDIX_$(echo $DEPENDENT_COMPONENT | tr a-z A-Z)_REFSPEC=$DEPENDENT_CHANGE_REFSPEC" >> "$CHANGE_METADATA_FILE"
92 fi
93
94}
Fatih Degirmenci459c3482020-06-15 21:15:43 +000095
96# file to record change metadata
Fatih Degirmenci929e8b02020-07-02 20:29:39 +000097export CHANGE_METADATA_FILE="$WORKSPACE/change.properties"
Fatih Degirmenci459c3482020-06-15 21:15:43 +000098/bin/rm -f "$CHANGE_METADATA_FILE"
99
100echo "Info : Generating change metadata"
101
Fatih Degirmenci459c3482020-06-15 21:15:43 +0000102# determine the project
103# this scripts is used by all engine repos so we need to determine what this change is for
104export ENGINE_COMPONENT="${GERRIT_PROJECT//*\//}"
105
Fatih Degirmenci9f2d4dc2020-06-23 17:09:37 +0000106echo "Info : Setting STACK_TYPE and STACK_VERSION"
Fatih Degirmenci459c3482020-06-15 21:15:43 +0000107if [[ "$GERRIT_PROJECT" =~ /stack/ ]]; then
Fatih Degirmenci9f2d4dc2020-06-23 17:09:37 +0000108 # set vars
Fatih Degirmenci459c3482020-06-15 21:15:43 +0000109 export STACK_TYPE="$ENGINE_COMPONENT"
Fatih Degirmenci9f2d4dc2020-06-23 17:09:37 +0000110 export STACK_VERSION="$GERRIT_PATCHSET_REVISION"
111 export STACK_REFSPEC="$GERRIT_REFSPEC"
112
Fatih Degirmenci9f2d4dc2020-06-23 17:09:37 +0000113 # record vars to properties file
Fatih Degirmenci459c3482020-06-15 21:15:43 +0000114 echo "STACK_TYPE=$STACK_TYPE" >> "$CHANGE_METADATA_FILE"
Fatih Degirmenci5db1c8f2020-07-02 07:59:51 +0000115 echo "DEPLOY_SCENARIO=$DEPLOY_SCENARIO" >> "$CHANGE_METADATA_FILE"
Fatih Degirmenci9f2d4dc2020-06-23 17:09:37 +0000116 echo "STACK_VERSION=$STACK_VERSION" >> "$CHANGE_METADATA_FILE"
117 echo "STACK_REFSPEC=$STACK_REFSPEC" >> "$CHANGE_METADATA_FILE"
Fatih Degirmenci459c3482020-06-15 21:15:43 +0000118elif [[ "$GERRIT_PROJECT" =~ /installer/ ]]; then
Fatih Degirmenci9f2d4dc2020-06-23 17:09:37 +0000119 # set vars
Fatih Degirmenci459c3482020-06-15 21:15:43 +0000120 case "${ENGINE_COMPONENT}" in
121 kolla)
122 export STACK_TYPE="openstack"
Fatih Degirmenci5db1c8f2020-07-02 07:59:51 +0000123 echo "Info : Deploy scenario is overriden by job to $DEPLOY_SCENARIO"
Fatih Degirmenci459c3482020-06-15 21:15:43 +0000124 ;;
125 kubespray)
126 export STACK_TYPE="kubernetes"
Fatih Degirmenci5db1c8f2020-07-02 07:59:51 +0000127 echo "Info : Deploy scenario is overriden by job to $DEPLOY_SCENARIO"
Fatih Degirmenci459c3482020-06-15 21:15:43 +0000128 ;;
129 oom)
130 export STACK_TYPE="onap"
Fatih Degirmenci5db1c8f2020-07-02 07:59:51 +0000131 echo "Info : Deploy scenario is overriden by job to $DEPLOY_SCENARIO"
Fatih Degirmenci459c3482020-06-15 21:15:43 +0000132 ;;
133 *) echo "ERROR : Invalid engine component $ENGINE_COMPONENT"; exit 1;;
134 esac
Fatih Degirmenci9f2d4dc2020-06-23 17:09:37 +0000135 export STACK_VERSION="$GERRIT_BRANCH"
Fatih Degirmenci459c3482020-06-15 21:15:43 +0000136
Fatih Degirmenci9f2d4dc2020-06-23 17:09:37 +0000137 # record vars to properties file
Fatih Degirmenci459c3482020-06-15 21:15:43 +0000138 echo "STACK_TYPE=$STACK_TYPE" >> "$CHANGE_METADATA_FILE"
Fatih Degirmenci5db1c8f2020-07-02 07:59:51 +0000139 echo "DEPLOY_SCENARIO=$DEPLOY_SCENARIO" >> "$CHANGE_METADATA_FILE"
Fatih Degirmenci459c3482020-06-15 21:15:43 +0000140 echo "STACK_VERSION=$STACK_VERSION" >> "$CHANGE_METADATA_FILE"
141 echo "NORDIX_$(echo $ENGINE_COMPONENT | tr a-z A-Z)_VERSION=$GERRIT_PATCHSET_REVISION" >> "$CHANGE_METADATA_FILE"
142 echo "NORDIX_$(echo $ENGINE_COMPONENT | tr a-z A-Z)_REFSPEC=$GERRIT_REFSPEC" >> "$CHANGE_METADATA_FILE"
143else
Fatih Degirmenci9f2d4dc2020-06-23 17:09:37 +0000144 # set vars
Fatih Degirmenci459c3482020-06-15 21:15:43 +0000145 export STACK_TYPE=kubernetes
Fatih Degirmenci9f2d4dc2020-06-23 17:09:37 +0000146 export STACK_VERSION=$GERRIT_BRANCH
147
Fatih Degirmenci9f2d4dc2020-06-23 17:09:37 +0000148 # record vars to properties file
Fatih Degirmenci5db1c8f2020-07-02 07:59:51 +0000149 echo "STACK_TYPE=$STACK_TYPE" >> "$CHANGE_METADATA_FILE"
150 echo "DEPLOY_SCENARIO=$DEPLOY_SCENARIO" >> "$CHANGE_METADATA_FILE"
Fatih Degirmencib112baf2020-06-23 09:32:32 +0000151 echo "STACK_VERSION=$STACK_VERSION" >> "$CHANGE_METADATA_FILE"
Fatih Degirmenci459c3482020-06-15 21:15:43 +0000152 echo "NORDIX_$(echo $ENGINE_COMPONENT | tr a-z A-Z)_VERSION=$GERRIT_PATCHSET_REVISION" >> "$CHANGE_METADATA_FILE"
153 echo "NORDIX_$(echo $ENGINE_COMPONENT | tr a-z A-Z)_REFSPEC=$GERRIT_REFSPEC" >> "$CHANGE_METADATA_FILE"
154fi
155
156# global vars
157export NORDIX_ARM_HTTPS_URL="https://artifactory.nordix.org/artifactory"
158export ARTIFACT_ARM_FOLDER="gerrit"
159export BUILD_IDENTIFIER=$GERRIT_CHANGE_NUMBER
Fatih Degirmenci48269bf2020-07-08 13:45:53 +0000160export OFFLINE_INSTALLER_FILE="/tmp/${STACK_TYPE}-${GERRIT_BRANCH}-${DISTRO}.bsx"
161export BUILD_ARTIFACTS="/tmp/${STACK_TYPE}-${GERRIT_BRANCH}-${DISTRO}.bsx"
Fatih Degirmenci459c3482020-06-15 21:15:43 +0000162export NORDIX_ARM_REPO="nordix-${STACK_TYPE}"
Fatih Degirmenci24eaec52020-07-10 19:47:40 +0000163export NORDIX_ARTIFACT_URL="$NORDIX_ARM_HTTPS_URL/$NORDIX_ARM_REPO/oss/$ARTIFACT_ARM_FOLDER/$BUILD_IDENTIFIER"
Fatih Degirmenci459c3482020-06-15 21:15:43 +0000164
165cat << EOF >> "$CHANGE_METADATA_FILE"
166BUILD_IDENTIFIER=$BUILD_IDENTIFIER
167BUILD_DATE=$(date '+%Y%m%d%H%M')
168BUILT_BY=$BUILD_URL
Fatih Degirmencide51df02020-06-29 19:33:25 +0000169DISTRO=$DISTRO
Fatih Degirmenci459c3482020-06-15 21:15:43 +0000170CI_LOOP=$CI_LOOP
171ENGINE_SHA=$(git rev-parse HEAD)
Fatih Degirmenci48269bf2020-07-08 13:45:53 +0000172OFFLINE_INSTALLER_FILE=$OFFLINE_INSTALLER_FILE
173BUILD_ARTIFACTS=$BUILD_ARTIFACTS
Fatih Degirmenci459c3482020-06-15 21:15:43 +0000174NORDIX_ARM_REPO=nordix-${STACK_TYPE}
175NORDIX_ARTIFACT_URL=$NORDIX_ARTIFACT_URL
176EOF
177
Fatih Degirmenci6cd44a72020-07-06 07:14:17 +0000178# NOTE (fdegir): we generated the change metadata file normally until here
179# we now determine the dependency as the last step to ensure we override vars
180determine_dependency
181
Fatih Degirmenci459c3482020-06-15 21:15:43 +0000182echo "Info : Change metadata"
183echo "-------------------------------------------------------------------------"
184cat "$CHANGE_METADATA_FILE"
185echo "-------------------------------------------------------------------------"
186
187# vim: set ts=2 sw=2 expandtab: