aboutsummaryrefslogtreecommitdiffstats
path: root/python/servo/testing_commands.py
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2024-02-08 12:40:15 +0100
committerGitHub <noreply@github.com>2024-02-08 11:40:15 +0000
commit5facf436f6835aa53a500ae99168b8a00ed4802c (patch)
tree9af0603e5e76781ef397c2063a1b46389b6e5be4 /python/servo/testing_commands.py
parent3620cfe2dd9e31e04663420fc5bd29421b33ede3 (diff)
downloadservo-5facf436f6835aa53a500ae99168b8a00ed4802c.tar.gz
servo-5facf436f6835aa53a500ae99168b8a00ed4802c.zip
mach: Make `./mach try` a little friendlier (#31290)
1. Move `./mach try` to `testing_commands.py which is a bit more consistent. 2. Make `./mach try` print out the remote name always and properly form the URL for ssh repositories. 3. Print out the try configuration matrix to make it more obvious what is being triggered remotely. 4. Better error handling. Print and error and exit if the remote isn't on GitHub and also clean up properly if something fails after making the temporary commit.
Diffstat (limited to 'python/servo/testing_commands.py')
-rw-r--r--python/servo/testing_commands.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/python/servo/testing_commands.py b/python/servo/testing_commands.py
index 2ca85569c58..22af292a8dc 100644
--- a/python/servo/testing_commands.py
+++ b/python/servo/testing_commands.py
@@ -15,6 +15,7 @@ import os
import os.path as path
import shutil
import subprocess
+import textwrap
import wpt
import wpt.manifestupdate
@@ -27,6 +28,7 @@ from mach.decorators import (
Command,
)
+import servo.try_parser
import tidy
from servo.command_base import BuildType, CommandBase, call, check_call
@@ -747,3 +749,51 @@ tests/wpt/mozilla/tests for Servo-only tests""" % reference_path)
# of panics won't cause timeouts on CI.
return self.context.commands.dispatch('run', self.context, build_type=build_type,
params=params + ['-f', 'tests/html/close-on-load.html'])
+
+ @Command('try', description='Runs try jobs by force pushing to try branch', category='testing')
+ @CommandArgument('--remote', '-r', default="origin", help='A git remote to run the try job on')
+ @CommandArgument('try_strings', default=["full"], nargs='...',
+ help="A list of try strings specifying what kind of job to run.")
+ def try_command(self, remote: str, try_strings: list[str]):
+ remote_url = subprocess.check_output(["git", "config", "--get", f"remote.{remote}.url"]).decode().strip()
+ if "github.com" not in remote_url:
+ print(f"The remote provided ({remote_url}) isn't a GitHub remote.")
+ return 1
+
+ try_string = " ".join(try_strings)
+ config = servo.try_parser.Config(try_string)
+ print(f"Trying on {remote} ({remote_url}) with following configuration:")
+ print()
+ print(textwrap.indent(config.to_json(indent=2), prefix=" "))
+ print()
+
+ # The commit message is composed of both the last commit message and the try string.
+ commit_message = subprocess.check_output(["git", "show", "-s", "--format=%s"]).decode().strip()
+ commit_message = f"{commit_message} ({try_string})"
+
+ result = call(["git", "commit", "--quiet", "--allow-empty", "-m", commit_message, "-m", f"{config.to_json()}"])
+ if result != 0:
+ return result
+
+ # From here on out, we need to always clean up the commit we added to the branch.
+ try:
+ result = call(["git", "push", "--quiet", remote, "--force", "HEAD:try"])
+ if result != 0:
+ return result
+
+ # TODO: This is a pretty naive approach to turning a GitHub remote URL (either SSH or HTTPS)
+ # into a URL to the Actions page. It might be better to create this action with the `gh`
+ # tool and get the real URL.
+ actions_url = remote_url.replace(".git", "/actions")
+ if not actions_url.startswith("https"):
+ actions_url = actions_url.replace(':', '/')
+ actions_url = actions_url.replace("git@", "")
+ actions_url = f"https://{actions_url}"
+ print(f"Actions available at: {actions_url}")
+
+ finally:
+ # Remove the last commit which only contains the try configuration.
+ result = call(["git", "reset", "--quiet", "--soft", "HEAD~1"])
+ if result != 0:
+ print("Could not clean up try commit. Sorry! Please try to reset to the previous commit.")
+ return result