econwar | f661d05 | 2019-01-07 14:50:03 +0000 | [diff] [blame] | 1 | #!/bin/bash |
Conor Ward | d48d835 | 2019-01-02 15:54:28 +0000 | [diff] [blame] | 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 | # |
| 22 | # This script will take the changes that are pushed to Nordix Gerrit and push upstream to ONAP |
| 23 | # Pre-requisites for script to run successfully: |
| 24 | # - Author name in Nordix Gerrit equals LFID i.e. need to run "git config --global user.name <LFID>" |
| 25 | # - infra public key on build server needs to be added to your users SSH Public Keys in ONAP Gerrit |
| 26 | # |
econwar | f661d05 | 2019-01-07 14:50:03 +0000 | [diff] [blame] | 27 | set -o nounset |
| 28 | set -o pipefail |
Conor Ward | d48d835 | 2019-01-02 15:54:28 +0000 | [diff] [blame] | 29 | |
| 30 | cd $WORKSPACE |
econwar | f661d05 | 2019-01-07 14:50:03 +0000 | [diff] [blame] | 31 | echo "Retrieving information from commit to push towards ONAP" |
Conor Ward | d48d835 | 2019-01-02 15:54:28 +0000 | [diff] [blame] | 32 | project=$(git config --local remote.origin.url | awk -F "29418/" '{print $2}') |
| 33 | message=$(git show -s --pretty=%B | grep -vi 'Signed-off-by') |
| 34 | username=$(git show -s --pretty=%an) |
| 35 | |
| 36 | pattern=" " |
| 37 | if [[ "$username" =~ $pattern ]] |
| 38 | then |
| 39 | echo "Incorrect username, use Linux Foundation ID as git user.name when pushing to Nordix" |
| 40 | exit 1 |
| 41 | fi |
| 42 | |
econwar | f661d05 | 2019-01-07 14:50:03 +0000 | [diff] [blame] | 43 | echo "Setting user name and email" |
Conor Ward | d48d835 | 2019-01-02 15:54:28 +0000 | [diff] [blame] | 44 | git config user.email $(git show -s --pretty=%ae) |
| 45 | git config user.name $username |
| 46 | |
econwar | f661d05 | 2019-01-07 14:50:03 +0000 | [diff] [blame] | 47 | echo "Checking out branch on master with new changes" |
econwar | 021e603 | 2019-01-10 09:39:30 +0000 | [diff] [blame] | 48 | git reset HEAD~1 --soft |
econwar | c79d307 | 2019-02-11 11:18:40 +0000 | [diff] [blame] | 49 | git checkout -b delivery_branch origin/$BRANCH |
Conor Ward | d48d835 | 2019-01-02 15:54:28 +0000 | [diff] [blame] | 50 | |
econwar | 021e603 | 2019-01-10 09:39:30 +0000 | [diff] [blame] | 51 | git config --get remote.upstream.url |
| 52 | retVal=$? |
| 53 | |
| 54 | if [[ $retVal -eq 0 ]] |
| 55 | then |
| 56 | git remote rm upstream |
| 57 | git remote add upstream "ssh://$username@gerrit.onap.org:29418/$project.git" |
| 58 | else |
| 59 | git remote add upstream "ssh://$username@gerrit.onap.org:29418/$project.git" |
| 60 | fi |
Conor Ward | d48d835 | 2019-01-02 15:54:28 +0000 | [diff] [blame] | 61 | |
econwar | f661d05 | 2019-01-07 14:50:03 +0000 | [diff] [blame] | 62 | echo "Committing changes and pushing upstream" |
Conor Ward | d48d835 | 2019-01-02 15:54:28 +0000 | [diff] [blame] | 63 | git commit -as -m "$message" |
econwar | a522790 | 2019-01-17 17:00:19 +0000 | [diff] [blame] | 64 | git push upstream HEAD:refs/for/$BRANCH |
econwar | f661d05 | 2019-01-07 14:50:03 +0000 | [diff] [blame] | 65 | |
econwar | 021e603 | 2019-01-10 09:39:30 +0000 | [diff] [blame] | 66 | retVal1=$? |
| 67 | if [[ $retVal1 -eq 0 ]] |
Conor Ward | d48d835 | 2019-01-02 15:54:28 +0000 | [diff] [blame] | 68 | then |
| 69 | echo "Push upstream to ONAP succeeded" |
| 70 | else |
| 71 | echo "Push upstream to ONAP failed" |
| 72 | exit 2 |
| 73 | fi |
econwar | 021e603 | 2019-01-10 09:39:30 +0000 | [diff] [blame] | 74 | |
| 75 | git checkout $BRANCH |
| 76 | git branch -D delivery_branch |