Add a run task separate from the build task

This commit is contained in:
Simon Sapin 2018-08-30 17:24:00 +02:00
parent c31b4ad095
commit b05a445284
4 changed files with 68 additions and 41 deletions

2
child-task.sh → build-task.sh Executable file → Normal file
View file

@ -4,5 +4,5 @@ curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain none -y
export PATH="$HOME/.cargo/bin:$PATH"
cd something-rust
cargo run --release
cargo build --release
gzip -c target/release/something-rust > something-rust.gz

View file

@ -0,0 +1,6 @@
#!/bin/sh
curl \
--retry 5 \
--connect-timeout 10 \
--location
https://queue.taskcluster.net/v1/task/$1/artifacts/$2

View file

@ -11,17 +11,27 @@ import taskcluster
event = json.loads(os.environ["GITHUB_EVENT"])
print("GitHub event:\n%s\n" % json.dumps(event, sort_keys=True, indent=4, separators=(',', ': ')))
task_id = taskcluster.slugId()
payload = {
# https://docs.taskcluster.net/docs/reference/workers/docker-worker/docs/features#feature-taskclusterproxy
queue = taskcluster.Queue(options={"baseUrl": "http://taskcluster/queue/v1/"})
command_prefix = """
git clone {event[repository][clone_url]} repo &&
cd repo &&
git checkout {event[after]} &&
""".format(event=event)
def create_task(name, command, artifacts=None, dependencies=None):
task_id = taskcluster.slugId()
payload = {
"taskGroupId": os.environ["DECISION_TASK_ID"],
"dependencies": [os.environ["DECISION_TASK_ID"]],
"schedulerId": "taskcluster-github", # FIXME: can we avoid hard-coding this?
"dependencies": [os.environ["DECISION_TASK_ID"]] + (dependencies or []),
"schedulerId": "taskcluster-github",
"provisionerId": "aws-provisioner-v1",
"workerType": "github-worker",
"created": taskcluster.fromNowJSON(""),
"deadline": taskcluster.fromNowJSON("1 hour"),
"metadata": {
"name": "Taskcluster experiments for Servo: Child task",
"name": "Taskcluster experiments for Servo: " + name,
"description": "",
"owner": event["pusher"]["name"] + "@users.noreply.github.com",
"source": event["compare"],
@ -33,23 +43,29 @@ payload = {
"/bin/bash",
"--login",
"-c",
"""
git clone {event[repository][clone_url]} repo &&
cd repo &&
git checkout {event[after]} &&
./child-task.sh
""".format(event=event),
command_prefix + command
],
"artifacts": {
"public/executable.gz": {
"public/" + artifact_name: {
"type": "file",
"path": "/repo/something-rust/something-rust.gz",
"path": path,
"expires": taskcluster.fromNowJSON("1 week"),
}
for artifact_name, path in artifacts or []
},
},
},
}
# https://docs.taskcluster.net/docs/reference/workers/docker-worker/docs/features#feature-taskclusterproxy
queue = taskcluster.Queue(options={"baseUrl": "http://taskcluster/queue/v1/"})
queue.createTask(task_id, payload)
print("new task scheduled: " + task_id)
}
queue.createTask(task_id, payload)
print("Scheduled %s: %s" % (name, task_id))
return task_id
build_task = create_task(
"build task",
"./build-task.sh",
artifacts=[("executable.gz", "/repo/something-rust/something-rust.gz")],
)
create_task(
"run task",
"./run-task.sh",
dependencies=[build_task],
)

5
run-task.sh Normal file
View file

@ -0,0 +1,5 @@
#!/bin/sh
./curl-artifact.sh $BUILD_TASK_ID public/executable.gz -o executable.gz
gunzip executable.gz
./executable