blob: 7b6fbaaaae855bdbd9c7123820ad45ecd13be644 [file] [log] [blame]
robert.tomczyka9b3ba62019-05-22 18:19:17 +01001#!/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#
22# This script will take the changes that are pushed to Nordix Gerrit and push upstream to Opendaylight
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 Opendaylight Gerrit
26#
27set -o nounset
28set -o pipefail
29
30cd $WORKSPACE
31echo "Retrieving information from commit to push towards Opendaylight"
32project=$(git config --local remote.origin.url | awk -F "29418/opendaylight/" '{print $2}')
33message=$(git show -s --pretty=%B | grep -vi 'Signed-off-by')
34username=$(git show -s --pretty=%an)
35
36pattern=" "
37if [[ "$username" =~ $pattern ]]
38then
39 echo "Incorrect username, use Linux Foundation ID as git user.name when pushing to Nordix"
40 exit 1
41fi
42
43echo "Setting user name and email"
44git config user.email $(git show -s --pretty=%ae)
45git config user.name $username
46
47echo "Checking out branch on master with new changes"
48git reset HEAD~1 --soft
49git checkout -b delivery_branch origin/$BRANCH
50
51git config --get remote.upstream.url
52retVal=$?
53
54if [[ $retVal -eq 0 ]]
55then
56 git remote rm upstream
57 git remote add upstream "ssh://$username@git.opendaylight.org:29418/$project.git"
58else
59 git remote add upstream "ssh://$username@git.opendaylight.org:29418/$project.git"
60fi
61
62echo "Committing changes and pushing upstream"
63git commit -as -m "$message"
64git push upstream HEAD:refs/for/$BRANCH
65
66retVal1=$?
67if [[ $retVal1 -eq 0 ]]
68then
69 echo "Push upstream to Opendaylight succeeded"
70else
71 echo "Push upstream to Opendaylight failed"
72 exit 2
73fi
74
75git checkout $BRANCH
76git branch -D delivery_branch