Commit 8a670837 authored by machenbach's avatar machenbach Committed by Commit bot

Calculate new version based on latest tag when pushing.

BUG=chromium:451357
TBR=tandrii@chromium.org
LOG=n
NOTRY=true

Review URL: https://codereview.chromium.org/868693002

Cr-Commit-Position: refs/heads/master@{#26243}
parent 845072e6
...@@ -606,6 +606,16 @@ class Step(GitRecipesMixin): ...@@ -606,6 +606,16 @@ class Step(GitRecipesMixin):
self[prefix + "build"], self[prefix + "build"],
self[prefix + "patch"]]) self[prefix + "patch"]])
def StoreVersion(self, version, prefix):
version_parts = version.split(".")
if len(version_parts) == 3:
version_parts.append("0")
major, minor, build, patch = version_parts
self[prefix + "major"] = major
self[prefix + "minor"] = minor
self[prefix + "build"] = build
self[prefix + "patch"] = patch
def SetVersion(self, version_file, prefix): def SetVersion(self, version_file, prefix):
output = "" output = ""
for line in FileToText(version_file).splitlines(): for line in FileToText(version_file).splitlines():
......
...@@ -36,6 +36,7 @@ from common_includes import * ...@@ -36,6 +36,7 @@ from common_includes import *
PUSH_MSG_GIT_SUFFIX = " (based on %s)" PUSH_MSG_GIT_SUFFIX = " (based on %s)"
PUSH_MSG_GIT_RE = re.compile(r".* \(based on (?P<git_rev>[a-fA-F0-9]+)\)$") PUSH_MSG_GIT_RE = re.compile(r".* \(based on (?P<git_rev>[a-fA-F0-9]+)\)$")
VERSION_RE = re.compile(r"^\d+\.\d+\.\d+(?:\.\d+)?$")
class Preparation(Step): class Preparation(Step):
MESSAGE = "Preparation." MESSAGE = "Preparation."
...@@ -44,6 +45,9 @@ class Preparation(Step): ...@@ -44,6 +45,9 @@ class Preparation(Step):
self.InitialEnvironmentChecks(self.default_cwd) self.InitialEnvironmentChecks(self.default_cwd)
self.CommonPrepare() self.CommonPrepare()
# Make sure tags are fetched.
self.Git("fetch origin +refs/tags/*:refs/tags/*")
if(self["current_branch"] == self.Config("TRUNKBRANCH") if(self["current_branch"] == self.Config("TRUNKBRANCH")
or self["current_branch"] == self.Config("BRANCHNAME")): or self["current_branch"] == self.Config("BRANCHNAME")):
print "Warning: Script started on branch %s" % self["current_branch"] print "Warning: Script started on branch %s" % self["current_branch"]
...@@ -109,55 +113,37 @@ class DetectLastPush(Step): ...@@ -109,55 +113,37 @@ class DetectLastPush(Step):
self["last_push_bleeding_edge"] = last_push_bleeding_edge self["last_push_bleeding_edge"] = last_push_bleeding_edge
# TODO(machenbach): Code similarities with bump_up_version.py. Merge after class GetLatestVersion(Step):
# turning this script into a pure git script. MESSAGE = "Get latest version from tags."
class GetCurrentBleedingEdgeVersion(Step):
MESSAGE = "Get latest bleeding edge version."
def RunStep(self): def RunStep(self):
versions = sorted(filter(VERSION_RE.match, self.vc.GetTags()),
key=SortingKey, reverse=True)
self.StoreVersion(versions[0], "latest_")
self["latest_version"] = self.ArrayToVersion("latest_")
# The version file on master can be used to bump up major/minor at
# branch time.
self.GitCheckoutFile(VERSION_FILE, self.vc.RemoteMasterBranch()) self.GitCheckoutFile(VERSION_FILE, self.vc.RemoteMasterBranch())
self.ReadAndPersistVersion("master_")
self["master_version"] = self.ArrayToVersion("master_")
# Store latest version. if SortingKey(self["master_version"]) > SortingKey(self["latest_version"]):
self.ReadAndPersistVersion("latest_") self["latest_version"] = self["master_version"]
self["latest_version"] = self.ArrayToVersion("latest_") self.StoreVersion(self["latest_version"], "latest_")
print "Bleeding edge version: %s" % self["latest_version"]
print "Determined latest version %s" % self["latest_version"]
class IncrementVersion(Step): class IncrementVersion(Step):
MESSAGE = "Increment version number." MESSAGE = "Increment version number."
def RunStep(self): def RunStep(self):
# Retrieve current version from last trunk push.
self.GitCheckoutFile(VERSION_FILE, self["last_push_trunk"])
self.ReadAndPersistVersion()
self["trunk_version"] = self.ArrayToVersion("")
if self["latest_build"] == "9999": # pragma: no cover
# If version control on bleeding edge was switched off, just use the last
# trunk version.
self["latest_version"] = self["trunk_version"]
if SortingKey(self["trunk_version"]) < SortingKey(self["latest_version"]):
# If the version on bleeding_edge is newer than on trunk, use it.
self.GitCheckoutFile(VERSION_FILE, self.vc.RemoteMasterBranch())
self.ReadAndPersistVersion()
if self.Confirm(("Automatically increment BUILD_NUMBER? (Saying 'n' will "
"fire up your EDITOR on %s so you can make arbitrary "
"changes. When you're done, save the file and exit your "
"EDITOR.)" % VERSION_FILE)):
text = FileToText(os.path.join(self.default_cwd, VERSION_FILE))
text = MSub(r"(?<=#define BUILD_NUMBER)(?P<space>\s+)\d*$",
r"\g<space>%s" % str(int(self["build"]) + 1),
text)
TextToFile(text, os.path.join(self.default_cwd, VERSION_FILE))
else:
self.Editor(os.path.join(self.default_cwd, VERSION_FILE))
# Variables prefixed with 'new_' contain the new version numbers for the # Variables prefixed with 'new_' contain the new version numbers for the
# ongoing trunk push. # ongoing trunk push.
self.ReadAndPersistVersion("new_") self["new_major"] = self["latest_major"]
self["new_minor"] = self["latest_minor"]
self["new_build"] = str(int(self["latest_build"]) + 1)
# Make sure patch level is 0 in a new push. # Make sure patch level is 0 in a new push.
self["new_patch"] = "0" self["new_patch"] = "0"
...@@ -419,7 +405,7 @@ class PushToTrunk(ScriptsBase): ...@@ -419,7 +405,7 @@ class PushToTrunk(ScriptsBase):
FreshBranch, FreshBranch,
PreparePushRevision, PreparePushRevision,
DetectLastPush, DetectLastPush,
GetCurrentBleedingEdgeVersion, GetLatestVersion,
IncrementVersion, IncrementVersion,
PrepareChangeLog, PrepareChangeLog,
EditChangeLog, EditChangeLog,
......
...@@ -616,27 +616,29 @@ class ScriptTest(unittest.TestCase): ...@@ -616,27 +616,29 @@ class ScriptTest(unittest.TestCase):
self.assertEquals("New\n Lines", self.assertEquals("New\n Lines",
FileToText(TEST_CONFIG["CHANGELOG_ENTRY_FILE"])) FileToText(TEST_CONFIG["CHANGELOG_ENTRY_FILE"]))
# Version on trunk: 3.22.4.0. Version on master (bleeding_edge): 3.22.6. TAGS = """
# Make sure that the increment is 3.22.7.0. 4425.0
def testIncrementVersion(self): 0.0.0.0
self.WriteFakeVersionFile() 3.9.6
self._state["last_push_trunk"] = "hash1" 3.22.4
self._state["latest_build"] = "6" test_tag
self._state["latest_version"] = "3.22.6.0" """
# Version as tag: 3.22.4.0. Version on master: 3.22.6.
# Make sure that the latest version is 3.22.6.0.
def testGetLatestVersion(self):
self.Expect([ self.Expect([
Cmd("git checkout -f hash1 -- src/version.cc", ""), Cmd("git tag", self.TAGS),
Cmd("git checkout -f origin/master -- src/version.cc", Cmd("git checkout -f origin/master -- src/version.cc",
"", cb=lambda: self.WriteFakeVersionFile(22, 6)), "", cb=lambda: self.WriteFakeVersionFile(22, 6)),
RL("Y"), # Increment build number.
]) ])
self.RunStep(PushToTrunk, IncrementVersion) self.RunStep(PushToTrunk, GetLatestVersion)
self.assertEquals("3", self._state["new_major"]) self.assertEquals("3", self._state["latest_major"])
self.assertEquals("22", self._state["new_minor"]) self.assertEquals("22", self._state["latest_minor"])
self.assertEquals("7", self._state["new_build"]) self.assertEquals("6", self._state["latest_build"])
self.assertEquals("0", self._state["new_patch"]) self.assertEquals("0", self._state["latest_patch"])
def _TestSquashCommits(self, change_log, expected_msg): def _TestSquashCommits(self, change_log, expected_msg):
TEST_CONFIG["CHANGELOG_ENTRY_FILE"] = self.MakeEmptyTempFile() TEST_CONFIG["CHANGELOG_ENTRY_FILE"] = self.MakeEmptyTempFile()
...@@ -770,6 +772,7 @@ Performance and stability improvements on all platforms.""", commit) ...@@ -770,6 +772,7 @@ Performance and stability improvements on all platforms.""", commit)
Cmd("git status -s -uno", ""), Cmd("git status -s -uno", ""),
Cmd("git status -s -b -uno", "## some_branch\n"), Cmd("git status -s -b -uno", "## some_branch\n"),
Cmd("git fetch", ""), Cmd("git fetch", ""),
Cmd("git fetch origin +refs/tags/*:refs/tags/*", ""),
Cmd("git branch", " branch1\n* branch2\n"), Cmd("git branch", " branch1\n* branch2\n"),
Cmd("git branch", " branch1\n* branch2\n"), Cmd("git branch", " branch1\n* branch2\n"),
Cmd(("git new-branch %s --upstream origin/master" % Cmd(("git new-branch %s --upstream origin/master" %
...@@ -785,14 +788,9 @@ Performance and stability improvements on all platforms.""", commit) ...@@ -785,14 +788,9 @@ Performance and stability improvements on all platforms.""", commit)
expectations += [ expectations += [
Cmd("git log -1 --format=%s hash2", Cmd("git log -1 --format=%s hash2",
"Version 3.4.5 (based on abc3)\n"), "Version 3.4.5 (based on abc3)\n"),
Cmd("git tag", self.TAGS),
Cmd("git checkout -f origin/master -- src/version.cc", Cmd("git checkout -f origin/master -- src/version.cc",
"", cb=self.WriteFakeVersionFile), "", cb=self.WriteFakeVersionFile),
Cmd("git checkout -f hash2 -- src/version.cc", "",
cb=self.WriteFakeVersionFile),
]
if manual:
expectations.append(RL("")) # Increment build number.
expectations += [
Cmd("git log --format=%H abc3..push_hash", "rev1\n"), Cmd("git log --format=%H abc3..push_hash", "rev1\n"),
Cmd("git log -1 --format=%s rev1", "Log text 1.\n"), Cmd("git log -1 --format=%s rev1", "Log text 1.\n"),
Cmd("git log -1 --format=%B rev1", "Text\nLOG=YES\nBUG=v8:321\nText\n"), Cmd("git log -1 --format=%B rev1", "Text\nLOG=YES\nBUG=v8:321\nText\n"),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment