-
Notifications
You must be signed in to change notification settings - Fork 61
/
autoReleaseBranch
executable file
·127 lines (102 loc) · 2.92 KB
/
autoReleaseBranch
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
# usage
if [ $# != 3 ] ; then
echo -e "Usage: ${0} <major|minor|update> <source_branch> <release_branch>"
exit 1
fi
current_branch="$(pwb)"
updateType="${1}"
source_branch="${2}"
branch="${3}"
echo "INFO: Fetching..."
if ! git fetch --all --tags ; then
echo "ERROR: Failed to fetch all tags!"
exit 1
fi
# cleanup trap
function cleanup {
echo "INFO: Checking out previous ${branch}..."
git checkout "${current_branch}"
}
trap cleanup EXIT
echo
if [ "${source_branch}" == "${branch}" ] ; then
echo "INFO: Already on branch ${source_branch}..."
else
echo "INFO: Checking out ${source_branch}..."
if ! git checkout "${source_branch}" ; then
echo "ERROR: Failed to checkout branch ${source_branch}"
exit 1
fi
echo "INFO: Rebasing origin/${source_branch}..."
if ! git rebase "origin/${source_branch}" ; then
echo "ERROR: Failed to rebase ${source_branch}!"
exit 1
fi
fi
echo
echo "INFO: Checking out target ${branch}..."
if ! git checkout "${branch}" ; then
echo "WARN: Failed to checkout target branch ${branch}"
echo -e "WARN: Do you want to create target branch ${branch} from branch ${source_branch}? [Y/n]"
read a
if [[ "${a}" != "" ]] && [[ "${a}" != "y" ]] ; then
exit 0
fi
if ! git checkout -b "${branch}" "${source_branch}" ; then
echo "ERROR: Failed to create new branch ${branch}"
exit 1
fi
echo "INFO: Pushing new branch to origin..."
if ! git push --set-upstream origin "${branch}" ; then
echo "ERROR: Failed to push new branch ${branch} to origin!"
exit 1
fi
fi
# rebasing
echo "INFO: Rebasing origin/${branch}..."
if ! git rebase "origin/${branch}" ; then
echo "ERROR: Failed to rebase ${branch}!"
exit 1
fi
# merge branchs
if [ "${source_branch}" == "${branch}" ] ; then
echo "INFO: Source and release branch are the same not merging: ${source_branch}"
else
echo "INFO: Merging ${source_branch}..."
if ! GIT_EDITOR=: git merge "${source_branch}" ; then
echo "ERROR: Failed to prepare repo for auto release!"
exit 1
fi
fi
# have user update pom.xml if necessary
echo -n "INFO: Merge complete. Please update versions in pom.xml: <enter>"
read a
if ! editor ./pom.xml ; then
echo "ERROR: pom.xml failed"
exit 1
fi
# commit changes
if output=$(git status --porcelain) && [ -z "$output" ]; then
echo "INFO: No changes in pom.xml, no commit needed."
else
git add pom.xml
if ! git commit -m "[Project] Update pom.xml in auto release" ; then
echo "ERROR: Failed to commit changed pom.xml"
exit 1
fi
fi
# push changes to origin
echo "INFO: Pushing ${branch} to origin..."
if ! git push origin "${branch}" ; then
echo "ERROR: Failed to push ${branch} to origin."
exit 1
fi
# now perform autoRelease
echo "INFO: Starting auto release on branch ${branch}..."
if ! autoRelease "${updateType}" "${branch}" ; then
echo "ERROR: Failed to perform auto release!"
exit 1
fi
echo "INFO: Performed auto-release on ${branch}"
exit 0