gitlab: manifest: Use a cerbero ref with build
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Thu, 2 May 2019 21:28:42 +0000 (17:28 -0400)
committerNicolas Dufresne <nicolas@ndufresne.ca>
Fri, 3 May 2019 20:05:33 +0000 (20:05 +0000)
For non-cerbero builds, pick a cerbero reference for which a build has
completed. This will reduce the number of cache miss, hence reduce the
number of timeouts and slow build we are facing each time cerbero is
updated.

Fixes #16

gitlab/build_manifest.py

index ec8901a..f8c7b01 100755 (executable)
@@ -2,12 +2,14 @@
 
 import argparse
 import os
-import requests
 import sys
 import subprocess
+import urllib.error
+import urllib.parse
+import urllib.request
+import json
 
 from typing import Dict, Tuple, List
-from urllib.parse import urlparse
 # from pprint import pprint
 
 GSTREAMER_MODULES: List[str] = [
@@ -44,6 +46,23 @@ os.environ['GIT_TERMINAL_PROMPT'] = '0'
 def git(*args, repository_path='.'):
     return subprocess.check_output(["git"] + list(args), cwd=repository_path).decode()
 
+def get_cerbero_last_build_info (namespace : str, branch : str):
+    base_url = f"https://gitlab.freedesktop.org/{namespace}/cerbero/-/jobs"
+    url = f"{base_url}/artifacts/{branch}/raw/cerbero-build/cerbero-deps.log"
+    deps = [{'commit': None}]
+
+    try:
+        # The logs are only available if all jobs have passed so it does not
+        # matter which distro/arch is picked.
+        values = { 'job': "cerbero deps fedora x86_64" }
+        data = urllib.parse.urlencode(values)
+        req = urllib.request.Request(f"{url}?{data}")
+        resp = urllib.request.urlopen(req);
+        deps = json.loads(resp.read())
+    except urllib.error.URLError:
+        return None
+
+    return deps[0]['commit']
 
 def get_branches_info(module: str, namespace: str, branches: List[str]) -> Tuple[str, str]:
     try:
@@ -54,6 +73,13 @@ def get_branches_info(module: str, namespace: str, branches: List[str]) -> Tuple
     if not res:
         return None, None
 
+    # Special case cerbero to avoid cache misses
+    if module == 'cerbero':
+        for branch in branches:
+            sha = get_cerbero_last_build_info(namespace, branch)
+            if sha is not None:
+                return sha, sha
+
     lines = res.split('\n')
     for branch in branches:
         for line in lines: