Commit 8c4440b1 authored by José Henrique's avatar José Henrique
Browse files

Cleanup code and logic

parent dcf3dbf3
......@@ -7,6 +7,7 @@ import os
from build_env import build_env_vars
from build_utils import start_notifier, start_build
from post_build import start_post_build
from post_build_env import init_post_build_env_vars
notifier_env_vars = build_env_vars
notifier_env_vars["TELEGRAM_TOKEN"] = os.getenv("TELEGRAM_TOKEN")
......@@ -16,7 +17,7 @@ if __name__ == "__main__":
start_notifier(notifier_env_vars)
if start_build(build_env_vars):
print("Build success, running post build actions...\n")
start_post_build()
start_post_build(init_post_build_env_vars(build_env_vars))
else:
print("Build failed.\n")
sys.exit(1)
......@@ -41,17 +41,6 @@ elif build_env_vars["version"] == "ten_plus":
else:
sys.exit("Invalid version")
# Build types
build_env_vars["production"] = build_env_vars["production"] == "true"
build_env_vars["eng_build"] = (build_env_vars["production"] is False
and build_env_vars["eng_build"] == "true")
build_env_vars["wip_branch"] = (build_env_vars["production"] is False
and build_env_vars["wip_branch"] == "true")
# Incremental
build_env_vars["generate_incremental"] = (
build_env_vars["generate_incremental"] == "true")
# Others
build_env_vars["working_dir"] = (
"/mnt/roms" if not os.getenv("working_dir")
......
......@@ -37,15 +37,7 @@ def pull_image(image_name):
docker_client.images.pull(image_name)
def sanitize_environment_vars(environment_vars):
for k, v in environment_vars.items():
if type(v) == bool:
environment_vars[k] = str(v).lower()
return environment_vars
def start_notifier(environment_vars):
environment_vars = sanitize_environment_vars(environment_vars)
container_name = "android_build_notifier"
image_name = "pixelexperience/android_build_notifier_ci"
volumes_to_mount = {
......@@ -65,7 +57,6 @@ def start_notifier(environment_vars):
def start_build(environment_vars):
environment_vars = sanitize_environment_vars(environment_vars)
container_name = "android_build"
image_name = "pixelexperience/android_build_ci"
volumes_to_mount = {
......
......@@ -3,21 +3,19 @@ import os
import sys
import json
from post_build_env import init_post_build_env_vars
from post_build_utils import *
post_build_env_vars = {}
files_to_upload = []
def sync_tools():
def sync_tools(post_build_env_vars):
for env_var in post_build_env_vars["tools"]:
if os.getenv("DEBUG") and os.path.exists(env_var["path"]):
return
sync_repo(env_var["url"], env_var["path"], env_var["branch"])
def create_release_zip():
def create_release_zip(post_build_env_vars):
target_files_path = (
post_build_env_vars["target_files_path"]
if post_build_env_vars["production"] else
......@@ -47,7 +45,7 @@ def create_release_zip():
post_build_env_vars["target_files_compressed_path"])
def extract_recovery():
def extract_recovery(post_build_env_vars):
if post_build_env_vars["aosp_recovery"]:
print("Extracting AOSP recovery...")
target_files_path = (
......@@ -69,7 +67,7 @@ def extract_recovery():
post_build_env_vars["aosp_recovery_path"])
def send_to_release_cp():
def send_to_release_cp(post_build_env_vars):
print("Uploading build artifacts to releasecp...")
has_target_files = (post_build_env_vars["production"] or
......@@ -114,14 +112,8 @@ def send_to_release_cp():
files_to_upload)
def start_post_build():
global post_build_env_vars
post_build_env_vars = init_post_build_env_vars()
sync_tools()
create_release_zip()
extract_recovery()
send_to_release_cp()
if os.getenv("DEBUG"):
start_post_build()
def start_post_build(post_build_env_vars):
sync_tools(post_build_env_vars)
create_release_zip(post_build_env_vars)
extract_recovery(post_build_env_vars)
send_to_release_cp(post_build_env_vars)
......@@ -4,8 +4,6 @@ import glob
import sys
import shutil
from build_env import build_env_vars
def find_file(path):
for file in glob.glob(path):
......@@ -23,8 +21,10 @@ def parse_build_prop_file(build_prop_path):
return props
def init_post_build_env_vars():
def init_post_build_env_vars(build_env_vars):
result = build_env_vars
result["production"] = result["production"] == "true"
result["generate_incremental"] = result["generate_incremental"] == "true"
if not os.getenv("DEBUG") and os.path.exists("post_build"):
shutil.rmtree('post_build')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment