jenkins-bot has submitted this change and it was merged.

Change subject: make-release: enhance MwVersion
......................................................................


make-release: enhance MwVersion

Get rid of code duplication when detecting versions and added in the
notin of phase and cycles (ie: rc0)

* We handled regular version and alpha/beta/rc using two different
  regex, that is now a single regex.
* Use named groups in regex and /x to make the regex easier to
  understand.
* The last matched group (a minor version for regular release and a
  cycle for a alpha/beta/rc) is tested for 0 to find out whether we can
  forge a previous version which is done by decrementing that last
  group.
* Update tests were relevant

Tests:

test_incomplete_version (tests.test_mwversion.TestMwVersion) ... ok
test_major_version (tests.test_mwversion.TestMwVersion) ... ok
test_master (tests.test_mwversion.TestMwVersion) ... ok
test_minor_version (tests.test_mwversion.TestMwVersion) ... ok
test_release_candidate (tests.test_mwversion.TestMwVersion) ... ok
test_release_candidate_bumps (tests.test_mwversion.TestMwVersion) ... ok

----------------------------------------------------------------------
Ran 6 tests in 0.002s

OK

bug: 57088
Change-Id: I34c67e95a85ee28f8c9b074c738324d564794013
---
M make-release/make-release.py
M make-release/tests/test_mwversion.py
2 files changed, 54 insertions(+), 25 deletions(-)

Approvals:
  Hashar: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/make-release/make-release.py b/make-release/make-release.py
index 05a43a8..9d91da2 100755
--- a/make-release/make-release.py
+++ b/make-release/make-release.py
@@ -180,6 +180,10 @@
         self.prev_version = decomposed.get('prevVersion', None)
         self.prev_branch = decomposed.get('prevBranch', None)
 
+        # alpha / beta / rc ..
+        self.phase = decomposed.get('phase', None)
+        self.cycle = decomposed.get('cycle', None)
+
     def __repr__(self):
         if self.raw is None:
             return "<MwVersion Null (snapshot?)>"
@@ -193,7 +197,17 @@
         '''Split a version number to branch / major
 
         Whenever a version is recognized, a dict is returned with keys:
-            major, branch, prevVersion and prevBranch
+            - major (ie 1.22)
+            - minor
+            - branch
+            - prevVersion
+            - prevBranch
+
+        When one or more letters are found after the minor version we consider
+        it a software development phase (ex: alpha, beta, rc) with incremental
+        cycles. Hence we will expose:
+            - phase
+            - cycle
 
         Default: {}
         '''
@@ -202,35 +216,41 @@
         if version is None:
             return ret
 
-        m = re.compile('(\d+)\.(\d+)\.(\d+)$').match(version)
-        if m is not None:
-            ret['major'] = m.group(1) + "." + m.group(2)
-            ret['branch'] = ('tags/' + m.group(1) + '.' + m.group(2)
-                             + '.' + m.group(3))
-            if int(m.group(3)) == 0:
-                ret['prevVersion'] = None
-            else:
-                newMinor = str(int(m.group(3)) - 1)
-                ret['prevVersion'] = ret['major'] + '.' + newMinor
-                ret['prevBranch'] = ('tags/' + m.group(1) + '.' + m.group(2)
-                                     + '.' + newMinor)
-            return ret
+        m = re.compile(r"""
+            (?P<major>\d+\.\d+)
+            \.
+            (?P<minor>\d+)
+            (?:
+                (?P<phase>[A-Za-z]+)
+                (?P<cycle>\d+)
+            )?
+        """, re.X).match(version)
 
-        m = re.compile('(\d+)\.(\d+)\.(\d+)([A-Za-z]+)(\d+)$').match(version)
         if m is None:
             return ret
 
-        ret['major'] = m.group(1) + "." + m.group(2)
-        ret['branch'] = ('tags/' + m.group(1) + '.' + m.group(2) + '.'
-                         + m.group(3) + m.group(4) + m.group(5))
-        if int(m.group(5)) == 0:
+        # Clear out unneed phase/cycle
+        ret = dict((k, v) for k, v in m.groupdict().iteritems()
+                   if v is not None)
+
+        ret['branch'] = 'tags/%s.%s%s%s' % (
+            ret['major'],
+            ret['minor'],
+            ret.get('phase', ''),
+            ret.get('cycle', '')
+        )
+
+        last = m.group(m.lastindex)
+        if int(last) == 0:
             ret['prevVersion'] = None
-        else:
-            newMinor = str(int(m.group(5)) - 1)
-            ret['prevVersion'] = (ret['major'] + "." + m.group(3)
-                                  + m.group(4) + newMinor)
-            ret['prevBranch'] = ('tags/' + m.group(1) + '.' + m.group(2)
-                                 + '.' + m.group(3) + m.group(4) + newMinor)
+            return ret
+
+        bits = [d if d is not None else '' for d in m.groups()]
+        bits[m.lastindex - 1] = str(int(bits[m.lastindex - 1]) - 1)
+
+        ret['prevVersion'] = '%s.%s%s%s' % tuple(bits)
+        ret['prevBranch'] = 'tags/' + ret['prevVersion']
+
         return ret
 
 
diff --git a/make-release/tests/test_mwversion.py 
b/make-release/tests/test_mwversion.py
index 7e61536..c717e6b 100644
--- a/make-release/tests/test_mwversion.py
+++ b/make-release/tests/test_mwversion.py
@@ -17,6 +17,9 @@
         self.prev_version = None
         self.prev_branch = None
 
+        self.phase = None
+        self.cycle = None
+
         self.__dict__.update(attributes)
 
 
@@ -58,6 +61,8 @@
             'raw': '1.22.0rc0',
             'major': '1.22',
             'branch': 'tags/1.22.0rc0',
+            'phase': 'rc',
+            'cycle': '0',
             })
         self.assertMwVersionEqual(expected, observed)
 
@@ -67,6 +72,8 @@
             'raw': '1.22.0rc0',
             'major': '1.22',
             'branch': 'tags/1.22.0rc0',
+            'phase': 'rc',
+            'cycle': '0',
             })
         self.assertMwVersionEqual(expected, observed)
 
@@ -77,6 +84,8 @@
             'branch': 'tags/1.22.0rc1',
             'prev_branch': 'tags/1.22.0rc0',
             'prev_version': '1.22.0rc0',
+            'phase': 'rc',
+            'cycle': '1',
             })
         self.assertMwVersionEqual(expected, observed)
 

-- 
To view, visit https://gerrit.wikimedia.org/r/96038
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I34c67e95a85ee28f8c9b074c738324d564794013
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/tools/release
Gerrit-Branch: master
Gerrit-Owner: Hashar <has...@free.fr>
Gerrit-Reviewer: CSteipp <cste...@wikimedia.org>
Gerrit-Reviewer: Hashar <has...@free.fr>
Gerrit-Reviewer: MarkAHershberger <mhershber...@wikimedia.org>
Gerrit-Reviewer: Reedy <re...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to