#!/usr/bin/bash
# load utils
. ./util/utils.sh
. ./util/fileUtils.sh
. ./util/gitUtils.sh
# config directory, file path and branch
########################################
dsrTemplatePath=/TemplatesPath/
mcPath=/RepoPath/
dsrFile=/TemplatesPath/template.json
mcFile=/RepoPath/repoFile.js
dsrReleaseBranch="release/hd231"
mcReleaseBranch="release/hd231"
mcBranch="hd231-leon"
# check the directory and file path set correctly
########################################
if [ -d $dsrTemplatePath ] && [ -d $mcPath ] && [ -f $dsrFile ] && [ -f $mcFile ]
then
echoSuccess "=== Success: Directory and file path set correctly! ==="
else
echoError "=== Error: Please check the directory and file path config and make it set correctly! ==="
exit
fi
# In DSRTemplate repo switch to the right branch and pull the new code
#####################################################
goDirectory "$dsrTemplatePath"
# print repoName
echoSuccess "=== Curent Repo is DSR-templates==="
dsrCurrentBranch=$(getCurrentBranch)
# check repo is clean status before any operation
checkClean "DSR-templates"
# checkout branch and update code
pullCode "$dsrReleaseBranch"
# In mc repo switch to the right branch and sync json content
############################################################
goDirectory "$mcPath"
echoSuccess "=== Curent Repo is mc ==="
mcCurrentBranch=$(getCurrentBranch)
# check release branch
isBranchExist "$mcReleaseBranch"
if [ $? -eq 0 ]
then
# check repo is clean status before any operation
checkClean "mc"
pullCode "$mcReleaseBranch"
else
restoreBranch "$dsrTemplatePath" "$dsrCurrentBranch"
echoError "=== Error: Please check the mc release branch correctly! ==="
exit
fi
# check and merge branch
isBranchExist "$mcBranch"
if [ $? -eq 0 ]
then
mergeBranch "$mcReleaseBranch" "$mcBranch"
checkConflict
else
restoreBranch "$dsrTemplatePath" "$dsrCurrentBranch"
echoError "=== Error: Please check the mc branch correctly! ==="
exit
fi
# get json and sync json
# jsonContent=$(cat $dsrFile)
# echo "export const drawdownFormDefination = $jsonContent" > $mcFile
# unix2dos "$mcFile"
# delete 2 to last line
# read dsrFile and append after the first line
sed -i "
2,\$d
1r $dsrFile
" "$mcFile"
# delete the second line
sed -i '2d' "$mcFile"
# convert the file format from unix to dos
unix2dos "$mcFile"
echoSuccess "=== Sync json Success ==="
# check if have new code
diffContent=$(git diff -- $mcFile)
if [ -z $diffContent ]
then
echoWarning "=== Warning: no code need to commit! ==="
restoreBranch "$mcPath" "$mcCurrentBranch"
restoreBranch "$dsrTemplatePath" "$dsrCurrentBranch"
else
# push code
pushCode "$mcBranch" "$mcFile" "sync mock json"
# restore branch
restoreBranch "$mcPath" "$mcCurrentBranch"
restoreBranch "$dsrTemplatePath" "$dsrCurrentBranch"
# print success info
echoSuccess "=== Success: sync mock json success ==="
fi