blob: 3eedac2cb1329c42697df990e8b0399b09d6ed80 [file] [log] [blame]
econwarf661d052019-01-07 14:50:03 +00001#!/bin/bash
Conor Wardd48d8352019-01-02 15:54:28 +00002
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#
econwarf661d052019-01-07 14:50:03 +000027set -o errexit
28set -o nounset
29set -o pipefail
Conor Wardd48d8352019-01-02 15:54:28 +000030
31cd $WORKSPACE
econwarf661d052019-01-07 14:50:03 +000032echo "Retrieving information from commit to push towards ONAP"
Conor Wardd48d8352019-01-02 15:54:28 +000033project=$(git config --local remote.origin.url | awk -F "29418/" '{print $2}')
34message=$(git show -s --pretty=%B | grep -vi 'Signed-off-by')
35username=$(git show -s --pretty=%an)
36
37pattern=" "
38if [[ "$username" =~ $pattern ]]
39then
40 echo "Incorrect username, use Linux Foundation ID as git user.name when pushing to Nordix"
41 exit 1
42fi
43
econwarf661d052019-01-07 14:50:03 +000044echo "Setting user name and email"
Conor Wardd48d8352019-01-02 15:54:28 +000045git config user.email $(git show -s --pretty=%ae)
46git config user.name $username
47
econwarf661d052019-01-07 14:50:03 +000048echo "Checking out branch on master with new changes"
Conor Wardd48d8352019-01-02 15:54:28 +000049git reset HEAD~1
50git checkout -b delivery_branch origin/master
51
econwar2de41752019-01-07 14:17:11 +000052echo '[remote "upstream"]' >> $WORKSPACE/.git/config
53echo " url = ssh://$username@gerrit.onap.org:29418/$project.git" >> $WORKSPACE/.git/config
54echo " fetch = +refs/heads/*:refs/remotes/upstream/*" >> $WORKSPACE/.git/config
Conor Wardd48d8352019-01-02 15:54:28 +000055
econwarf661d052019-01-07 14:50:03 +000056echo "Committing changes and pushing upstream"
Conor Wardd48d8352019-01-02 15:54:28 +000057git commit -as -m "$message"
Conor Wardd48d8352019-01-02 15:54:28 +000058git push upstream HEAD:refs/for/master
econwarf661d052019-01-07 14:50:03 +000059
Conor Wardd48d8352019-01-02 15:54:28 +000060retVal=$?
61if [[ $retVal -eq 0 ]]
62then
63 echo "Push upstream to ONAP succeeded"
64else
65 echo "Push upstream to ONAP failed"
66 exit 2
67fi