From eb21ceaf98b9202de9e2dbb6b641b2164748694e Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 7 Dec 2018 19:13:16 +0100 Subject: [PATCH] Upload to doc.servo.org when merging to master --- .taskcluster.yml | 3 +-- etc/taskcluster/decision_task.py | 36 ++++++++++++++++++++++++++++++-- etc/taskcluster/decisionlib.py | 16 ++++++++------ etc/taskcluster/mock.py | 8 ++++++- 4 files changed, 52 insertions(+), 11 deletions(-) diff --git a/.taskcluster.yml b/.taskcluster.yml index ea33b12034f..10559de409c 100644 --- a/.taskcluster.yml +++ b/.taskcluster.yml @@ -25,8 +25,7 @@ tasks: owner: &task_owner ${event.pusher.name}@users.noreply.github.com source: &task_source ${event.compare} scopes: - # Granted to role "repo:github.com/servo/servo:branch:*" - - "assume:project:servo:decision-task/trusted" + - "assume:repo:github.com/servo/servo:branch:${event.ref[11:]}" routes: # len("refs/heads/") == 11, so event.ref[11:] is the branch name - "tc-treeherder.v2.servo/servo-${event.ref[11:]}.${event.after}" diff --git a/etc/taskcluster/decision_task.py b/etc/taskcluster/decision_task.py index 19c3e435e25..a2a284194e6 100644 --- a/etc/taskcluster/decision_task.py +++ b/etc/taskcluster/decision_task.py @@ -10,9 +10,11 @@ from decisionlib import * def main(task_for, mock=False): if task_for == "github-push": - if CONFIG.git_ref in ["refs/heads/auto", "refs/heads/try", "refs/heads/try-taskcluster"]: - CONFIG.treeherder_repo_name = "servo-" + CONFIG.git_ref.split("/")[-1] + assert CONFIG.git_ref.startswith("refs/heads/") + branch = CONFIG.git_ref[len("refs/heads/"):] + CONFIG.treeherder_repository_names = ["servo-" + branch] + if branch in ["auto", "try", "try-taskcluster"]: linux_tidy_unit_docs() android_arm32_dev() android_arm32_release() @@ -28,6 +30,11 @@ def main(task_for, mock=False): linux_build_task("Indexed by task definition").find_or_create() android_x86_wpt() + if branch == "master": + # Also show these tasks in https://treeherder.mozilla.org/#/jobs?repo=servo-auto + CONFIG.treeherder_repository_names.append("servo-auto") + upload_docs() + # https://tools.taskcluster.net/hooks/project-servo/daily elif task_for == "daily": daily_tasks_setup() @@ -100,6 +107,31 @@ def linux_tidy_unit_docs(): ) +def upload_docs(): + docs_build_task_id = Task.find("docs." + CONFIG.git_sha) + return ( + linux_task("Upload docs to GitHub Pages") + .with_treeherder("Linux x64", "DocUpload") + .with_dockerfile(dockerfile_path("base")) + .with_curl_artifact_script(docs_build_task_id, "docs.bundle") + .with_features("taskclusterProxy") + .with_scopes("secrets:get:project/servo/doc.servo.org") + .with_env(PY="""if 1: + import urllib, json + url = "http://taskcluster/secrets/v1/secret/project/servo/doc.servo.org" + token = json.load(urllib.urlopen(url))["secret"]["token"] + open("/root/.git-credentials", "w").write("https://git:%s@github.com/" % token) + """) + .with_script(""" + python -c "$PY" + git init --bare + git config credential.helper store + git fetch --quiet docs.bundle + git push --force https://github.com/servo/doc.servo.org FETCH_HEAD:gh-pages + """) + .create() + ) + def macos_unit(): return ( macos_build_task("Dev build + unit tests") diff --git a/etc/taskcluster/decisionlib.py b/etc/taskcluster/decisionlib.py index 77197b1bd0b..553113db326 100644 --- a/etc/taskcluster/decisionlib.py +++ b/etc/taskcluster/decisionlib.py @@ -43,7 +43,7 @@ class Config: self.docker_image_buil_worker_type = None self.docker_images_expire_in = "1 month" self.repacked_msi_files_expire_in = "1 month" - self.treeherder_repo_name = None + self.treeherder_repository_names = [] # Set by docker-worker: # https://docs.taskcluster.net/docs/reference/workers/docker-worker/docs/environment @@ -156,9 +156,9 @@ class Task: "symbol": symbol, }) - if CONFIG.treeherder_repo_name: + for repo in CONFIG.treeherder_repository_names: assert CONFIG.git_sha - suffix = ".v2._/%s.%s" % (CONFIG.treeherder_repo_name, CONFIG.git_sha) + suffix = ".v2._/%s.%s" % (repo, CONFIG.git_sha) self.with_routes( "tc-treeherder" + suffix, "tc-treeherder-staging" + suffix, @@ -223,6 +223,11 @@ class Task: print("Scheduled %s" % self.name) return task_id + @staticmethod + def find(index_path): + full_index_path = "%s.%s" % (CONFIG.index_prefix, index_path) + return SHARED.index_service.findTask(full_index_path)["taskId"] + def find_or_create(self, index_path=None): """ Try to find a task in the Index and return its ID. @@ -240,18 +245,17 @@ class Task: worker_type = self.worker_type index_by = json.dumps([worker_type, self.build_worker_payload()]).encode("utf-8") index_path = "by-task-definition." + hashlib.sha256(index_by).hexdigest() - index_path = "%s.%s" % (CONFIG.index_prefix, index_path) task_id = SHARED.found_or_created_indexed_tasks.get(index_path) if task_id is not None: return task_id try: - task_id = SHARED.index_service.findTask(index_path)["taskId"] + task_id = Task.find(index_path) except taskcluster.TaskclusterRestFailure as e: if e.status_code != 404: # pragma: no cover raise - self.routes.append("index." + index_path) + self.routes.append("index.%s.%s" % (CONFIG.index_prefix, index_path)) task_id = self.create() SHARED.found_or_created_indexed_tasks[index_path] = task_id diff --git a/etc/taskcluster/mock.py b/etc/taskcluster/mock.py index d3e19d88080..43fd0cfe27f 100755 --- a/etc/taskcluster/mock.py +++ b/etc/taskcluster/mock.py @@ -31,7 +31,9 @@ class TaskclusterRestFailure(Exception): class Index: __init__ = insertTask = lambda *_, **__: None - def findTask(self, _): + def findTask(self, path): + if ".docs." in path: + return {"taskId": ""} raise TaskclusterRestFailure @@ -50,5 +52,9 @@ decision_task.main("github-push", mock=True) print("\n# Push with hot caches:") decision_task.main("github-push", mock=True) +print("\n# Push to master:") +decision_task.CONFIG.git_ref = "refs/heads/master" +decision_task.main("github-push", mock=True) + print("\n# Daily:") decision_task.main("daily", mock=True)