diff --git a/.taskcluster.yml b/.taskcluster.yml index d7b380ae766..2629526ea64 100644 --- a/.taskcluster.yml +++ b/.taskcluster.yml @@ -27,6 +27,11 @@ tasks: sha256:7471a998e4462638c8d3e2cf0b4a99c9a5c8ca9f2ec0ae01cc069473b35cde10" features: taskclusterProxy: true + artifacts: + public/repo.bundle: + type: file + path: /repo.bundle + expires: {$fromNow: '1 day'} env: GIT_URL: ${event.repository.clone_url} TASK_FOR: ${tasks_for} diff --git a/etc/taskcluster/decision_task.py b/etc/taskcluster/decision_task.py index 841bc54882c..9500656fb2c 100644 --- a/etc/taskcluster/decision_task.py +++ b/etc/taskcluster/decision_task.py @@ -10,6 +10,11 @@ from decisionlib import CONFIG, SHARED def main(task_for): + with decisionlib.make_repo_bundle(): + tasks(task_for) + + +def tasks(task_for): if CONFIG.git_ref.startswith("refs/heads/"): branch = CONFIG.git_ref[len("refs/heads/"):] CONFIG.treeherder_repository_name = "servo-" + ( diff --git a/etc/taskcluster/decisionlib.py b/etc/taskcluster/decisionlib.py index d556f46139c..e206ae8aa97 100644 --- a/etc/taskcluster/decisionlib.py +++ b/etc/taskcluster/decisionlib.py @@ -14,6 +14,7 @@ Project-independent library for Taskcluster decision tasks """ import base64 +import contextlib import datetime import hashlib import json @@ -28,6 +29,7 @@ import taskcluster __all__ = [ "CONFIG", "SHARED", "Task", "DockerWorkerTask", "GenericWorkerTask", "WindowsGenericWorkerTask", "MacOsGenericWorkerTask", + "make_repo_bundle", ] @@ -842,3 +844,19 @@ def deindent(string): def url_basename(url): return url.rpartition("/")[-1] + + +@contextlib.contextmanager +def make_repo_bundle(): + subprocess.check_call(["git", "config", "user.name", "Decision task"]) + subprocess.check_call(["git", "config", "user.email", "nobody@mozilla.com"]) + tree = subprocess.check_output(["git", "show", CONFIG.git_sha, "--pretty=%T", "--no-patch"]) + message = "Shallow version of commit " + CONFIG.git_sha + commit = subprocess.check_output(["git", "commit-tree", tree.strip(), "-m", message]) + subprocess.check_call(["git", "update-ref", "refs/heads/shallow", commit.strip()]) + subprocess.check_call(["git", "show-ref"]) + with subprocess.Popen(["git", "bundle", "create", "../repo.bundle", "refs/heads/shallow"]) as p: + yield + exit_code = p.wait() + if exit_code: + sys.exit(exit_code) diff --git a/etc/taskcluster/mock.py b/etc/taskcluster/mock.py index 9299c7c84df..cbc495ee5b5 100755 --- a/etc/taskcluster/mock.py +++ b/etc/taskcluster/mock.py @@ -39,7 +39,7 @@ class Index: stringDate = str slugId = b"".lower -Queue = fromNow = MagicMock() +sys.exit = Queue = fromNow = MagicMock() sys.modules["taskcluster"] = sys.modules[__name__] sys.dont_write_bytecode = True os.environ.update(**{k: k for k in "TASK_ID TASK_OWNER TASK_SOURCE GIT_URL GIT_SHA".split()}) @@ -48,6 +48,7 @@ os.environ["TASKCLUSTER_ROOT_URL"] = "https://community-tc.services.mozilla.com" os.environ["TASKCLUSTER_PROXY_URL"] = "http://taskcluster" os.environ["NEW_AMI_WORKER_TYPE"] = "-" import decision_task +decision_task.decisionlib.subprocess = MagicMock() print("\n# Push:") decision_task.main("github-push")