Fatih Degirmenci | 7a43976 | 2019-05-07 10:39:31 +0200 | [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 | set -o errexit |
| 22 | set -o nounset |
| 23 | set -o pipefail |
| 24 | |
| 25 | # this function processes commit message to determine the impacted scenario |
| 26 | # using the input provided by the committer. |
| 27 | # |
Fatih Degirmenci | 62e907a | 2019-07-16 11:02:09 +0200 | [diff] [blame] | 28 | # 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 Degirmenci | 7a43976 | 2019-05-07 10:39:31 +0200 | [diff] [blame] | 30 | # |
Fatih Degirmenci | 62e907a | 2019-07-16 11:02:09 +0200 | [diff] [blame] | 31 | # provisioner-type: <provisioner type> |
Fatih Degirmenci | 7a43976 | 2019-05-07 10:39:31 +0200 | [diff] [blame] | 32 | # installer-type: <installer type> |
| 33 | # deploy-scenario: <scenario name> |
| 34 | # |
| 35 | # example is |
| 36 | # |
Fatih Degirmenci | 62e907a | 2019-07-16 11:02:09 +0200 | [diff] [blame] | 37 | # provisioner-type: bifrost |
Fatih Degirmenci | 7a43976 | 2019-05-07 10:39:31 +0200 | [diff] [blame] | 38 | # installer-type: kubespray |
| 39 | # deploy-scenario: k8-calico-nofeature |
| 40 | function override_installer_scenario() { |
Fatih Degirmenci | 62e907a | 2019-07-16 11:02:09 +0200 | [diff] [blame] | 41 | echo "Info: Processing $GERRIT_PROJECT patchset $GERRIT_REFSPEC to determine the provisioner, installer and, scenario" |
Fatih Degirmenci | 7a43976 | 2019-05-07 10:39:31 +0200 | [diff] [blame] | 42 | cd $WORKSPACE |
| 43 | COMMIT_MESSAGE=$(git show -s --format=%B) |
| 44 | |
Fatih Degirmenci | 62e907a | 2019-07-16 11:02:09 +0200 | [diff] [blame] | 45 | 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 |
| 50 | export PROVISIONER_TYPE=bifrost |
| 51 | fi |
| 52 | |
Fatih Degirmenci | 7a43976 | 2019-05-07 10:39:31 +0200 | [diff] [blame] | 53 | if [[ "$COMMIT_MESSAGE" =~ "deploy-scenario:" && "$COMMIT_MESSAGE" =~ "installer-type:" ]]; then |
| 54 | export INSTALLER_TYPE=$(echo "$COMMIT_MESSAGE" | grep '^installer-type:' | cut -d":" -f2 | sed 's/\s*//g') |
| 55 | export DEPLOY_SCENARIO=$(echo "$COMMIT_MESSAGE" | grep '^deploy-scenario:' | cut -d":" -f2 | sed 's/\s*//g') |
Fatih Degirmenci | ed6187c | 2019-05-08 08:56:52 +0200 | [diff] [blame] | 56 | write_change_metadata |
Fatih Degirmenci | 7a43976 | 2019-05-07 10:39:31 +0200 | [diff] [blame] | 57 | else |
Fatih Degirmenci | 569dfca | 2019-05-07 11:20:53 +0200 | [diff] [blame] | 58 | echo "Info: Installer type or deploy scenario is not specified." |
| 59 | echo "Info: Falling back to programmatically determining them." |
Fatih Degirmenci | 7a43976 | 2019-05-07 10:39:31 +0200 | [diff] [blame] | 60 | fi |
| 61 | } |
| 62 | |
| 63 | # this function will process the changed files to determine the impacted scenario |
| 64 | # if it is no specified by the committer. only one scenario per change should be |
| 65 | # touched. |
| 66 | # TODO: this is not implented yet. |
| 67 | function determine_scenario() { |
Fatih Degirmenci | ed6187c | 2019-05-08 08:56:52 +0200 | [diff] [blame] | 68 | # for infra/engine repo, we set INSTALLER_TYPE and DEPLOY_SCENARIO to their defaults |
Fatih Degirmenci | 569dfca | 2019-05-07 11:20:53 +0200 | [diff] [blame] | 69 | echo "Info: Processing $GERRIT_PROJECT patchset $GERRIT_REFSPEC" |
Fatih Degirmenci | ed6187c | 2019-05-08 08:56:52 +0200 | [diff] [blame] | 70 | if [[ "$GERRIT_PROJECT" == "infra/engine" ]]; then |
| 71 | echo "Info: Setting INSTALLER_TYPE and DEPLOY_SCENARIO to defaults for project $GERRIT_PROJECT patchset $GERRIT_REFSPEC" |
Fatih Degirmenci | 8f98095 | 2019-10-17 14:56:04 +0200 | [diff] [blame] | 72 | export PROVISIONER_TYPE=$PROVISIONER_TYPE |
Fatih Degirmenci | ed6187c | 2019-05-08 08:56:52 +0200 | [diff] [blame] | 73 | export INSTALLER_TYPE=kubespray |
| 74 | export DEPLOY_SCENARIO=k8-calico-nofeature |
| 75 | write_change_metadata |
| 76 | else |
| 77 | cd $WORKSPACE |
| 78 | COMMIT_MESSAGE=$(git show -s --format=%B) |
Fatih Degirmenci | cfcf778 | 2019-10-16 01:19:17 +0200 | [diff] [blame] | 79 | export PROVISIONER_TYPE=none |
| 80 | export INSTALLER_TYPE=none |
| 81 | export DEPLOY_SCENARIO=none |
| 82 | write_change_metadata |
Fatih Degirmenci | ed6187c | 2019-05-08 08:56:52 +0200 | [diff] [blame] | 83 | echo "Info: Not implemented!" |
Fatih Degirmenci | 9da0e3d | 2019-10-15 18:39:52 +0200 | [diff] [blame] | 84 | exit 0 |
Fatih Degirmenci | ed6187c | 2019-05-08 08:56:52 +0200 | [diff] [blame] | 85 | fi |
Fatih Degirmenci | 7a43976 | 2019-05-07 10:39:31 +0200 | [diff] [blame] | 86 | } |
| 87 | |
Fatih Degirmenci | ed6187c | 2019-05-08 08:56:52 +0200 | [diff] [blame] | 88 | function write_change_metadata() { |
| 89 | echo "Info: Writing change metadata to $WORKSPACE/change.properties" |
| 90 | cat << EOF > $WORKSPACE/change.properties |
Fatih Degirmenci | fcf1625 | 2019-05-07 11:00:11 +0200 | [diff] [blame] | 91 | PROJECT_GIT_URL=$GIT_BASE_HTTPS/$GERRIT_PROJECT |
Fatih Degirmenci | 62e907a | 2019-07-16 11:02:09 +0200 | [diff] [blame] | 92 | PROVISIONER_TYPE=$PROVISIONER_TYPE |
Fatih Degirmenci | fcf1625 | 2019-05-07 11:00:11 +0200 | [diff] [blame] | 93 | INSTALLER_TYPE=$INSTALLER_TYPE |
Fatih Degirmenci | ed6187c | 2019-05-08 08:56:52 +0200 | [diff] [blame] | 94 | DEPLOY_SCENARIO=$DEPLOY_SCENARIO |
Fatih Degirmenci | fcf1625 | 2019-05-07 11:00:11 +0200 | [diff] [blame] | 95 | GERRIT_PATCHSET_REVISION=$GERRIT_PATCHSET_REVISION |
Fatih Degirmenci | 569dfca | 2019-05-07 11:20:53 +0200 | [diff] [blame] | 96 | GERRIT_REFSPEC=$GERRIT_REFSPEC |
Fatih Degirmenci | fcf1625 | 2019-05-07 11:00:11 +0200 | [diff] [blame] | 97 | EOF |
| 98 | |
Fatih Degirmenci | ed6187c | 2019-05-08 08:56:52 +0200 | [diff] [blame] | 99 | echo "Info: Content of change.properties" |
| 100 | echo "-------------------------------------------------------------------------" |
| 101 | cat $WORKSPACE/change.properties |
| 102 | echo "-------------------------------------------------------------------------" |
| 103 | |
| 104 | # need to exit here to ensure we don't go further while determining scenario |
| 105 | exit 0 |
| 106 | } |
| 107 | |
Fatih Degirmenci | 62e907a | 2019-07-16 11:02:09 +0200 | [diff] [blame] | 108 | echo "Info: Determining the provisioner, installer, and scenario" |
Fatih Degirmenci | ed6187c | 2019-05-08 08:56:52 +0200 | [diff] [blame] | 109 | |
Fatih Degirmenci | 62e907a | 2019-07-16 11:02:09 +0200 | [diff] [blame] | 110 | declare -a PROVISIONER_TYPE |
Fatih Degirmenci | ed6187c | 2019-05-08 08:56:52 +0200 | [diff] [blame] | 111 | declare -a INSTALLER_TYPE |
| 112 | declare -a DEPLOY_SCENARIO |
| 113 | |
| 114 | override_installer_scenario |
| 115 | determine_scenario |
Fatih Degirmenci | 7a43976 | 2019-05-07 10:39:31 +0200 | [diff] [blame] | 116 | |
| 117 | # vim: set ts=2 sw=2 expandtab: |