From 411da3def53d9366609e3b8aa1715c4971215793 Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Thu, 17 Nov 2016 14:49:48 -0500 Subject: [PATCH] Resolve component refs on build submission. Fixes #203. The modulemd files we had used to all pin the commit hashes of the components they were pulling in. We changed this with modulemd-1.0 and now modules can define their components in terms of their *stream* (a.k.a. their dist-git *branch*). This is awesome, and is a big stepping stone towards greater things. The problem is that we used to take that git ref literally from the modulemd and pass it on to koji. Now that instead we are passing on a branch name to koji, it falls down. Koji requires us to send it an explicit commit hash. This change takes that branch name and converts it to an explicit commit hash when the module is first submitted. Verified that things are working again: - http://koji.stg.fedoraproject.org/koji/taskinfo?taskID=90084980 --- module_build_service/scm.py | 17 ++++++++++------- module_build_service/utils.py | 18 ++++++++++++------ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/module_build_service/scm.py b/module_build_service/scm.py index fef2d1fc..b7b411af 100644 --- a/module_build_service/scm.py +++ b/module_build_service/scm.py @@ -140,10 +140,10 @@ class SCM(object): raise RuntimeError("checkout: Unhandled SCM scheme.") return sourcedir - def get_latest(self): + def get_latest(self, branch='master'): """Get the latest commit ID. - :returns: str -- the latest commit ID, e.g. the git master HEAD + :returns: str -- the latest commit ID, e.g. the git $BRANCH HEAD :raises: RuntimeError """ if self.scheme == "git": @@ -151,13 +151,16 @@ class SCM(object): proc = sp.Popen(cmd, stdout=sp.PIPE, stderr=sp.PIPE) output, stderr = proc.communicate() if proc.returncode != 0: - raise RuntimeError("Cannot get git hash of master HEAD in %s" - % self.repository) + raise RuntimeError("Cannot get git hash of %s HEAD in %s" + % (branch, self.repository)) for line in output.split(os.linesep): - if line.endswith("\trefs/heads/master"): + if line.endswith("\trefs/heads/%s" % branch): return line.split("\t")[0] - raise RuntimeError("Couldn't determine the git master HEAD hash in %s" - % self.repository) + + # Hopefully `branch` is really a commit hash. Code later needs to verify this. + log.warn("Couldn't determine the git %s HEAD hash in %s." + % (branch, self.repository)) + return branch else: raise RuntimeError("get_latest: Unhandled SCM scheme.") diff --git a/module_build_service/utils.py b/module_build_service/utils.py index e2e8a342..cdeab962 100644 --- a/module_build_service/utils.py +++ b/module_build_service/utils.py @@ -294,12 +294,18 @@ def submit_module_build(username, url): if not pkg.cache: pkg.cache = conf.rpms_default_cache + pkgname if not pkg.ref: - try: - pkg.ref = module_build_service.scm.SCM( - pkg.repository).get_latest() - except Exception as e: - raise UnprocessableEntity( - "Failed to get the latest commit: %s" % pkgname) + pkg.ref = 'master' + try: + # If the modulemd specifies that the 'f25' branch is what + # we want to pull from, we need to resolve that f25 branch + # to the specific commit available at the time of + # submission (now). + pkg.ref = module_build_service.scm.SCM( + pkg.repository).get_latest(branch=pkg.ref) + except Exception as e: + raise UnprocessableEntity( + "Failed to get the latest commit for %s#%s" % ( + pkgname, pkg.ref)) except Exception: module.transition(conf, models.BUILD_STATES["failed"]) db.session.add(module)