Use git describe for superrepo project versions

This gives us some visibility into the versions being installed when
generating packages from a superrepo. Ultimately these versions are less
important than the superrepo version, so these are mostly informational.

Change-Id: I551e7a28c8c476bfd53e5b301d4f59e9106e7e7e
This commit is contained in:
Clint Byrum 2016-07-16 16:56:32 -07:00
parent 169b858a83
commit 8a949f50b9
2 changed files with 54 additions and 11 deletions

View File

@ -81,12 +81,18 @@ class BuildSpec(object):
project['gitref'] = subrepo.head.commit.hexsha
project['name'] = subdir
project['giturl'] = subrepo.working_tree_dir
project['version'] = subrepo.git.describe(always=True)
self._manifest['projects'].append(project)
projects = []
if 'projects' in self._manifest:
for project in self._manifest['projects']:
if limit_projects is None or project['name'] in limit_projects:
if project.get('version'):
project_version = project['version']
del project['version']
else:
project_version = self.version
projects.append(OpenstackProject.factory(self.settings,
project,
self.version))
project_version))
return projects

View File

@ -63,20 +63,42 @@ class TestBuildSpec(unittest.TestCase):
for project in bs.projects:
self.assertEqual('99', project.version)
def _add_setup_py(self, repo):
with open(os.path.join(repo.working_tree_dir,
'setup.py'), 'w') as setup:
setup.write("#!/usr/bin/python\n")
repo.index.add(['setup.py'])
repo.index.commit('adding setup.py')
@utils.make_test_repo("parentrepo")
@utils.make_test_repo("childrepo2")
@utils.make_test_repo("childrepo")
@utils.make_test_repo("reqrepo")
def test_build_spec_superrepo(self, parentrepo, childrepo, reqrepo):
def test_build_spec_superrepo(self,
parentrepo,
childrepo2,
childrepo,
reqrepo):
parentrepo = git.Repo(parentrepo)
childname = os.path.basename(childrepo)
with open(os.path.join(childrepo, 'setup.py'), 'w') as setup:
setup.write("#!/usr/bin/python\n")
childrepo = git.Repo(childrepo)
childrepo.index.add(['setup.py'])
childrepo.index.commit('adding setup.py')
self._add_setup_py(childrepo)
child2name = os.path.basename(childrepo2)
childrepo2 = git.Repo(childrepo2)
self._add_setup_py(childrepo2)
# tag child repo to test describe behavior
cw = childrepo2.config_writer()
cw.set_value("user", "email", "nobody@noexist.test")
cw.set_value("user", "name", "Nobody McNoperson")
cw.release()
childrepo2.create_tag('test-tag-1', message='Annotated ftw')
parentrepo.create_submodule(childname, childname,
url=childrepo.working_tree_dir)
parentrepo.index.commit('adding child repo')
parentrepo.create_submodule(child2name, child2name,
url=childrepo2.working_tree_dir)
parentrepo.index.commit('adding child repos')
constraints_path = os.path.join(reqrepo, 'upper-constraints.txt')
with open(constraints_path, 'w') as cf:
cf.write("foo==1.0\n{}==11.0\n".format(childname))
@ -87,6 +109,8 @@ class TestBuildSpec(unittest.TestCase):
url=reqrepo.working_tree_dir)
parenthash = parentrepo.head.commit.hexsha
childhash = childrepo.head.commit.hexsha
child2hash = childrepo2.head.commit.hexsha
child2describe = childrepo2.git.describe(always=True)
manifest = {
'settings': {},
'superrepo': parentrepo.working_tree_dir,
@ -96,10 +120,23 @@ class TestBuildSpec(unittest.TestCase):
tf.flush()
tf.seek(0)
bs = build_spec.BuildSpec(tf, parenthash)
self.assertEqual(1, len(bs.projects))
self.assertEqual(childhash, bs.projects[0].gitref)
child_path = os.path.join(parentrepo.working_tree_dir, childname)
self.assertEqual(child_path, bs.projects[0].giturl)
self.assertEqual(2, len(bs.projects))
results = {
childname: {
'gitref': childhash,
'version': childhash[:7],
},
child2name: {
'gitref': child2hash,
'version': child2describe,
}
}
for project in bs.projects:
child_path = os.path.join(
parentrepo.working_tree_dir, project.name)
self.assertEqual(child_path, project.giturl)
self.assertEqual(results[project.name]['gitref'], project.gitref)
self.assertEqual(results[project.name]['version'], project.version)
constraints_added = os.path.join(parentrepo.working_tree_dir,
'requirements',
'upper-constraints.txt')