forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmark-new-version.sh
executable file
·164 lines (139 loc) · 6.87 KB
/
mark-new-version.sh
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
#!/bin/bash
# Copyright 2014 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Bumps the version number by creating a couple of commits.
set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
NEW_VERSION=${1-}
fetch_url=$(git remote -v | grep GoogleCloudPlatform/kubernetes.git | grep fetch | awk '{ print $2 }')
if ! push_url=$(git remote -v | grep GoogleCloudPlatform/kubernetes.git | grep push | awk '{ print $2 }'); then
push_url="https://github.com/GoogleCloudPlatform/kubernetes.git"
fi
fetch_remote=$(git remote -v | grep GoogleCloudPlatform/kubernetes.git | grep fetch | awk '{ print $1 }')
VERSION_REGEX="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"
[[ ${NEW_VERSION} =~ $VERSION_REGEX ]] || {
echo "!!! You must specify the version in the form of '$VERSION_REGEX'" >&2
exit 1
}
VERSION_MAJOR="${BASH_REMATCH[1]}"
VERSION_MINOR="${BASH_REMATCH[2]}"
VERSION_PATCH="${BASH_REMATCH[3]}"
if ! git diff-index --quiet --cached HEAD; then
echo "!!! You must not have any changes in your index when running this command"
exit 1
fi
if ! git diff-files --quiet pkg/version/base.go; then
echo "!!! You have changes in 'pkg/version/base.go' already."
exit 1
fi
release_branch="release-${VERSION_MAJOR}.${VERSION_MINOR}"
current_branch=$(git rev-parse --abbrev-ref HEAD)
if [[ "${VERSION_PATCH}" != "0" ]]; then
# sorry, no going back in time, pull latest from upstream
git remote update > /dev/null 2>&1
if git ls-remote --tags --exit-code ${fetch_url} refs/tags/${NEW_VERSION} > /dev/null; then
echo "!!! You are trying to tag ${NEW_VERSION} but it already exists. Stop it!"
exit 1
fi
last_version="v${VERSION_MAJOR}.${VERSION_MINOR}.$((VERSION_PATCH-1))"
if ! git ls-remote --tags --exit-code ${fetch_url} refs/tags/${last_version} > /dev/null; then
echo "!!! You are trying to tag ${NEW_VERSION} but ${last_version} doesn't even exist!"
exit 1
fi
# this is rather magic. This checks that HEAD is a descendant of the github branch release-x.y
branches=$(git branch --contains $(git ls-remote --heads ${fetch_url} refs/heads/${release_branch} | cut -f1) ${current_branch})
if [[ $? -ne 0 ]]; then
echo "!!! git failed, I dunno...."
exit 1
fi
if [[ ${branches} != "* ${current_branch}" ]]; then
echo "!!! You are trying to tag to an existing minor release but branch: ${release_branch} is not an ancestor of ${current_branch}"
exit 1
fi
fi
SED=sed
if which gsed &>/dev/null; then
SED=gsed
fi
if ! ("$SED" --version 2>&1 | grep -q GNU); then
echo "!!! GNU sed is required. If on OS X, use 'brew install gnu-sed'."
fi
VERSION_FILE="${KUBE_ROOT}/pkg/version/base.go"
GIT_MINOR="${VERSION_MINOR}.${VERSION_PATCH}"
echo "+++ Updating to ${NEW_VERSION}"
"$SED" -r -i -e "s/gitMajor\s+string = \"[^\"]*\"/gitMajor string = \"${VERSION_MAJOR}\"/" "${VERSION_FILE}"
"$SED" -r -i -e "s/gitMinor\s+string = \"[^\"]*\"/gitMinor string = \"${GIT_MINOR}\"/" "${VERSION_FILE}"
"$SED" -r -i -e "s/gitVersion\s+string = \"[^\"]*\"/gitVersion string = \"$NEW_VERSION\"/" "${VERSION_FILE}"
gofmt -s -w "${VERSION_FILE}"
echo "+++ Committing version change"
git add "${VERSION_FILE}"
git commit -m "Kubernetes version $NEW_VERSION"
echo "+++ Tagging version"
git tag -a -m "Kubernetes version $NEW_VERSION" "${NEW_VERSION}"
echo "+++ Updating to ${NEW_VERSION}-dev"
"$SED" -r -i -e "s/gitMajor\s+string = \"[^\"]*\"/gitMajor string = \"${VERSION_MAJOR}\"/" "${VERSION_FILE}"
"$SED" -r -i -e "s/gitMinor\s+string = \"[^\"]*\"/gitMinor string = \"${GIT_MINOR}\+\"/" "${VERSION_FILE}"
"$SED" -r -i -e "s/gitVersion\s+string = \"[^\"]*\"/gitVersion string = \"$NEW_VERSION-dev\"/" "${VERSION_FILE}"
gofmt -s -w "${VERSION_FILE}"
echo "+++ Committing version change"
git add "${VERSION_FILE}"
git commit -m "Kubernetes version ${NEW_VERSION}-dev"
echo ""
echo "Success you must now:"
echo ""
echo "- Push the tag:"
echo " git push ${push_url} v${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}"
echo " - Please note you are pushing the tag live BEFORE your PRs."
echo " You need this so the builds pick up the right tag info."
echo " If something goes wrong further down please fix the tag!"
echo " Either delete this tag and give up, fix the tag before your next PR,"
echo " or find someone who can help solve the tag problem!"
echo ""
if [[ "${VERSION_PATCH}" == "0" ]]; then
echo "- Send branch: ${current_branch} as a PR to master"
echo "- Get someone to review and merge that PR"
echo "- Push the new release branch"
echo " git push ${push_url} ${current_branch}:${release_branch}"
else
echo "- Send branch: ${current_branch} as a PR to ${release_branch}"
echo "- Get someone to review and merge that PR"
echo ""
echo "Now you need to back merge the release branch into master. This should"
echo "only be done if you are committing to the latest release branch. If the"
echo "latest release branch is, for example, release-0.10 and you are adding"
echo "a commit to release-0.9, you may skip the remaining instructions"
echo ""
echo "We do this back merge so that master will always show the latest version."
echo "The version in master would, for exampe show v0.10.2+ instead of v0.10.0+"
echo "It is not enough to just edit the version file in pkg/version/base.go in a"
echo "seperate PR. Doing it this way means that git will see the tag you just"
echo "pushed as an ancestor of master, even though the tag is on on a release"
echo "branch. The tag will thus be found by tools like git describe"
echo ""
echo "- Update so you see that merge in ${fetch_remote}"
echo " git remote update"
echo "- Create and check out a new branch based on master"
echo " git checkout -b merge-${release_branch}-to-master ${fetch_remote}/master"
echo "- Merge the ${release_branch} into your merge-${release_branch}-to-master branch:"
echo " git merge -s recursive -X ours ${fetch_remote}/${release_branch}"
echo " - It's possible you have merge conflicts that weren't resolved by the merge strategy."
echo " - You will almost always want to take what is in HEAD"
echo " - If you are not SURE how to solve these correctly, ask for help."
echo " - It is possible to break other people's work if you didn't understand why"
echo " the conflict happened and the correct way to solve it."
echo "- Send merge-${release_branch}-to-master as a PR to master"
echo "- Take the afternoon off"
fi