Guest User

Untitled

a guest
Jun 22nd, 2018
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. : '
  3.  
  4. goal: install spr-paid-component from appropriate branch of sprinklr-app-client
  5.  
  6. step 0: if current branch name is live then script will exit without doing anything
  7. becuase for live branch, spr-paid-component would have been added as a dependency with proper version number.
  8.  
  9. step 1: Check if branch name as a argument is given or not :
  10. if given :
  11. clone from given branch name
  12.  
  13. step 2: If branch name is not given or branch with given name not exist in sprinklr-app-client:
  14. clone from branch same as current branch name
  15.  
  16. step 3: if branch as current branch name not exist in sprinklr-app-client :
  17. infer branch name with following strategy
  18. if branch name contains "hotfix" word
  19. inferred branch name is live
  20. else if branch name contains "release" word
  21. inferred branch name is master
  22. else
  23. inferred branch name is master
  24. clone from inferred branch
  25.  
  26. '
  27. # for linebreak
  28. br(){
  29. echo ""
  30. }
  31.  
  32. br
  33. echo "============================================================================"
  34. echo "Installing spr-paid-component from appropriate branch of sprinklr-app-client"
  35. echo "============================================================================"
  36.  
  37. url=git@prod-gitlab.sprinklr.com:sprinklr/frontend/sprinklr-app-client.git
  38. nameOfCurrentBranch=$(git branch | grep "*" | awk '{ print $2}')
  39.  
  40. # step 0
  41. if [ "$nameOfCurrentBranch" == "live" ]
  42. then
  43. br
  44. echo "Add spr-paid-component as a dependency in 'neo/package.json' with proper version number, if not added"
  45. exit;
  46. fi
  47.  
  48. clone(){
  49. br
  50. echo "spr-paid-components cloning from branch: $1"
  51. git clone --depth 1 $url -b $1
  52. }
  53.  
  54. # step 3
  55. infere_branch_name(){
  56. br
  57. echo "Inferring branch name from current branch..."
  58. if [[ "$nameOfCurrentBranch" =~ ^hotfix-.*$ ]]
  59. then
  60. inferredBranchName="live"
  61. elif [[ "$nameOfCurrentBranch" =~ ^release-.*$ ]]
  62. then
  63. inferredBranchName="master"
  64. else
  65. inferredBranchName="master"
  66. fi
  67. echo "Inferred branch name is: $inferredBranchName"
  68. }
  69.  
  70. fallback(){
  71. clone $nameOfCurrentBranch || # step 2
  72. {
  73. br
  74. echo "$1 doesn't exist in sprinklr-app-client so trying to infer branch name from current branch"
  75.  
  76. # step 3
  77. infere_branch_name
  78. clone "$inferredBranchName"
  79. }
  80. }
  81.  
  82.  
  83. cd node_modules
  84. rm -rf spr-paid-components
  85. mkdir spr-paid-components
  86. cd spr-paid-components
  87.  
  88.  
  89.  
  90. if [ $# -ne 0 ] # if argument given
  91. then
  92.  
  93. branch=$1 # take branch name from argument
  94.  
  95. clone $branch || # step 1
  96. {
  97. br
  98. echo "Provided branch doesn't exist in sprinklr-app-client so trying to clone from branch name as current branch name"
  99. fallback
  100. }
  101.  
  102. else # if argument not given given
  103.  
  104. br
  105. echo "You haven't provided branch name so trying to clone from branch with name as current branch name"
  106. fallback
  107. fi
  108.  
  109.  
  110. mv sprinklr-app-client/packages/spr-space/* .
  111. rm -rf sprinklr-app-client
Add Comment
Please, Sign In to add comment