-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforward.sh
More file actions
107 lines (94 loc) · 3.36 KB
/
Copy pathforward.sh
File metadata and controls
107 lines (94 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
# community master repo
community_master_path=$HOME/work/community-master
# calling directory
curr_dir=$(pwd)
# community path for current branch
community_path="${curr_dir/enterprise/community}"
# enterprise path for current branch
enterprise_path="${curr_dir/community/enterprise}"
if [ $# -ne 1 ]
then
echo "usage: bash forward.sh <forward_branch>"
echo "example: bash forward.sh saas-18.4"
exit 0
fi
# Input verification
target_branch=$1
# Verify target branch exists
cd $community_master_path
existing_versions=$(git ls-remote --heads origin | awk -F'/' '{print $NF}')
if ! echo "$existing_versions" | grep -q "^$target_branch$"; then
echo -e "\e[31mError: '$target_branch' is not a valid target!\e[0m"
exit 1
fi
# Verify target branch is a different version
cd $curr_dir
current_version=$( git rev-parse --abbrev-ref --symbolic-full-name @{u} | sed 's/^\(dev\|origin\)\///' )
if [[ "$current_version" == "$target_branch"* ]]; then
echo -e "\e[31mError: current version is already '$target_branch'!\e[0m"
exit 1
fi
# Community side
cd $community_path
fw_branch=false
current_branch=$(git branch --show-current)
# Check whether current branch is already a FW
if [[ "$current_branch" == *"-fw" ]]; then
# Remove anything after the first decimal number, reverse string, remove anything before the second "-", reverse again.
# This gives the original branch name (before the previous FW).
# eg. saas-18.2-18.0-opw-4865082-reference_all_split_mo_in_picking-drod-457866-fw => 18.0-opw-4865082-reference_all_split_mo_in_picking-drod
current_branch=$( echo $current_branch | sed -E 's/^[^-]*-([0-9]+(\.[0-9]+)?)-(.*)/\3/' | rev | cut -d'-' -f3- | rev )
fi
# Find the FW branch on the remote
fw_branch=$(git branch -r | grep "$target_branch-$current_branch" | sed 's/^[[:space:]]*//' | sed 's|dev/||')
if [ $fw_branch ]; then
git fetch dev $fw_branch > /dev/null
git switch $fw_branch > /dev/null
else
echo -e "\e[31mCould not find a community FW!\e[0m"
echo "Defaulting to: $target_branch"
echo ""
fw_branch=$target_branch
git switch $fw_branch > /dev/null
git pull > /dev/null
fi
echo ""
echo -e "\e[32mCommunity done!\e[0m"
echo "Switched to: $fw_branch"
echo ""
# Enterprise side
cd $enterprise_path
fw_branch=false
current_branch=$(git branch --show-current)
# Check whether current branch is already a FW
if [[ "$current_branch" == *"-fw" ]]; then
current_branch=$( echo $current_branch | sed -E 's/^[^-]*-([0-9]+(\.[0-9]+)?)-(.*)/\3/' | rev | cut -d'-' -f3- | rev )
fi
# Find the FW branch on the remote
fw_branch=$(git branch -r | grep "$target_branch-$current_branch" | sed 's/^[[:space:]]*//' | sed 's|dev/||')
if [ $fw_branch ]; then
git fetch dev $fw_branch > /dev/null
git switch $fw_branch > /dev/null
else
echo -e "\e[31mCould not find an enterprise FW!\e[0m"
echo "Defaulting to: $target_branch"
echo ""
fw_branch=$target_branch
git switch $fw_branch > /dev/null
git pull > /dev/null
fi
echo ""
echo -e "\e[32mEnterprise done!\e[0m"
echo "Switched to: $fw_branch"
echo ""
# Update workspace configuration
cd $community_path
db_name_current=$(echo ${current_branch#saas-} | cut -d'-' -f1 | tr -d '.')
db_name_new=$(echo ${target_branch#saas-} | tr -d '.')
loc=$community_path/$(echo ${community_path#*opw-} | rev | cut -d'-' -f2- | rev).code-workspace
sed -i "s|$db_name_current|$db_name_new|g" $loc
# All done
cd $curr_dir
echo -e "\e[32mDone!\e[0m"
exit 0