import time import hashlib import argparse from shared import run_cmd_checked, find_app_services_root, fatal_err import re LAST_CONTENTS_HASH_FILE = ".lastAutoPublishContentsHash" GITIGNORED_FILES_THAT_AFFECT_THE_BUILD = ["local.properties"] parser = argparse.ArgumentParser(description="Publish android packages to local maven repo, but only if changed since last publish") parser.parse_args() root_dir = find_app_services_root() if str(root_dir) != os.path.abspath(os.curdir): fatal_err(f"This only works if run from the repo root ({root_dir!r} != {os.path.abspath(os.curdir)!r})") # Calculate a hash reflecting the current state of the repo. contents_hash = hashlib.sha256() contents_hash.update( run_cmd_checked(["git", "rev-parse", "HEAD"], capture_output=True).stdout ) contents_hash.update(b"\x00") # Git can efficiently tell us about changes to tracked files, including # the diff of their contents, if you give it enough "-v"s. changes = run_cmd_checked(["git", "status", "-v", "-v"], capture_output=True).stdout contents_hash.update(changes)
local_repo_path = args.use_local_repo remote_repo_url = args.remote_repo_url branch = args.branch action = args.action repo_path = local_repo_path if repo_path is None: repo_path = tempfile.mkdtemp(suffix="-a-c") if remote_repo_url is None: remote_repo_url = DEFAULT_REMOTE_REPO_URL step_msg(f"Cloning {remote_repo_url}") run_cmd_checked(["git", "clone", remote_repo_url, repo_path]) if branch is not None: run_cmd_checked(["git", "checkout", branch], cwd=repo_path) elif branch is not None: fatal_err("Cannot specify fenix branch when using a local repo; check it out locally and try again.") step_msg(f"Configuring {repo_path} to autopublish appservices") set_gradle_substitution_path(repo_path, "autoPublish.application-services.dir", find_app_services_root()) if action == "do-nothing": exit(0) elif action == "run-tests" or action is None: # There are a lot of non-app-services-related components and we don't want to run all their tests. # Read the build config to find which projects actually depend on appservices. # It's a bit gross but it makes the tests run faster! # First, find out what names a-c uses to refer to apservices projects in dependency declarations. dep_names = set() dep_pattern = re.compile("\s*const val ([A-Za-z0-9_]+) = .*Versions.mozilla_appservices") with Path(repo_path, "buildSrc", "src", "main", "java", "Dependencies.kt").open() as f: for ln in f:
#!/usr/bin/env python3 # Purpose: Run cargo update and make a pull-request against master. # Dependencies: None # Usage: ./automation/cargo-update-pr.py from shared import step_msg, fatal_err, run_cmd_checked, find_app_services_root, ensure_working_tree_clean step_msg("Checking that the generated protobuf Rust files are up-to-date") # ensure_working_tree_clean() config_file_path = find_app_services_root() / "tools/protobuf_files.toml" run_cmd_checked(["cargo", "run", "--bin", "protobuf-gen", config_file_path]) if run_cmd_checked(["git", "status", "--porcelain"], capture_output=True).stdout: run_cmd_checked(["git", "status"]) fatal_err(""" The protobuf rust files are outdated. You can fix this yourself by running cargo run --bin protobuf-gen <APP_SERVICES_ROOT>/tools/protobuf_files.toml """)
args = parser.parse_args() remote = args.remote ensure_working_tree_clean() today_date = datetime.today().strftime("%Y-%m-%d") branch_name = f"cargo-update-{today_date}" step_msg(f"Check if branch {branch_name} already exists") res = subprocess.run( ["git", "show-ref", "--verify", f"refs/heads/{branch_name}"], capture_output=True) if res.returncode == 0: fatal_err(f"The branch {branch_name} already exists!") step_msg(f"Updating remote {remote}") run_cmd_checked(["git", "remote", "update", remote]) step_msg(f"Creating branch {branch_name}") run_cmd_checked( ["git", "checkout", "-b", branch_name, "--no-track", f"{remote}/main"]) step_msg("Running cargo update") run_cmd_checked(["cargo", "update"]) while True: step_msg("Regenerating dependency summaries") res = subprocess.run(["./tools/regenerate_dependency_summaries.sh"]) if res.returncode == 0: