Skip to content
Snippets Groups Projects
Commit dbfd868d authored by Julien Cristau's avatar Julien Cristau
Browse files

Bug 1824856 - update android buildconfig lint script for mercurial. r=jlorenzo

parent 44da51f4
No related branches found
No related tags found
No related merge requests found
......@@ -7,14 +7,14 @@
import logging
import os
import subprocess
import sys
from pygit2 import Repository
from update_buildconfig_from_gradle import main as update_build_config
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
PROJECT_DIR = os.path.realpath(os.path.join(CURRENT_DIR, "..", "..", ".."))
OUTPUT_DIR = os.path.join(PROJECT_DIR, "artifacts", "git")
OUTPUT_DIR = os.path.join(PROJECT_DIR, "artifacts")
BUILDCONFIG_DIFF_FILE_NAME = "buildconfig.diff"
BUILDCONFIG_DIFF_FILE = os.path.join(OUTPUT_DIR, BUILDCONFIG_DIFF_FILE_NAME)
BUILDCONFIG_FILE_NAME = ".buildconfig.yml"
......@@ -22,18 +22,18 @@ BUILDCONFIG_FILE_NAME = ".buildconfig.yml"
logger = logging.getLogger(__name__)
def _are_buildconfig_files_changed(git_diff):
return any(
delta.new_file.path.endswith(BUILDCONFIG_FILE_NAME) for delta in git_diff.deltas
)
def _buildconfig_files_diff():
cmd = ["hg", "diff", "--rev", "draft() and ancestors(.)", "-I", "**/.buildconfig.yml"]
p = subprocess.run(cmd, capture_output=True, universal_newlines=True)
return p.stdout
def _execute_taskcluster_steps(diff, task_id):
os.makedirs(OUTPUT_DIR, exist_ok=True)
with open(BUILDCONFIG_DIFF_FILE, mode="w") as f:
f.write(diff.patch)
f.write(diff)
tc_root_url = os.environ["TASKCLUSTER_ROOT_URL"]
artifact_url = f"{tc_root_url}/api/queue/v1/task/{task_id}/artifacts/public%2Fgit%2F{BUILDCONFIG_DIFF_FILE_NAME}" # noqa E501
artifact_url = f"{tc_root_url}/api/queue/v1/task/{task_id}/artifacts/public%2F{BUILDCONFIG_DIFF_FILE_NAME}" # noqa E501
message = f"""{BUILDCONFIG_FILE_NAME} file changed! Please update it by running:
curl --location --compressed {artifact_url} | git apply
......@@ -49,8 +49,8 @@ def _execute_local_steps():
def main():
update_build_config()
diff = Repository(PROJECT_DIR).diff()
if _are_buildconfig_files_changed(diff):
diff = _buildconfig_files_diff()
if diff:
task_id = os.environ.get("TASK_ID")
if task_id:
_execute_taskcluster_steps(diff, task_id)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment