#!/bin/bash # repos UPSTREAM_CLONE="git://vxgit.wrs.com/git" # UPSTREAM_PUSH="ssh://vxgit.wrs.com/git" ROOT_REPO=cgcs-root JENKINS_HOST=yow-cgts3-lx.wrs.com # SOURCE_CONTEXT=TC_17.06 # SOURCE_JENKINS_BUILD=TC_17.06_Pull # PREFIX=TC # SW_VERSION=18.03 # JOB=patching USAGE=0 if [ x"$1" = x ] ; then echo "ERROR: You must specify a source context" USAGE=1 fi SOURCE_CONTEXT=$1 if [ x"$2" = x ] ; then echo "ERROR: You must specify a source context" USAGE=1 fi SOURCE_JENKINS_BUILD=$2 if [ x"$3" = x ] ; then echo "ERROR: You must specify a prefix for patch and patch branch names" USAGE=1 fi PREFIX=$3 if [ x"$4" = x ] ; then echo "ERROR: You must specify a sw_version" USAGE=1 fi SW_VERSION=$4 if [ x"$5" = x ] ; then echo "ERROR: You must specify a job directory" USAGE=1 fi JOB=$5 if [ $USAGE -ne 0 ] ; then echo "USAGE: make_patching_branch " echo " e.g. make_patching_branch CGCS_DEV_0007 Secure_Src_Pull_CGCS_DEV_0007 CGCS 14.10 testpatch" exit 1 fi PATCH_BRANCH=$PREFIX"_"$SW_VERSION"_PATCHING" PATCH_TAG0=v$PREFIX"_"$SW_VERSION"_PATCH_0000" MY_LOCAL_DISK=/localdisk/designer/$USER/$JOB MY_REPO=$MY_LOCAL_DISK if [[ "$JOB" = /* ]] then MY_LOCAL_DISK=$JOB MY_REPO=$JOB fi echo "PREFIX=$PREFIX" echo "SW_VERSION=$SW_VERSION" echo "JOB=$JOB" echo "SOURCE_CONTEXT=$SOURCE_CONTEXT" echo "MY_LOCAL_DISK=$MY_LOCAL_DISK" echo "MY_REPO=$MY_REPO" echo "SOURCE_JENKINS_BUILD=$SOURCE_JENKINS_BUILD" echo "PATCH_BRANCH=$PATCH_BRANCH" echo "UPSTREAM_CLONE=$UPSTREAM_CLONE" mkdir -p $MY_LOCAL_DISK if [ $? -ne 0 ] ; then echo "ERROR: failed to create directory '$MY_LOCAL_DISK'" exit 1 fi cd $MY_LOCAL_DISK if [ $? -ne 0 ] ; then echo "ERROR: failed to change to directory '$MY_LOCAL_DISK'" exit 1 fi # Get latest tools if [ ! -d bin ] ; then echo "clone bin" git clone git://git.wrs.com/git/bin else echo "pull bin" cd bin git pull cd $MY_LOCAL_DISK fi export PATH=$MY_REPO/build-tools/branching:$PATH # Create repo mkdir -p $MY_REPO if [ $? -ne 0 ] ; then echo "ERROR: failed to create directory '$MY_REPO'" exit 1 fi chgrp cgts $MY_REPO if [ $? -ne 0 ] ; then echo "ERROR: failed chgrp '$MY_REPO'" exit 1 fi chmod 750 $MY_REPO if [ $? -ne 0 ] ; then echo "ERROR: failed to chmod '$MY_REPO'" exit 1 fi cd $MY_REPO if [ $? -ne 0 ] ; then echo "ERROR: failed to change to directory '$MY_LOCAL_DISK'" exit 1 fi if [ ! -d $ROOT_REPO ] ; then WRGIT_ALL_ADDONS=1 wrgit clone $UPSTREAM_CLONE/$ROOT_REPO $ROOT_REPO $SOURCE_CONTEXT if [ $? -ne 0 ] ; then echo "ERROR: failed to clone from repo '$UPSTREAM_CLONE' with context '$SOURCE_CONTEXT'" exit 1 fi MY_REPO=$MY_REPO/$ROOT_REPO else MY_REPO=$MY_REPO/$ROOT_REPO cd $MY_REPO if [ $? -ne 0 ] ; then echo "ERROR: failed to change to directory '$MY_REPO'" exit 1 fi wrgit checkout $SOURCE_CONTEXT if [ $? -ne 0 ] ; then echo "ERROR: wrgit checkout '$SOURCE_CONTEXT' failed" exit 1 fi wrgit pull if [ $? -ne 0 ] ; then echo "ERROR: wrgit pull failed" exit 1 fi fi cd $MY_REPO if [ $? -ne 0 ] ; then echo "ERROR: failed to change to directory '$MY_REPO'" exit 1 fi git branch | grep $PATCH_BRANCH if [ $? -ne 0 ] ; then # Set context CONTEXT_PATH="/localdisk/designer/jenkins/$SOURCE_JENKINS_BUILD/$ROOT_REPO/CONTEXT" if [ -f $CONTEXT_PATH ]; then cp $CONTEXT_PATH ../ else CONTEXT_PROVIDER=$JENKINS_HOST:$CONTEXT_PATH scp $CONTEXT_PROVIDER ../ if [ $? -ne 0 ] ; then echo "ERROR: failed to obtain context from '$CONTEXT_PROVIDER'" exit 1 fi fi source ../CONTEXT if [ $? -ne 0 ] ; then echo "ERROR: failed to set context" exit 1 fi git branch | grep $PATCH_BRANCH if [ $? -ne 0 ] ; then # create patching branch and tag create_branches_and_tags.sh $PATCH_BRANCH . if [ $? -ne 0 ] ; then echo "ERROR: failed to create branch '$PATCH_BRANCH'" exit 1 fi push_branches_tags.sh $PATCH_BRANCH if [ $? -ne 0 ] ; then echo "ERROR: failed to push branch '$PATCH_BRANCH' to '$UPSTREAM_PUSH'" exit 1 fi fi else wrgit checkout $PATCH_BRANCH if [ $? -ne 0 ] ; then echo "ERROR: wrgit checkout '$PATCH_BRANCH' failed" exit 1 fi fi git tag | grep $PATCH_TAG0 if [ $? -ne 0 ] ; then create_tags.sh $PATCH_TAG0 if [ $? -ne 0 ] ; then echo "ERROR: failed to create tag '$PATCH_TAG0'" exit 1 fi push_tags.sh $PATCH_TAG0 if [ $? -ne 0 ] ; then echo "ERROR: failed to push branch '$PATCH_BRANCH' to '$UPSTREAM_PUSH'" exit 1 fi fi