Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 1 | #!/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 Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 22 | set -o nounset |
| 23 | set -o errexit |
| 24 | set -o pipefail |
| 25 | |
Fatih Degirmenci | 6cd44a7 | 2020-07-06 07:14:17 +0000 | [diff] [blame] | 26 | # 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 |
| 28 | function 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 Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 95 | |
| 96 | # file to record change metadata |
Fatih Degirmenci | 929e8b0 | 2020-07-02 20:29:39 +0000 | [diff] [blame] | 97 | export CHANGE_METADATA_FILE="$WORKSPACE/change.properties" |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 98 | /bin/rm -f "$CHANGE_METADATA_FILE" |
| 99 | |
| 100 | echo "Info : Generating change metadata" |
| 101 | |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 102 | # determine the project |
| 103 | # this scripts is used by all engine repos so we need to determine what this change is for |
| 104 | export ENGINE_COMPONENT="${GERRIT_PROJECT//*\//}" |
| 105 | |
Fatih Degirmenci | 9f2d4dc | 2020-06-23 17:09:37 +0000 | [diff] [blame] | 106 | echo "Info : Setting STACK_TYPE and STACK_VERSION" |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 107 | if [[ "$GERRIT_PROJECT" =~ /stack/ ]]; then |
Fatih Degirmenci | 9f2d4dc | 2020-06-23 17:09:37 +0000 | [diff] [blame] | 108 | # set vars |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 109 | export STACK_TYPE="$ENGINE_COMPONENT" |
Fatih Degirmenci | 9f2d4dc | 2020-06-23 17:09:37 +0000 | [diff] [blame] | 110 | export STACK_VERSION="$GERRIT_PATCHSET_REVISION" |
| 111 | export STACK_REFSPEC="$GERRIT_REFSPEC" |
| 112 | |
Fatih Degirmenci | 9f2d4dc | 2020-06-23 17:09:37 +0000 | [diff] [blame] | 113 | # record vars to properties file |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 114 | echo "STACK_TYPE=$STACK_TYPE" >> "$CHANGE_METADATA_FILE" |
Fatih Degirmenci | 5db1c8f | 2020-07-02 07:59:51 +0000 | [diff] [blame] | 115 | echo "DEPLOY_SCENARIO=$DEPLOY_SCENARIO" >> "$CHANGE_METADATA_FILE" |
Fatih Degirmenci | 9f2d4dc | 2020-06-23 17:09:37 +0000 | [diff] [blame] | 116 | echo "STACK_VERSION=$STACK_VERSION" >> "$CHANGE_METADATA_FILE" |
| 117 | echo "STACK_REFSPEC=$STACK_REFSPEC" >> "$CHANGE_METADATA_FILE" |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 118 | elif [[ "$GERRIT_PROJECT" =~ /installer/ ]]; then |
Fatih Degirmenci | 9f2d4dc | 2020-06-23 17:09:37 +0000 | [diff] [blame] | 119 | # set vars |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 120 | case "${ENGINE_COMPONENT}" in |
| 121 | kolla) |
| 122 | export STACK_TYPE="openstack" |
Fatih Degirmenci | 5db1c8f | 2020-07-02 07:59:51 +0000 | [diff] [blame] | 123 | echo "Info : Deploy scenario is overriden by job to $DEPLOY_SCENARIO" |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 124 | ;; |
| 125 | kubespray) |
| 126 | export STACK_TYPE="kubernetes" |
Fatih Degirmenci | 5db1c8f | 2020-07-02 07:59:51 +0000 | [diff] [blame] | 127 | echo "Info : Deploy scenario is overriden by job to $DEPLOY_SCENARIO" |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 128 | ;; |
| 129 | oom) |
| 130 | export STACK_TYPE="onap" |
Fatih Degirmenci | 5db1c8f | 2020-07-02 07:59:51 +0000 | [diff] [blame] | 131 | echo "Info : Deploy scenario is overriden by job to $DEPLOY_SCENARIO" |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 132 | ;; |
| 133 | *) echo "ERROR : Invalid engine component $ENGINE_COMPONENT"; exit 1;; |
| 134 | esac |
Fatih Degirmenci | 9f2d4dc | 2020-06-23 17:09:37 +0000 | [diff] [blame] | 135 | export STACK_VERSION="$GERRIT_BRANCH" |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 136 | |
Fatih Degirmenci | 9f2d4dc | 2020-06-23 17:09:37 +0000 | [diff] [blame] | 137 | # record vars to properties file |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 138 | echo "STACK_TYPE=$STACK_TYPE" >> "$CHANGE_METADATA_FILE" |
Fatih Degirmenci | 5db1c8f | 2020-07-02 07:59:51 +0000 | [diff] [blame] | 139 | echo "DEPLOY_SCENARIO=$DEPLOY_SCENARIO" >> "$CHANGE_METADATA_FILE" |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 140 | 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" |
| 143 | else |
Fatih Degirmenci | 9f2d4dc | 2020-06-23 17:09:37 +0000 | [diff] [blame] | 144 | # set vars |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 145 | export STACK_TYPE=kubernetes |
Fatih Degirmenci | 9f2d4dc | 2020-06-23 17:09:37 +0000 | [diff] [blame] | 146 | export STACK_VERSION=$GERRIT_BRANCH |
| 147 | |
Fatih Degirmenci | 9f2d4dc | 2020-06-23 17:09:37 +0000 | [diff] [blame] | 148 | # record vars to properties file |
Fatih Degirmenci | 5db1c8f | 2020-07-02 07:59:51 +0000 | [diff] [blame] | 149 | echo "STACK_TYPE=$STACK_TYPE" >> "$CHANGE_METADATA_FILE" |
| 150 | echo "DEPLOY_SCENARIO=$DEPLOY_SCENARIO" >> "$CHANGE_METADATA_FILE" |
Fatih Degirmenci | b112baf | 2020-06-23 09:32:32 +0000 | [diff] [blame] | 151 | echo "STACK_VERSION=$STACK_VERSION" >> "$CHANGE_METADATA_FILE" |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 152 | 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" |
| 154 | fi |
| 155 | |
| 156 | # global vars |
| 157 | export NORDIX_ARM_HTTPS_URL="https://artifactory.nordix.org/artifactory" |
| 158 | export ARTIFACT_ARM_FOLDER="gerrit" |
| 159 | export BUILD_IDENTIFIER=$GERRIT_CHANGE_NUMBER |
Fatih Degirmenci | 48269bf | 2020-07-08 13:45:53 +0000 | [diff] [blame] | 160 | export OFFLINE_INSTALLER_FILE="/tmp/${STACK_TYPE}-${GERRIT_BRANCH}-${DISTRO}.bsx" |
| 161 | export BUILD_ARTIFACTS="/tmp/${STACK_TYPE}-${GERRIT_BRANCH}-${DISTRO}.bsx" |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 162 | export NORDIX_ARM_REPO="nordix-${STACK_TYPE}" |
Fatih Degirmenci | 24eaec5 | 2020-07-10 19:47:40 +0000 | [diff] [blame^] | 163 | export NORDIX_ARTIFACT_URL="$NORDIX_ARM_HTTPS_URL/$NORDIX_ARM_REPO/oss/$ARTIFACT_ARM_FOLDER/$BUILD_IDENTIFIER" |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 164 | |
| 165 | cat << EOF >> "$CHANGE_METADATA_FILE" |
| 166 | BUILD_IDENTIFIER=$BUILD_IDENTIFIER |
| 167 | BUILD_DATE=$(date '+%Y%m%d%H%M') |
| 168 | BUILT_BY=$BUILD_URL |
Fatih Degirmenci | de51df0 | 2020-06-29 19:33:25 +0000 | [diff] [blame] | 169 | DISTRO=$DISTRO |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 170 | CI_LOOP=$CI_LOOP |
| 171 | ENGINE_SHA=$(git rev-parse HEAD) |
Fatih Degirmenci | 48269bf | 2020-07-08 13:45:53 +0000 | [diff] [blame] | 172 | OFFLINE_INSTALLER_FILE=$OFFLINE_INSTALLER_FILE |
| 173 | BUILD_ARTIFACTS=$BUILD_ARTIFACTS |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 174 | NORDIX_ARM_REPO=nordix-${STACK_TYPE} |
| 175 | NORDIX_ARTIFACT_URL=$NORDIX_ARTIFACT_URL |
| 176 | EOF |
| 177 | |
Fatih Degirmenci | 6cd44a7 | 2020-07-06 07:14:17 +0000 | [diff] [blame] | 178 | # 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 |
| 180 | determine_dependency |
| 181 | |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 182 | echo "Info : Change metadata" |
| 183 | echo "-------------------------------------------------------------------------" |
| 184 | cat "$CHANGE_METADATA_FILE" |
| 185 | echo "-------------------------------------------------------------------------" |
| 186 | |
| 187 | # vim: set ts=2 sw=2 expandtab: |