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 | # |
| 28 | # installer type and scenario should be placed at the beginning of lines |
| 29 | # separately and the format of the entry in commit message is as below |
| 30 | # |
| 31 | # installer-type: <installer type> |
| 32 | # deploy-scenario: <scenario name> |
| 33 | # |
| 34 | # example is |
| 35 | # |
| 36 | # installer-type: kubespray |
| 37 | # deploy-scenario: k8-calico-nofeature |
| 38 | function override_installer_scenario() { |
Fatih Degirmenci | 569dfca | 2019-05-07 11:20:53 +0200 | [diff] [blame^] | 39 | echo "Info: Processing $GERRIT_PROJECT patchset $GERRIT_REFSPEC to determine the installer and the scenario" |
Fatih Degirmenci | 7a43976 | 2019-05-07 10:39:31 +0200 | [diff] [blame] | 40 | cd $WORKSPACE |
| 41 | COMMIT_MESSAGE=$(git show -s --format=%B) |
| 42 | |
| 43 | if [[ "$COMMIT_MESSAGE" =~ "deploy-scenario:" && "$COMMIT_MESSAGE" =~ "installer-type:" ]]; then |
| 44 | export INSTALLER_TYPE=$(echo "$COMMIT_MESSAGE" | grep '^installer-type:' | cut -d":" -f2 | sed 's/\s*//g') |
| 45 | export DEPLOY_SCENARIO=$(echo "$COMMIT_MESSAGE" | grep '^deploy-scenario:' | cut -d":" -f2 | sed 's/\s*//g') |
| 46 | else |
Fatih Degirmenci | 569dfca | 2019-05-07 11:20:53 +0200 | [diff] [blame^] | 47 | echo "Info: Installer type or deploy scenario is not specified." |
| 48 | echo "Info: Falling back to programmatically determining them." |
Fatih Degirmenci | 7a43976 | 2019-05-07 10:39:31 +0200 | [diff] [blame] | 49 | determine_scenario |
| 50 | fi |
| 51 | } |
| 52 | |
| 53 | # this function will process the changed files to determine the impacted scenario |
| 54 | # if it is no specified by the committer. only one scenario per change should be |
| 55 | # touched. |
| 56 | # TODO: this is not implented yet. |
| 57 | function determine_scenario() { |
Fatih Degirmenci | 569dfca | 2019-05-07 11:20:53 +0200 | [diff] [blame^] | 58 | echo "Info: Processing $GERRIT_PROJECT patchset $GERRIT_REFSPEC" |
Fatih Degirmenci | 7a43976 | 2019-05-07 10:39:31 +0200 | [diff] [blame] | 59 | cd $WORKSPACE |
| 60 | COMMIT_MESSAGE=$(git show -s --format=%B) |
Fatih Degirmenci | 569dfca | 2019-05-07 11:20:53 +0200 | [diff] [blame^] | 61 | echo "Info: Not implemented!" |
Fatih Degirmenci | 7a43976 | 2019-05-07 10:39:31 +0200 | [diff] [blame] | 62 | exit 1 |
| 63 | } |
| 64 | |
Fatih Degirmenci | 569dfca | 2019-05-07 11:20:53 +0200 | [diff] [blame^] | 65 | echo "Info: Determining the impacted scenario and used installer" |
Fatih Degirmenci | 7a43976 | 2019-05-07 10:39:31 +0200 | [diff] [blame] | 66 | |
| 67 | declare -a DEPLOY_SCENARIO |
| 68 | declare -a INSTALLER_TYPE |
| 69 | export PROJECT_GIT_URL=$GIT_BASE_HTTPS/$GERRIT_PROJECT |
| 70 | |
| 71 | override_installer_scenario |
| 72 | |
Fatih Degirmenci | 569dfca | 2019-05-07 11:20:53 +0200 | [diff] [blame^] | 73 | echo "Info: Writing change metadata to $WORKSPACE/change.properties" |
Fatih Degirmenci | fcf1625 | 2019-05-07 11:00:11 +0200 | [diff] [blame] | 74 | cat << EOF > $WORKSPACE/change.properties |
| 75 | PROJECT_GIT_URL=$GIT_BASE_HTTPS/$GERRIT_PROJECT |
| 76 | DEPLOY_SCENARIO=$DEPLOY_SCENARIO |
| 77 | INSTALLER_TYPE=$INSTALLER_TYPE |
| 78 | GERRIT_PATCHSET_REVISION=$GERRIT_PATCHSET_REVISION |
Fatih Degirmenci | 569dfca | 2019-05-07 11:20:53 +0200 | [diff] [blame^] | 79 | GERRIT_REFSPEC=$GERRIT_REFSPEC |
Fatih Degirmenci | fcf1625 | 2019-05-07 11:00:11 +0200 | [diff] [blame] | 80 | EOF |
| 81 | |
Fatih Degirmenci | 569dfca | 2019-05-07 11:20:53 +0200 | [diff] [blame^] | 82 | echo "Info: Content of change.properties" |
Fatih Degirmenci | fcf1625 | 2019-05-07 11:00:11 +0200 | [diff] [blame] | 83 | echo "-------------------------------------------------------------------------" |
| 84 | cat $WORKSPACE/change.properties |
| 85 | echo "-------------------------------------------------------------------------" |
Fatih Degirmenci | 7a43976 | 2019-05-07 10:39:31 +0200 | [diff] [blame] | 86 | |
| 87 | # vim: set ts=2 sw=2 expandtab: |