blob: 14833b3e4c2d43e8145887d2b904fb78ae4b860c [file] [log] [blame]
Fatih Degirmenci7a439762019-05-07 10:39:31 +02001#!/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
21set -o errexit
22set -o nounset
23set -o pipefail
24
25# this function processes commit message to determine the impacted scenario
26# using the input provided by the committer.
27#
Fatih Degirmenci62e907a2019-07-16 11:02:09 +020028# provisioner type, installer type and scenario should be placed at the beginning of
29# lines separately and the format of the entry in commit message is as below
Fatih Degirmenci7a439762019-05-07 10:39:31 +020030#
Fatih Degirmenci62e907a2019-07-16 11:02:09 +020031# provisioner-type: <provisioner type>
Fatih Degirmenci7a439762019-05-07 10:39:31 +020032# installer-type: <installer type>
33# deploy-scenario: <scenario name>
34#
35# example is
36#
Fatih Degirmenci62e907a2019-07-16 11:02:09 +020037# provisioner-type: bifrost
Fatih Degirmenci7a439762019-05-07 10:39:31 +020038# installer-type: kubespray
39# deploy-scenario: k8-calico-nofeature
40function override_installer_scenario() {
Fatih Degirmenci62e907a2019-07-16 11:02:09 +020041 echo "Info: Processing $GERRIT_PROJECT patchset $GERRIT_REFSPEC to determine the provisioner, installer and, scenario"
Fatih Degirmenci7a439762019-05-07 10:39:31 +020042 cd $WORKSPACE
43 COMMIT_MESSAGE=$(git show -s --format=%B)
44
Fatih Degirmenci62e907a2019-07-16 11:02:09 +020045 if [[ "$COMMIT_MESSAGE" =~ "provisioner-type:" ]]; then
46 # we support heat as well so ensure we capture it
47 export PROVISIONER_TYPE=$(echo "$COMMIT_MESSAGE" | grep '^provisioner-type:' | cut -d":" -f2 | sed 's/\s*//g')
48 else
49 # default is almost always bifrost
Fatih Degirmenci9d77fc62019-11-28 16:37:31 +010050 if [[ "$PROVISIONER_TYPE" == "" ]]; then
51 export PROVISIONER_TYPE=bifrost
52 fi
Fatih Degirmenci62e907a2019-07-16 11:02:09 +020053 fi
54
Fatih Degirmenci7a439762019-05-07 10:39:31 +020055 if [[ "$COMMIT_MESSAGE" =~ "deploy-scenario:" && "$COMMIT_MESSAGE" =~ "installer-type:" ]]; then
56 export INSTALLER_TYPE=$(echo "$COMMIT_MESSAGE" | grep '^installer-type:' | cut -d":" -f2 | sed 's/\s*//g')
57 export DEPLOY_SCENARIO=$(echo "$COMMIT_MESSAGE" | grep '^deploy-scenario:' | cut -d":" -f2 | sed 's/\s*//g')
Fatih Degirmencied6187c2019-05-08 08:56:52 +020058 write_change_metadata
Fatih Degirmenci7a439762019-05-07 10:39:31 +020059 else
Fatih Degirmenci569dfca2019-05-07 11:20:53 +020060 echo "Info: Installer type or deploy scenario is not specified."
61 echo "Info: Falling back to programmatically determining them."
Fatih Degirmenci7a439762019-05-07 10:39:31 +020062 fi
63}
64
65# this function will process the changed files to determine the impacted scenario
66# if it is no specified by the committer. only one scenario per change should be
67# touched.
68# TODO: this is not implented yet.
69function determine_scenario() {
Fatih Degirmencied6187c2019-05-08 08:56:52 +020070 # for infra/engine repo, we set INSTALLER_TYPE and DEPLOY_SCENARIO to their defaults
Fatih Degirmenci569dfca2019-05-07 11:20:53 +020071 echo "Info: Processing $GERRIT_PROJECT patchset $GERRIT_REFSPEC"
Fatih Degirmencied6187c2019-05-08 08:56:52 +020072 if [[ "$GERRIT_PROJECT" == "infra/engine" ]]; then
73 echo "Info: Setting INSTALLER_TYPE and DEPLOY_SCENARIO to defaults for project $GERRIT_PROJECT patchset $GERRIT_REFSPEC"
Fatih Degirmenci8f980952019-10-17 14:56:04 +020074 export PROVISIONER_TYPE=$PROVISIONER_TYPE
Fatih Degirmencied6187c2019-05-08 08:56:52 +020075 export INSTALLER_TYPE=kubespray
76 export DEPLOY_SCENARIO=k8-calico-nofeature
77 write_change_metadata
78 else
79 cd $WORKSPACE
80 COMMIT_MESSAGE=$(git show -s --format=%B)
Fatih Degirmencicfcf7782019-10-16 01:19:17 +020081 export PROVISIONER_TYPE=none
82 export INSTALLER_TYPE=none
83 export DEPLOY_SCENARIO=none
84 write_change_metadata
Fatih Degirmencied6187c2019-05-08 08:56:52 +020085 echo "Info: Not implemented!"
Fatih Degirmenci9da0e3d2019-10-15 18:39:52 +020086 exit 0
Fatih Degirmencied6187c2019-05-08 08:56:52 +020087 fi
Fatih Degirmenci7a439762019-05-07 10:39:31 +020088}
89
Fatih Degirmencied6187c2019-05-08 08:56:52 +020090function write_change_metadata() {
91 echo "Info: Writing change metadata to $WORKSPACE/change.properties"
92 cat << EOF > $WORKSPACE/change.properties
Fatih Degirmencifcf16252019-05-07 11:00:11 +020093PROJECT_GIT_URL=$GIT_BASE_HTTPS/$GERRIT_PROJECT
Fatih Degirmenci62e907a2019-07-16 11:02:09 +020094PROVISIONER_TYPE=$PROVISIONER_TYPE
Fatih Degirmencifcf16252019-05-07 11:00:11 +020095INSTALLER_TYPE=$INSTALLER_TYPE
Fatih Degirmencied6187c2019-05-08 08:56:52 +020096DEPLOY_SCENARIO=$DEPLOY_SCENARIO
Fatih Degirmencifcf16252019-05-07 11:00:11 +020097GERRIT_PATCHSET_REVISION=$GERRIT_PATCHSET_REVISION
Fatih Degirmenci569dfca2019-05-07 11:20:53 +020098GERRIT_REFSPEC=$GERRIT_REFSPEC
Fatih Degirmencifcf16252019-05-07 11:00:11 +020099EOF
100
Fatih Degirmencied6187c2019-05-08 08:56:52 +0200101 echo "Info: Content of change.properties"
102 echo "-------------------------------------------------------------------------"
103 cat $WORKSPACE/change.properties
104 echo "-------------------------------------------------------------------------"
105
106 # need to exit here to ensure we don't go further while determining scenario
107 exit 0
108}
109
Fatih Degirmenci62e907a2019-07-16 11:02:09 +0200110echo "Info: Determining the provisioner, installer, and scenario"
Fatih Degirmencied6187c2019-05-08 08:56:52 +0200111
Fatih Degirmenci62e907a2019-07-16 11:02:09 +0200112declare -a PROVISIONER_TYPE
Fatih Degirmencied6187c2019-05-08 08:56:52 +0200113declare -a INSTALLER_TYPE
114declare -a DEPLOY_SCENARIO
115
116override_installer_scenario
117determine_scenario
Fatih Degirmenci7a439762019-05-07 10:39:31 +0200118
119# vim: set ts=2 sw=2 expandtab: