# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. """
Support for running jobs that are invoked via the `run-task` script. """
import os
from mozbuild.util import memoize from mozpack import path from taskgraph.transforms.run.common import support_caches from taskgraph.util.schema import Schema from taskgraph.util.yaml import load_yaml from voluptuous import Any, Optional, Required
from gecko_taskgraph.transforms.job import run_job_using from gecko_taskgraph.transforms.job.common import add_tooltool, support_vcs_checkout from gecko_taskgraph.transforms.task import taskref_or_string
run_task_schema = Schema(
{
Required("using"): "run-task", # Whether or not to use caches.
Optional("use-caches"): Any(bool, [str]), # if true (the default), perform a checkout of gecko on the worker
Required("checkout"): bool,
Optional( "cwd",
description="Path to run command in. If a checkout is present, the path " "to the checkout will be interpolated with the key `checkout`",
): str, # The sparse checkout profile to use. Value is the filename relative to # "sparse-profile-prefix" which defaults to "build/sparse-profiles/".
Required("sparse-profile"): Any(str, None), # The relative path to the sparse profile.
Optional("sparse-profile-prefix"): str, # if true, perform a checkout of a comm-central based branch inside the # gecko checkout
Required("comm-checkout"): bool, # The command arguments to pass to the `run-task` script, after the # checkout arguments. If a list, it will be passed directly; otherwise # it will be included in a single argument to `bash -cx`.
Required("command"): Any([taskref_or_string], taskref_or_string), # Base work directory used to set up the task.
Optional("workdir"): str, # If not false, tooltool downloads will be enabled via relengAPIProxy # for either just public files, or all files. Only supported on # docker-worker.
Required("tooltool-downloads"): Any( False, "public", "internal",
), # Whether to run as root. (defaults to False)
Optional("run-as-root"): bool,
}
)
def common_setup(config, job, taskdesc, command):
run = job["run"] if run["checkout"]:
support_vcs_checkout(config, job, taskdesc)
command.append( "--gecko-checkout={}".format(taskdesc["worker"]["env"]["GECKO_PATH"])
)
def script_url(config, script): if"MOZ_AUTOMATION"in os.environ and"TASK_ID"notin os.environ: raise Exception("TASK_ID must be defined to use run-task on generic-worker")
task_id = os.environ.get("TASK_ID", "")
tc_url = "http://firefox-ci-tc.services.mozilla.com" return f"{tc_url}/api/queue/v1/task/{task_id}/artifacts/public/{script}"
run_cwd = run.get("cwd") if run_cwd and run["checkout"]:
run_cwd = path.normpath(
run_cwd.format(checkout=taskdesc["worker"]["env"]["GECKO_PATH"])
) elif run_cwd and"{checkout}"in run_cwd: raise Exception( "Found `{{checkout}}` interpolation in `cwd` for task {name} " "but the task doesn't have a checkout: {cwd}".format(
cwd=run_cwd, name=job.get("name", job.get("label"))
)
)
# dict is for the case of `{'task-reference': text_type}`. if isinstance(run_command, (str, dict)):
run_command = ["bash", "-cx", run_command] if run["comm-checkout"]:
command.append( "--comm-checkout={}/comm".format(taskdesc["worker"]["env"]["GECKO_PATH"])
) if run["run-as-root"]:
command.extend(("--user", "root", "--group", "root")) if run_cwd:
command.extend(("--task-cwd", run_cwd))
command.append("--")
command.extend(run_command)
worker["command"] = command
run_command = run["command"]
run_cwd = run.get("cwd") if run_cwd and run["checkout"]:
run_cwd = path.normpath(
run_cwd.format(checkout=taskdesc["worker"]["env"]["GECKO_PATH"])
) elif run_cwd and"{checkout}"in run_cwd: raise Exception( "Found `{{checkout}}` interpolation in `cwd` for task {name} " "but the task doesn't have a checkout: {cwd}".format(
cwd=run_cwd, name=job.get("name", job.get("label"))
)
)
# dict is for the case of `{'task-reference': text_type}`. if isinstance(run_command, (str, dict)): if is_win: if isinstance(run_command, dict): for k in run_command.keys():
run_command[k] = f'"{run_command[k]}"' else:
run_command = f'"{run_command}"'
run_command = ["bash", "-cx", run_command]
if run["comm-checkout"]:
command.append( "--comm-checkout={}/comm".format(taskdesc["worker"]["env"]["GECKO_PATH"])
)
if run["run-as-root"]:
command.extend(("--user", "root", "--group", "root")) if run_cwd:
command.extend(("--task-cwd", run_cwd))
command.append("--") if is_bitbar: # Use the bitbar wrapper script which sets up the device and adb # environment variables
command.append("/builds/taskcluster/script.py")
command.extend(run_command)
if is_win:
taskref = False for c in command: if isinstance(c, dict):
taskref = True
if taskref:
cmd = [] for c in command: if isinstance(c, dict): for v in c.values():
cmd.append(v) else:
cmd.append(c)
worker["command"] = [{"artifact-reference": " ".join(cmd)}] else:
worker["command"] = [" ".join(command)] else:
worker["command"] = [
["chmod", "+x", "run-task"],
command,
]
Messung V0.5
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.