Skip to content

Commit

Permalink
Move all setup after clone to tools/ci/tc_run.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jgraham committed Mar 14, 2019
1 parent e3e39da commit 73379b4
Show file tree
Hide file tree
Showing 8 changed files with 427 additions and 328 deletions.
544 changes: 291 additions & 253 deletions .taskcluster.yml

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions tools/ci/ci_wpt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ SCRIPT_DIR=$(cd $(dirname "$0") && pwd -P)
WPT_ROOT=$SCRIPT_DIR/../..
cd $WPT_ROOT

source tools/ci/lib.sh

main() {
git fetch --quiet --unshallow https://github.com/web-platform-tests/wpt.git +refs/heads/*:refs/remotes/origin/*
install_chrome unstable
pip install --user -U tox codecov
cd tools/wpt
tox
Expand Down
6 changes: 4 additions & 2 deletions tools/ci/ci_wptrunner_infrastructure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ SCRIPT_DIR=$(cd $(dirname "$0") && pwd -P)
WPT_ROOT=$SCRIPT_DIR/../..
cd $WPT_ROOT

source tools/ci/lib.sh
add_wpt_hosts() {
./wpt make-hosts-file | sudo tee -a /etc/hosts
}

test_infrastructure() {
local ARGS="";
Expand All @@ -22,7 +24,7 @@ main() {
./wpt manifest --rebuild -p ~/meta/MANIFEST.json
for PRODUCT in "${PRODUCTS[@]}"; do
if [[ "$PRODUCT" == "chrome" ]]; then
install_chrome unstable
add_wpt_hosts
test_infrastructure "--binary=$(which google-chrome-unstable)"
else
test_infrastructure
Expand Down
22 changes: 0 additions & 22 deletions tools/ci/lib.sh

This file was deleted.

137 changes: 124 additions & 13 deletions tools/ci/run_tc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

"""Wrapper script for running jobs in TaskCluster
This is intended for running test jobs in TaskCluster. The script takes
a two arguments which are the name of the test job and the script to actually
run.
This is intended for running test jobs in TaskCluster. The script
takes a two positional arguments which are the name of the test job
and the script to actually run.
The name of the test job is used to determine whether the script should be run
for this push (this is in lieu of having a proper decision task. There are
for this push (this is in lieu of having a proper decision task). There are
several ways that the script can be scheduled to run
1. The output of wpt test-jobs includes the job name
Expand All @@ -20,12 +20,19 @@
tc-jobs: job1,job2,[...]
In addition to scheduling the event, the script sets two environment variables;
In addition, there are a number of keyword arguments used to set options for the
environment in which the jobs run. Documentation for these is in the command help.
As well as running the script, the script sets two environment variables;
GITHUB_BRANCH which is the branch that the commits will merge into (if it's a PR)
or the branch that the commits are on (if it's a push), and GITHUB_PULL_REQUEST
which is the string "false" if the event triggering this job wasn't a pull request
or the pull request number if it was. The semantics of these varaibles are chosen
or the pull request number if it was. The semantics of these variables are chosen
to match the corresponding TRAVIS_* variables.
Note: for local testing in the Docker image the script ought to still work, but
full functionality requires that the TASK_EVENT environment variable is set to
the serialization of a GitHub event payload.
"""

import argparse
Expand All @@ -34,6 +41,11 @@
import re
import subprocess
import sys
try:
from urllib2 import urlopen
except ImportError:
# Python 3 case
from urllib.request import urlopen


root = os.path.abspath(
Expand All @@ -51,14 +63,90 @@ def run(cmd, return_stdout=False, **kwargs):
return f(cmd, **kwargs)


def start(cmd):
print(" ".join(cmd))
subprocess.Popen(cmd)


def get_parser():
p = argparse.ArgumentParser()
p.add_argument("--oom-killer",
action="store_true",
default=False,
help="Run userspace OOM killer")
p.add_argument("--hosts",
dest="hosts_file",
action="store_true",
default=True,
help="Setup wpt entries in hosts file")
p.add_argument("--no-hosts",
dest="hosts_file",
action="store_false",
help="Don't setup wpt entries in hosts file")
p.add_argument("--browser",
action="append",
default=[],
help="Browsers that will be used in the job")
p.add_argument("--channel",
default=None,
choices=["experimental", "dev", "nightly", "beta", "stable"],
help="Chrome browser channel")
p.add_argument("--xvfb",
action="store_true",
help="Start xvfb")
p.add_argument("--checkout",
help="Revision to checkout before starting job")
p.add_argument("job",
help="Name of the job associated with the current event")
p.add_argument("script", help="Script to run for the job")
p.add_argument("script",
help="Script to run for the job")
p.add_argument("script_args",
nargs=argparse.REMAINDER,
help="Additional arguments to pass to the script")
return p


def start_userspace_oom_killer():
# Start userspace OOM killer: https://github.com/rfjakob/earlyoom
# It will report memory usage every minute and prefer to kill browsers.
start(["sudo", "earlyoom", "-p", "-r", "60" "--prefer=(chrome|firefox)", "--avoid=python"])


def make_hosts_file():
subprocess.check_call(["sudo", "sh", "-c", "./wpt make-hosts-file >> /etc/hosts"])


def checkout_revision(rev):
subprocess.check_call(["git", "checkout", "-q", rev])


def install_chrome(channel):
if channel in ("experimental", "dev", "nightly"):
deb_archive = "google-chrome-unstable_current_amd64.deb"
elif channel == "beta":
deb_archive = "google-chrome-beta_current_amd64.deb"
elif channel == "stable":
deb_archive = "google-chrome-stable_current_amd64.deb"
else:
raise ValueError("Unrecognized release channel: %s" % channel)

dest = os.path.join("/tmp", deb_archive)
resp = urlopen("https://dl.google.com/linux/direct/%s" % deb_archive)
with open(dest, "w") as f:
f.write(resp.read())

subprocess.check_call(["sudo", "apt-get", "-qqy", "update"])
subprocess.check_call(["sudo", "gdebi", "-n", "/tmp/%s" % deb_archive])


def start_xvfb():
start(["sudo", "Xvfb", os.environ["DISPLAY"], "-screen", "0",
"%sx%sx%s" % (os.environ["SCREEN_WIDTH"],
os.environ["SCREEN_HEIGHT"],
os.environ["SCREEN_DEPTH"])])
start(["sudo", "fluxbox", "-display", os.environ["DISPLAY"]])


def get_extra_jobs(event):
body = None
jobs = set()
Expand All @@ -70,7 +158,7 @@ def get_extra_jobs(event):
if not body:
return jobs

regexp = re.compile("\s*tc-jobs:(.*)$")
regexp = re.compile(r"\s*tc-jobs:(.*)$")

for line in body.splitlines():
m = regexp.match(line)
Expand Down Expand Up @@ -109,11 +197,30 @@ def include_job(job):
return job in set(jobs_str.splitlines())


def setup_environment(args):
if args.hosts_file:
make_hosts_file()

if "chrome" in args.browser:
assert args.channel is not None
install_chrome(args.channel)

if args.xvfb:
start_xvfb()

if args.oom_killer:
start_userspace_oom_killer()

if args.checkout:
checkout_revision(args.checkout)


def main():
args = get_parser().parse_args()
try:
event = json.loads(os.environ["TASK_EVENT"])
except ValueError:
except KeyError:
# For example under local testing
event = {}

if event:
Expand All @@ -137,13 +244,17 @@ def main():
for fn, msg in run_if:
if fn():
print(msg)
# Run the job
os.chdir(root)
print(args.script)
sys.exit(subprocess.call([args.script]))
break
else:
print("Job not scheduled for this push")
return

# Run the job
setup_environment(args)
os.chdir(root)
cmd = [args.script] + args.script_args
print(cmd)
sys.exit(subprocess.call(cmd))


if __name__ == "__main__":
Expand Down
32 changes: 1 addition & 31 deletions tools/ci/start.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1 @@
# This script is designed to be sourced from tools/docker/start.sh

# Start userspace OOM killer: https://github.com/rfjakob/earlyoom
# It will report memory usage every minute and prefer to kill browsers.
sudo earlyoom -p -r 60 --prefer '(chrome|firefox)' --avoid 'python' &

sudo sh -c './wpt make-hosts-file >> /etc/hosts'

if [[ $BROWSER == "chrome" ]] || [[ "$BROWSER" == all ]]
then
# Install Chrome dev
if [[ "$CHANNEL" == "dev" ]] || [[ "$CHANNEL" == "nightly" ]]
then
deb_archive=google-chrome-unstable_current_amd64.deb
elif [[ "$CHANNEL" == "beta" ]]
then
deb_archive=google-chrome-beta_current_amd64.deb
elif [[ "$CHANNEL" == "stable" ]]
then
deb_archive=google-chrome-stable_current_amd64.deb
else
echo Unrecognized release channel: $CHANNEL >&2
exit 1
fi
wget -O /tmp/$deb_archive https://dl.google.com/linux/direct/$deb_archive

sudo apt-get -qqy update && sudo gdebi -n /tmp/$deb_archive
fi

sudo Xvfb $DISPLAY -screen 0 ${SCREEN_WIDTH}x${SCREEN_HEIGHT}x${SCREEN_DEPTH} &
sudo fluxbox -display $DISPLAY &
# Contents of this script superceeded by tools/ci/run_tc.py
5 changes: 4 additions & 1 deletion tools/ci/tests/test_run_tc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
("Some initial line\n\ntc-jobs:foo, bar", set(["foo", "bar"])),
("tc-jobs:foo, bar \nbaz", set(["foo", "bar"])),
("tc-jobs:all", set(["all"])),
("", set())])
("", set()),
("tc-jobs:foo\ntc-jobs:bar", set(["foo"]))])
@pytest.mark.parametrize("event", [
{"commits": [{"message": "<message>"}]},
{"pull_request": {"body": "<message>"}}
])
def test_extra_jobs_pr(msg, expected, event):
def sub(obj):
"""Copy obj, except if it's a string with the value <message>
replace it with the value of the msg argument"""
if isinstance(obj, dict):
return {key: sub(value) for (key, value) in iteritems(obj)}
elif isinstance(obj, list):
Expand Down
6 changes: 3 additions & 3 deletions tools/wpt/testfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def branch_point():
return git("rev-parse", "HEAD")
elif os.environ.get("GITHUB_PULL_REQUEST", "false") != "false":
# This is a PR, so the base branch is in GITHUB_BRANCH
travis_branch = os.environ.get("GITHUB_BRANCH")
assert travis_branch, "GITHUB_BRANCH environment variable is defined"
branch_point = git("merge-base", "HEAD", travis_branch)
base_branch = os.environ.get("GITHUB_BRANCH")
assert base_branch, "GITHUB_BRANCH environment variable is defined"
branch_point = git("merge-base", "HEAD", base_branch)
else:
# Otherwise we aren't on a PR, so we try to find commits that are only in the
# current branch c.f.
Expand Down

0 comments on commit 73379b4

Please sign in to comment.