2018-08-07 23:29:17 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import os
|
|
|
|
import requests
|
|
|
|
import sys
|
|
|
|
|
2018-10-23 12:41:58 +00:00
|
|
|
from typing import Dict, Tuple, List
|
2018-08-07 23:29:17 +00:00
|
|
|
|
2018-10-23 12:41:58 +00:00
|
|
|
GSTREAMER_MODULES: List[str] = [
|
|
|
|
# 'orc',
|
2018-08-07 23:29:17 +00:00
|
|
|
'gst-build',
|
|
|
|
'gstreamer',
|
|
|
|
'gst-plugins-base',
|
|
|
|
'gst-plugins-good',
|
|
|
|
'gst-plugins-bad',
|
|
|
|
'gst-plugins-ugly',
|
|
|
|
'gst-libav',
|
|
|
|
'gst-devtools',
|
|
|
|
'gst-docs',
|
|
|
|
'gst-editing-services',
|
|
|
|
'gst-omx',
|
|
|
|
'gst-python',
|
|
|
|
'gst-rtsp-server'
|
|
|
|
]
|
|
|
|
|
2018-10-23 12:41:58 +00:00
|
|
|
MANIFEST_TEMPLATE: str = """<?xml version="1.0" encoding="UTF-8"?>
|
2018-08-07 23:29:17 +00:00
|
|
|
<manifest>
|
2018-10-23 14:02:37 +00:00
|
|
|
<remote fetch="{}" name="user"/>
|
2018-08-07 23:29:17 +00:00
|
|
|
<remote fetch="https://gitlab.freedesktop.org/gstreamer/" name="gstreamer"/>
|
|
|
|
<remote fetch="git://anongit.freedesktop.org/gstreamer/" name="origin"/>
|
2018-10-23 14:02:37 +00:00
|
|
|
{}
|
2018-08-07 23:29:17 +00:00
|
|
|
</manifest>"""
|
|
|
|
|
|
|
|
|
2018-10-23 12:41:58 +00:00
|
|
|
def request(path: str) -> Dict[str, str]:
|
|
|
|
gitlab_header: Dict[str, str] = {'JOB_TOKEN': os.environ["CI_JOB_TOKEN"]}
|
2018-08-07 23:29:17 +00:00
|
|
|
|
|
|
|
return requests.get('https://gitlab.gnome.org/api/v4/' + path, headers=gitlab_header).json()
|
|
|
|
|
|
|
|
|
2018-10-23 14:02:37 +00:00
|
|
|
|
2018-10-23 12:41:58 +00:00
|
|
|
def find_repository_sha(module: str, branchname: str) -> Tuple[str, str]:
|
2018-08-07 23:29:17 +00:00
|
|
|
for project in request('projects?search=' + module):
|
|
|
|
if project['name'] != module:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if 'namespace' not in project:
|
|
|
|
# print("No 'namespace' in: %s - ignoring?" % project, file=sys.stderr)
|
|
|
|
continue
|
|
|
|
|
2018-10-23 13:34:19 +00:00
|
|
|
id = project['id']
|
2018-08-07 23:29:17 +00:00
|
|
|
if project['namespace']['name'] in useful_namespaces:
|
|
|
|
if project['namespace']['name'] == user_namespace:
|
|
|
|
# If we have a branch with same name, use it.
|
2018-10-23 13:34:19 +00:00
|
|
|
for branch in request(f"{id}/repository/branches"):
|
2018-08-07 23:29:17 +00:00
|
|
|
if branch['name'] == branchname:
|
2018-10-23 13:34:19 +00:00
|
|
|
name = project['namespace']['name']
|
|
|
|
print(f"{name}/{branchname}")
|
2018-08-07 23:29:17 +00:00
|
|
|
|
|
|
|
return 'user', branch['commit']['id']
|
|
|
|
else:
|
2018-10-23 13:34:19 +00:00
|
|
|
for branch in request(f"{id}/repository/branches"):
|
2018-08-07 23:29:17 +00:00
|
|
|
if branch['name'] == branchname:
|
2018-10-23 13:34:19 +00:00
|
|
|
print(f"gstreamer/{branchname}")
|
2018-08-07 23:29:17 +00:00
|
|
|
return 'gstreamer', branch['commit']['id']
|
|
|
|
|
2018-10-23 13:34:19 +00:00
|
|
|
branch, = request(f"{id}/repository/branches?search=master")
|
2018-08-07 23:29:17 +00:00
|
|
|
print('gstreamer/master')
|
|
|
|
return 'gstreamer', branch.attributes['commit']['id']
|
|
|
|
|
|
|
|
print('origin/master')
|
|
|
|
return 'origin', 'master'
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2018-10-23 12:41:58 +00:00
|
|
|
user_namespace: str = os.environ['CI_PROJECT_NAMESPACE']
|
|
|
|
project_name: str = os.environ['CI_PROJECT_NAME']
|
|
|
|
branchname: str = os.environ['CI_COMMIT_REF_NAME']
|
2018-08-07 23:29:17 +00:00
|
|
|
|
2018-10-23 12:41:58 +00:00
|
|
|
useful_namespaces: List[str] = ['gstreamer']
|
2018-08-07 23:29:17 +00:00
|
|
|
if branchname != 'master':
|
|
|
|
useful_namespaces.append(user_namespace)
|
|
|
|
|
|
|
|
# Shouldn't be needed.
|
2018-10-23 12:41:58 +00:00
|
|
|
remote: str = "git://anongit.freedesktop.org/gstreamer/"
|
|
|
|
projects: str = ''
|
2018-10-23 14:02:37 +00:00
|
|
|
project_template: str = " <project name=\"{}\" remote=\"{}\" revision=\"{}\" />\n"
|
2018-10-23 12:41:58 +00:00
|
|
|
user_remote: str = os.path.dirname(os.environ['CI_PROJECT_URL'])
|
2018-08-07 23:29:17 +00:00
|
|
|
for module in GSTREAMER_MODULES:
|
2018-10-23 13:34:19 +00:00
|
|
|
print(f"Checking {module}:", end=' ')
|
2018-08-07 23:29:17 +00:00
|
|
|
|
2018-10-23 13:34:19 +00:00
|
|
|
remote = 'origin'
|
2018-08-07 23:29:17 +00:00
|
|
|
revision = None
|
|
|
|
if module == project_name:
|
|
|
|
revision = os.environ['CI_COMMIT_SHA']
|
2018-10-23 13:34:19 +00:00
|
|
|
remote = 'user'
|
|
|
|
print(f"{user_namespace}/{branchname}")
|
2018-08-07 23:29:17 +00:00
|
|
|
else:
|
|
|
|
remote, revision = find_repository_sha(module, branchname)
|
|
|
|
|
|
|
|
if not revision:
|
|
|
|
revision = 'master'
|
2018-10-23 14:02:37 +00:00
|
|
|
projects += project_template.format(module, remote, revision)
|
2018-08-07 23:29:17 +00:00
|
|
|
|
|
|
|
with open('manifest.xml', mode='w') as manifest:
|
2018-10-23 14:02:37 +00:00
|
|
|
print(MANIFEST_TEMPLATE.format(user_remote, projects), file=manifest)
|