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:
parent
169b858a83
commit
eb35b01803
|
@ -81,12 +81,18 @@ class BuildSpec(object):
|
||||||
project['gitref'] = subrepo.head.commit.hexsha
|
project['gitref'] = subrepo.head.commit.hexsha
|
||||||
project['name'] = subdir
|
project['name'] = subdir
|
||||||
project['giturl'] = subrepo.working_tree_dir
|
project['giturl'] = subrepo.working_tree_dir
|
||||||
|
project['version'] = subrepo.git.describe(always=True)
|
||||||
self._manifest['projects'].append(project)
|
self._manifest['projects'].append(project)
|
||||||
projects = []
|
projects = []
|
||||||
if 'projects' in self._manifest:
|
if 'projects' in self._manifest:
|
||||||
for project in self._manifest['projects']:
|
for project in self._manifest['projects']:
|
||||||
if limit_projects is None or project['name'] in limit_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,
|
projects.append(OpenstackProject.factory(self.settings,
|
||||||
project,
|
project,
|
||||||
self.version))
|
project_version))
|
||||||
return projects
|
return projects
|
||||||
|
|
|
@ -63,20 +63,38 @@ class TestBuildSpec(unittest.TestCase):
|
||||||
for project in bs.projects:
|
for project in bs.projects:
|
||||||
self.assertEqual('99', project.version)
|
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("parentrepo")
|
||||||
|
@utils.make_test_repo("childrepo2")
|
||||||
@utils.make_test_repo("childrepo")
|
@utils.make_test_repo("childrepo")
|
||||||
@utils.make_test_repo("reqrepo")
|
@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)
|
parentrepo = git.Repo(parentrepo)
|
||||||
childname = os.path.basename(childrepo)
|
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 = git.Repo(childrepo)
|
||||||
childrepo.index.add(['setup.py'])
|
self._add_setup_py(childrepo)
|
||||||
childrepo.index.commit('adding setup.py')
|
|
||||||
|
child2name = os.path.basename(childrepo2)
|
||||||
|
childrepo2 = git.Repo(childrepo2)
|
||||||
|
self._add_setup_py(childrepo2)
|
||||||
|
|
||||||
|
# tag child repo to test describe behavior
|
||||||
|
childrepo2.create_tag('test-tag-1', message='Annotated ftw')
|
||||||
parentrepo.create_submodule(childname, childname,
|
parentrepo.create_submodule(childname, childname,
|
||||||
url=childrepo.working_tree_dir)
|
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')
|
constraints_path = os.path.join(reqrepo, 'upper-constraints.txt')
|
||||||
with open(constraints_path, 'w') as cf:
|
with open(constraints_path, 'w') as cf:
|
||||||
cf.write("foo==1.0\n{}==11.0\n".format(childname))
|
cf.write("foo==1.0\n{}==11.0\n".format(childname))
|
||||||
|
@ -87,6 +105,8 @@ class TestBuildSpec(unittest.TestCase):
|
||||||
url=reqrepo.working_tree_dir)
|
url=reqrepo.working_tree_dir)
|
||||||
parenthash = parentrepo.head.commit.hexsha
|
parenthash = parentrepo.head.commit.hexsha
|
||||||
childhash = childrepo.head.commit.hexsha
|
childhash = childrepo.head.commit.hexsha
|
||||||
|
child2hash = childrepo2.head.commit.hexsha
|
||||||
|
child2describe = childrepo2.git.describe(always=True)
|
||||||
manifest = {
|
manifest = {
|
||||||
'settings': {},
|
'settings': {},
|
||||||
'superrepo': parentrepo.working_tree_dir,
|
'superrepo': parentrepo.working_tree_dir,
|
||||||
|
@ -96,10 +116,23 @@ class TestBuildSpec(unittest.TestCase):
|
||||||
tf.flush()
|
tf.flush()
|
||||||
tf.seek(0)
|
tf.seek(0)
|
||||||
bs = build_spec.BuildSpec(tf, parenthash)
|
bs = build_spec.BuildSpec(tf, parenthash)
|
||||||
self.assertEqual(1, len(bs.projects))
|
self.assertEqual(2, len(bs.projects))
|
||||||
self.assertEqual(childhash, bs.projects[0].gitref)
|
results = {
|
||||||
child_path = os.path.join(parentrepo.working_tree_dir, childname)
|
childname: {
|
||||||
self.assertEqual(child_path, bs.projects[0].giturl)
|
'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,
|
constraints_added = os.path.join(parentrepo.working_tree_dir,
|
||||||
'requirements',
|
'requirements',
|
||||||
'upper-constraints.txt')
|
'upper-constraints.txt')
|
||||||
|
|
Loading…
Reference in New Issue