import os
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.
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:
            m = dep_pattern.match(ln)
            if m is not None:
                dep_names.add(m.group(1))
Beispiel #3
0
#!/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
    """)
ac_repo_path = local_ac_repo_path
if ac_repo_path is None:
    if remote_ac_repo_url is not None:
        ac_repo_path = tempfile.mkdtemp(suffix="-fenix")
        step_msg(f"Cloning {remote_ac_repo_url}")
        run_cmd_checked(["git", "clone", remote_ac_repo_url, ac_repo_path])
        if ac_branch is not None:
            run_cmd_checked(["git", "checkout", ac_branch], cwd=ac_repo_path)
elif ac_branch is not None:
    fatal_err(
        "Cannot specify a-c 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 ac_repo_path is not None:
    step_msg(
        f"Configuring {repo_path} to autopublish android-components from {ac_repo_path}"
    )
    set_gradle_substitution_path(repo_path,
                                 "autoPublish.android-components.dir",
                                 ac_repo_path)

if action == "do-nothing":
    exit(0)
elif action == "run-tests" or action is None:
    # Fenix has unittest targets for a wide variety of different configurations.
    # It's not useful to us to run them all, so just pick the one that sounds like it's
    # least likely to be broken for unrelated reasons.
    step_msg("Running fenix tests")