Commit 3c17b3b3 authored by machenbach's avatar machenbach Committed by Commit bot

Refactor version increment in release scripts.

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

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

Cr-Commit-Position: refs/heads/master@{#26284}
parent 44f1b9d1
......@@ -47,6 +47,7 @@ from git_recipes import GitFailedException
CHANGELOG_FILE = "ChangeLog"
VERSION_FILE = os.path.join("src", "version.cc")
VERSION_RE = re.compile(r"^\d+\.\d+\.\d+(?:\.\d+)?$")
# V8 base directory.
V8_BASE = os.path.dirname(
......@@ -380,7 +381,7 @@ class Step(GitRecipesMixin):
def __getitem__(self, key):
# Convenience method to allow direct [] access on step classes for
# manipulating the backed state dict.
return self._state[key]
return self._state.get(key)
def __setitem__(self, key, value):
# Convenience method to allow direct [] access on step classes for
......@@ -589,6 +590,20 @@ class Step(GitRecipesMixin):
except GitFailedException:
self.WaitForResolvingConflicts(patch_file)
def GetLatestVersion(self):
# Use cached version if available.
if self["latest_version"]:
return self["latest_version"]
# Make sure tags are fetched.
self.Git("fetch origin +refs/tags/*:refs/tags/*")
version_parts = sorted(filter(VERSION_RE.match, self.vc.GetTags()),
key=SortingKey, reverse=True)[0].split(".")
if len(version_parts) == 3:
version_parts.append("0")
self["latest_version"] = ".".join(version_parts)
return self["latest_version"]
def FindLastCandidatesPush(
self, parent_hash="", branch="", include_patches=False):
push_pattern = "^Version [[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*"
......
......@@ -45,9 +45,6 @@ class Preparation(Step):
self.InitialEnvironmentChecks(self.default_cwd)
self.CommonPrepare()
# Make sure tags are fetched.
self.Git("fetch origin +refs/tags/*:refs/tags/*")
if(self["current_branch"] == self.Config("CANDIDATESBRANCH")
or self["current_branch"] == self.Config("BRANCHNAME")):
print "Warning: Script started on branch %s" % self["current_branch"]
......@@ -114,37 +111,29 @@ class DetectLastPush(Step):
self["last_push_master"] = last_push_master
class GetLatestVersion(Step):
MESSAGE = "Get latest version from tags."
class IncrementVersion(Step):
MESSAGE = "Increment version number."
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_")
latest_version = self.GetLatestVersion()
# The version file on master can be used to bump up major/minor at
# branch time.
self.GitCheckoutFile(VERSION_FILE, self.vc.RemoteMasterBranch())
self.ReadAndPersistVersion("master_")
self["master_version"] = self.ArrayToVersion("master_")
if SortingKey(self["master_version"]) > SortingKey(self["latest_version"]):
self["latest_version"] = self["master_version"]
self.StoreVersion(self["latest_version"], "latest_")
print "Determined latest version %s" % self["latest_version"]
master_version = self.ArrayToVersion("master_")
# Use the highest version from master or from tags to determine the new
# version.
authoritative_version = sorted(
[master_version, latest_version], key=SortingKey)[1]
self.StoreVersion(authoritative_version, "authoritative_")
class IncrementVersion(Step):
MESSAGE = "Increment version number."
def RunStep(self):
# Variables prefixed with 'new_' contain the new version numbers for the
# ongoing candidates push.
self["new_major"] = self["latest_major"]
self["new_minor"] = self["latest_minor"]
self["new_build"] = str(int(self["latest_build"]) + 1)
self["new_major"] = self["authoritative_major"]
self["new_minor"] = self["authoritative_minor"]
self["new_build"] = str(int(self["authoritative_build"]) + 1)
# Make sure patch level is 0 in a new push.
self["new_patch"] = "0"
......@@ -153,6 +142,8 @@ class IncrementVersion(Step):
self["new_minor"],
self["new_build"])
print ("Incremented version to %s" % self["version"])
class PrepareChangeLog(Step):
MESSAGE = "Prepare raw ChangeLog entry."
......@@ -429,7 +420,6 @@ class PushToCandidates(ScriptsBase):
FreshBranch,
PreparePushRevision,
DetectLastPush,
GetLatestVersion,
IncrementVersion,
PrepareChangeLog,
EditChangeLog,
......
......@@ -623,19 +623,20 @@ test_tag
# 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):
def testIncrementVersion(self):
self.Expect([
Cmd("git fetch origin +refs/tags/*:refs/tags/*", ""),
Cmd("git tag", self.TAGS),
Cmd("git checkout -f origin/master -- src/version.cc",
"", cb=lambda: self.WriteFakeVersionFile(22, 6)),
])
self.RunStep(PushToCandidates, GetLatestVersion)
self.RunStep(PushToCandidates, IncrementVersion)
self.assertEquals("3", self._state["latest_major"])
self.assertEquals("22", self._state["latest_minor"])
self.assertEquals("6", self._state["latest_build"])
self.assertEquals("0", self._state["latest_patch"])
self.assertEquals("3", self._state["new_major"])
self.assertEquals("22", self._state["new_minor"])
self.assertEquals("7", self._state["new_build"])
self.assertEquals("0", self._state["new_patch"])
def _TestSquashCommits(self, change_log, expected_msg):
TEST_CONFIG["CHANGELOG_ENTRY_FILE"] = self.MakeEmptyTempFile()
......@@ -778,7 +779,6 @@ Performance and stability improvements on all platforms."""
Cmd("git status -s -uno", ""),
Cmd("git status -s -b -uno", "## some_branch\n"),
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 new-branch %s --upstream origin/master" %
......@@ -794,6 +794,7 @@ Performance and stability improvements on all platforms."""
expectations += [
Cmd("git log -1 --format=%s hash2",
"Version 3.4.5 (based on abc3)\n"),
Cmd("git fetch origin +refs/tags/*:refs/tags/*", ""),
Cmd("git tag", self.TAGS),
Cmd("git checkout -f origin/master -- src/version.cc",
"", cb=self.WriteFakeVersionFile),
......
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