tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

startup-test.py (3082B)


      1 #!/usr/bin/env python3
      2 
      3 import argparse
      4 import subprocess
      5 from datetime import datetime, timedelta
      6 
      7 PLATFORM_TO_ARCH = {
      8    "linux": ["x86_64", "i686"],
      9    "macos": ["x86_64", "aarch64"],
     10    "windows": ["x86_64", "i686"],
     11 }
     12 
     13 
     14 class DynamicArchAction(argparse.Action):
     15    def __call__(self, parser, namespace, values, option_string=None):
     16        platform = getattr(namespace, "platform", None)
     17        if not platform:
     18            raise argparse.ArgumentError(
     19                self, "The --platform argument must be provided before --arch."
     20            )
     21 
     22        valid_archs = PLATFORM_TO_ARCH.get(platform, [])
     23        if values not in valid_archs:
     24            raise argparse.ArgumentError(
     25                self,
     26                f"Invalid architecture '{values}' for platform '{platform}'. "
     27                f"Valid options are: {', '.join(valid_archs)}",
     28            )
     29        setattr(namespace, self.dest, values)
     30 
     31 
     32 parser = argparse.ArgumentParser(
     33    description="Downloads and executes yesterday's build of Tor or Mullvad browser nightly."
     34 )
     35 
     36 parser.add_argument(
     37    "--platform",
     38    required=True,
     39    help="Specify the platform (linux, macos or windows). Must be provided before --arch.",
     40    choices=PLATFORM_TO_ARCH.keys(),
     41 )
     42 parser.add_argument(
     43    "--arch",
     44    required=True,
     45    help="Specify the architecture (validated dynamically based on --platform).",
     46    action=DynamicArchAction,
     47 )
     48 parser.add_argument(
     49    "--browser",
     50    required=True,
     51    choices=["tor", "mullvad"],
     52    help="Specify the browser (tor or mullvad)",
     53 )
     54 
     55 args = parser.parse_args()
     56 arch = f"-{args.arch}"
     57 extra = ""
     58 
     59 if args.platform == "linux":
     60    archive_extension = "tar.xz"
     61    binary = f"Browser/start-{args.browser}-browser"
     62 elif args.platform == "macos":
     63    archive_extension = "dmg"
     64    # The URL doesn't include the architecture for MacOS,
     65    # because it's a universal build.
     66    arch = ""
     67    if args.browser == "tor":
     68        binary = "Contents/MacOS/firefox"
     69    else:
     70        binary = "Contents/MacOS/mullvadbrowser"
     71 elif args.platform == "windows":
     72    archive_extension = "exe"
     73 
     74    if args.browser == "tor":
     75        extra = "-portable"
     76        binary = "Browser/firefox.exe"
     77    else:
     78        binary = "mullvadbrowser.exe"
     79 
     80 yesterday = (datetime.now() - timedelta(days=1)).strftime("%Y.%m.%d")
     81 
     82 download_url_base = (
     83    "https://nightlies.tbb.torproject.org/nightly-builds/tor-browser-builds"
     84 )
     85 if args.browser == "tor":
     86    download_url = f"{download_url_base}/tbb-nightly.{yesterday}/nightly-{args.platform}{arch}/{args.browser}-browser-{args.platform}{arch}{extra}-tbb-nightly.{yesterday}.{archive_extension}"
     87 else:
     88    download_url = f"{download_url_base}/tbb-nightly.{yesterday}/mullvadbrowser-nightly-{args.platform}{arch}/{args.browser}-browser-{args.platform}{arch}-tbb-nightly.{yesterday}.{archive_extension}"
     89 
     90 subprocess.run(
     91    [
     92        "python3",
     93        "testing/mozharness/scripts/does_it_crash.py",
     94        "--run-for",
     95        "30",
     96        "--thing-url",
     97        download_url,
     98        "--thing-to-run",
     99        binary,
    100    ],
    101    check=True,
    102 )