new_release: go back in history and compute depth
make get_last_release() go further back in release history, compute the depth at which it finds a release. Properly increment feature version based on the depth at which the last release was found. Change-Id: I5880611a7d9005cee8fe4c2d7920f84d880eeeb8 Task: 22351
This commit is contained in:
parent
e7ac6d6ab8
commit
eb4c7ac4ef
@ -98,16 +98,22 @@ def get_last_series_info(series, deliverable):
|
||||
'Could not determine previous version: %s' % (e,))
|
||||
|
||||
|
||||
def feature_increment(last_release):
|
||||
"""How much do we need to increment the feature number to provision
|
||||
for future stable releases in skipped series, based on last release
|
||||
found.
|
||||
"""
|
||||
return max(1, last_release['depth'])
|
||||
|
||||
|
||||
def get_release_history(series, deliverable):
|
||||
"""Retrieve the history of releases for a given deliverable.
|
||||
Returns an array of arrays containing the releases for each series,
|
||||
in reverse chronological order starting from specified series.
|
||||
"""
|
||||
all_series = sorted(os.listdir('deliverables'), reverse=True)
|
||||
series_index = all_series.index(series)
|
||||
release_history = []
|
||||
# Only consider current & previous series, to preserve current behavior
|
||||
for current_series in all_series[series_index:series_index + 1]:
|
||||
for current_series in all_series[all_series.index(series):-1]:
|
||||
try:
|
||||
deliv_info = get_deliverable_data(current_series, deliverable)
|
||||
releases = deliv_info['releases']
|
||||
@ -120,14 +126,16 @@ def get_release_history(series, deliverable):
|
||||
|
||||
|
||||
def get_last_release(release_history, deliverable, release_type):
|
||||
depth = 0
|
||||
for releases in release_history:
|
||||
if releases:
|
||||
return releases[-1]
|
||||
return dict({'depth': depth}, **releases[-1])
|
||||
elif release_type == 'bugfix':
|
||||
raise RuntimeError(
|
||||
'The first release for a series must '
|
||||
'be at least a feature release to allow '
|
||||
'for stable releases from the previous series.')
|
||||
depth = depth + 1
|
||||
|
||||
raise RuntimeError('No previous version could be found')
|
||||
|
||||
@ -228,7 +236,9 @@ def main():
|
||||
# base. If the differences are only patch levels the results
|
||||
# do not change, but if there was a minor version update then
|
||||
# the new version needs to be incremented based on that.
|
||||
new_version_parts = increment_version(last_version, (0, 1, 0))
|
||||
new_version_parts = increment_version(last_version, (
|
||||
0, feature_increment(last_release), 0)
|
||||
)
|
||||
|
||||
# NOTE(dhellmann): Save the SHAs for the commits where the
|
||||
# branch was created in each repo, even though that is
|
||||
@ -272,7 +282,7 @@ def main():
|
||||
else:
|
||||
increment = {
|
||||
'bugfix': (0, 0, 1),
|
||||
'feature': (0, 1, 0),
|
||||
'feature': (0, feature_increment(last_release), 0),
|
||||
'major': (1, 0, 0),
|
||||
}[args.release_type]
|
||||
new_version_parts = increment_version(last_version, increment)
|
||||
|
@ -124,7 +124,7 @@ class TestGetLastRelease(base.BaseTestCase):
|
||||
],
|
||||
]
|
||||
self.assertEqual(
|
||||
{'version': '1.0.0'},
|
||||
{'version': '1.0.0', 'depth': 0},
|
||||
new_release.get_last_release(
|
||||
release_history,
|
||||
'anydeliverable',
|
||||
@ -140,7 +140,7 @@ class TestGetLastRelease(base.BaseTestCase):
|
||||
],
|
||||
]
|
||||
self.assertEqual(
|
||||
{'version': '1.0.1'},
|
||||
{'version': '1.0.1', 'depth': 0},
|
||||
new_release.get_last_release(
|
||||
release_history,
|
||||
'anydeliverable',
|
||||
@ -173,7 +173,7 @@ class TestGetLastRelease(base.BaseTestCase):
|
||||
],
|
||||
]
|
||||
self.assertEqual(
|
||||
{'version': '1.0.1'},
|
||||
{'version': '1.0.1', 'depth': 1},
|
||||
new_release.get_last_release(
|
||||
release_history,
|
||||
'anydeliverable',
|
||||
@ -202,10 +202,60 @@ class TestGetLastRelease(base.BaseTestCase):
|
||||
{'version': '1.0.0'},
|
||||
],
|
||||
]
|
||||
self.assertRaises(
|
||||
RuntimeError,
|
||||
new_release.get_last_release,
|
||||
self.assertEqual(
|
||||
{'version': '1.0.0', 'depth': 2},
|
||||
new_release.get_last_release(
|
||||
release_history,
|
||||
'anydeliverable',
|
||||
'feature',
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class TestFeatureIncrement(base.BaseTestCase):
|
||||
|
||||
def test_last_release_in_current(self):
|
||||
release_history = [
|
||||
[
|
||||
{'version': '1.1.1'},
|
||||
{'version': '1.1.0'},
|
||||
],
|
||||
[
|
||||
{'version': '1.0.0'},
|
||||
],
|
||||
]
|
||||
last = new_release.get_last_release(
|
||||
release_history,
|
||||
'anydeliverable',
|
||||
'bugfix',
|
||||
'feature',
|
||||
)
|
||||
self.assertEqual(1, new_release.feature_increment(last))
|
||||
|
||||
def test_last_release_in_previous(self):
|
||||
release_history = [
|
||||
[],
|
||||
[
|
||||
{'version': '1.0.0'},
|
||||
],
|
||||
]
|
||||
last = new_release.get_last_release(
|
||||
release_history,
|
||||
'anydeliverable',
|
||||
'feature',
|
||||
)
|
||||
self.assertEqual(1, new_release.feature_increment(last))
|
||||
|
||||
def test_previous_was_skipped(self):
|
||||
release_history = [
|
||||
[],
|
||||
[],
|
||||
[
|
||||
{'version': '1.1.3'},
|
||||
],
|
||||
]
|
||||
last = new_release.get_last_release(
|
||||
release_history,
|
||||
'anydeliverable',
|
||||
'feature',
|
||||
)
|
||||
self.assertEqual(2, new_release.feature_increment(last))
|
||||
|
Loading…
Reference in New Issue
Block a user