-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlt_rebase_merge.sh
More file actions
executable file
·176 lines (152 loc) · 4.88 KB
/
lt_rebase_merge.sh
File metadata and controls
executable file
·176 lines (152 loc) · 4.88 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/bin/bash
set -x
PR_BRANCH=$1
TARGET_BRANCH=$2
NEXT_BRANCH="$2-next"
NVR_REGEX="[0-9]*\.[0-9]*\.[0-9]*"
if [ -z "$PR_BRANCH" ] || [ -z "$TARGET_BRANCH" ]; then
echo "Usage: $0 <pr_branch> <target_branch>"
exit 1
fi
# Check if all branches exist
git show-ref --verify --quiet refs/heads/"${PR_BRANCH}"
if [ $? -ne 0 ]; then
echo "Branch ${PR_BRANCH} does not exist."
exit 1
fi
git show-ref --verify --quiet refs/heads/"${TARGET_BRANCH}"
if [ $? -ne 0 ]; then
echo "Branch ${TARGET_BRANCH} does not exist."
exit 1
fi
git show-ref --verify --quiet refs/heads/"${NEXT_BRANCH}"
if [ $? -ne 0 ] ; then
echo "Branch ${NEXT_BRANCH} does not exist."
exit 1
fi
#collect all static data fire before making alterations to the local and remote repositories
PAST_VERSION=$(git describe --tags --abbrev=0 "${TARGET_BRANCH}" | awk -F '-' '{print $2}')
if [ -z "$PAST_VERSION" ]; then
echo "Failed to get a CIQ Tag from ${TARGET_BRANCH}."
echo "LastTag: $(git describe --tags --abbrev=0 "${TARGET_BRANCH}")"
exit 1
fi
# Check if PAST_VERSION matches the regex
if ! [[ $PAST_VERSION =~ $NVR_REGEX ]]; then # check if PAST_VERSION matches the regex
echo "PAST_VERSION: ${PAST_VERSION} does not match the regex ${NVR_REGEX}"
exit 1
fi
PAST_VERSION_BRANCH="ciq-${PAST_VERSION}"
echo "PAST_VERSION: $PAST_VERSION"
echo "PAST_VERSION_BRANCH: $PAST_VERSION_BRANCH"
NEW_GKH_TAG=$(git describe --tags --abbrev=0 "${PR_BRANCH}" | sed 's/^.//g')
if [ -z "$NEW_GKH_TAG" ]; then
echo "Failed to get a GKH Tag from ${PR_BRANCH}."
echo "LastTag: $(git describe --tags --abbrev=0 "${PR_BRANCH}")"
exit 1
fi
# Check if NEW_GKH_TAG matches the regex
if ! [[ $NEW_GKH_TAG =~ $NVR_REGEX ]]; then # check if NEW_GKH_TAG matches the regex
echo "NEW_GKH_TAG: ${NEW_GKH_TAG} does not match the regex ${NVR_REGEX}"
exit 1
fi
NEW_CIQ_TAG="ciq_kernel-${NEW_GKH_TAG}-1"
# merge PR branch into next branch
set +x
echo "Commands expected to run (This is in the event it fails during the run)"
echo "git checkout \"${NEXT_BRANCH}\""
echo "git pull origin \"${NEXT_BRANCH}\""
echo "git merge --ff-only \"${PR_BRANCH}\""
echo "git push origin \"${NEXT_BRANCH}\""
echo "git branch -m \"${TARGET_BRANCH}\" \"${PAST_VERSION_BRANCH}\""
echo "git push origin :\"${TARGET_BRANCH}\" \"${PAST_VERSION_BRANCH}\""
echo "git push origin -u \"${PAST_VERSION_BRANCH}\""
echo "git branch -m \"${NEXT_BRANCH}\" \"${TARGET_BRANCH}\""
echo "git push origin :\"${NEXT_BRANCH}\" \"${TARGET_BRANCH}\""
echo "git push origin -u \"${TARGET_BRANCH}\""
echo "git tag \"${NEW_CIQ_TAG}\" \"${TARGET_BRANCH}\""
echo "git push origin \"${NEW_CIQ_TAG}\""
echo "git checkout $NEXT_BRANCH"
git checkout "${NEXT_BRANCH}"
if [ $? -ne 0 ]; then
echo "Failed to checkout ${NEXT_BRANCH}."
exit 1
fi
echo "git pull origin $NEXT_BRANCH"
git pull origin "${NEXT_BRANCH}"
if [ $? -ne 0 ]; then
echo "Failed to pull ${NEXT_BRANCH}."
exit 1
fi
echo "git merge --ff-only ${PR_BRANCH}"
git merge --ff-only "${PR_BRANCH}"
if [ $? -ne 0 ]; then
echo "Failed to merge ${PR_BRANCH} into ${NEXT_BRANCH}."
exit 1
fi
echo "git push origin $NEXT_BRANCH"
git push origin "${NEXT_BRANCH}"
if [ $? -ne 0 ]; then
echo "Failed to push ${NEXT_BRANCH}."
exit 1
fi
echo "Delete PR branch ${PR_BRANCH} locally and remotely"
echo "git push origin :${PR_BRANCH}"
git push origin :"${PR_BRANCH}"
if [ $? -ne 0 ]; then
echo "Failed to delete ${PR_BRANCH} remotely."
exit 1
fi
git branch -d "${PR_BRANCH}"
if [ $? -ne 0 ]; then
echo "Failed to delete ${PR_BRANCH} locally."
exit 1
fi
echo "git branch -m $TARGET_BRANCH $PAST_VERSION_BRANCH"
git branch -m "${TARGET_BRANCH}" "${PAST_VERSION_BRANCH}"
if [ $? -ne 0 ]; then
echo "Failed to rename ${TARGET_BRANCH} to ${PAST_VERSION_BRANCH}."
exit 1
fi
echo "git push origin :$TARGET_BRANCH $PAST_VERSION_BRANCH"
git push origin :"${TARGET_BRANCH}" "${PAST_VERSION_BRANCH}"
if [ $? -ne 0 ]; then
echo "Failed to delete ${TARGET_BRANCH}."
exit 1
fi
echo "git push origin -u $PAST_VERSION_BRANCH"
git push origin -u "${PAST_VERSION_BRANCH}"
if [ $? -ne 0 ]; then
echo "Failed to push ${PAST_VERSION_BRANCH}."
exit 1
fi
echo "git branch -m $NEXT_BRANCH $TARGET_BRANCH"
git branch -m "${NEXT_BRANCH}" "${TARGET_BRANCH}"
if [ $? -ne 0 ]; then
echo "Failed to rename ${NEXT_BRANCH} to ${TARGET_BRANCH}."
exit 1
fi
echo "git push origin :$NEXT_BRANCH $TARGET_BRANCH"
git push origin :"${NEXT_BRANCH}" "${TARGET_BRANCH}"
if [ $? -ne 0 ]; then
echo "Failed to delete ${NEXT_BRANCH}."
exit 1
fi
echo "git push origin -u $TARGET_BRANCH"
git push origin -u "${TARGET_BRANCH}"
if [ $? -ne 0 ]; then
echo "Failed to push ${TARGET_BRANCH}."
exit 1
fi
echo "git tag $NEW_CIQ_TAG $TARGET_BRANCH"
git tag "${NEW_CIQ_TAG}" "${TARGET_BRANCH}"
if [ $? -ne 0 ]; then
echo "Failed to tag ${TARGET_BRANCH} with ${NEW_CIQ_TAG}."
exit 1
fi
echo "git push origin $NEW_CIQ_TAG"
git push origin "${NEW_CIQ_TAG}"
if [ $? -ne 0 ]; then
echo "Failed to push ${NEW_CIQ_TAG}."
exit 1
fi