You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

155 lines
5.0 KiB

# encoding: utf-8
import os
import sys
import stat
from pathlib import Path
import time
import re
import socket
import task
import tools
import log_tail
class CIProcess():
def __init__(self, unity_exe_path, buld_player_name, p4path, local_name, upload_name_prex, upload_path, notice_webhook, build_version, suffix):
self.unity_exe_path = unity_exe_path
self.buld_player_name = buld_player_name
self.unity_method_name = 'H3DBuild.ContentPipeline.BuildPlayerCmd'
self.unity_log_path = os.getcwd() + "/build-android-output/unity_log.txt"
self.export_path = os.getcwd() + "/../build/Android"
self.p4path = p4path
self.local_name = local_name
self.upload_name_prex = upload_name_prex
self.upload_path = upload_path
self.notice_webhook = notice_webhook
self.build_version = build_version
self.suffix = suffix
def Build(self):
tools.DelFiles("../Library/ScriptAssemblies")
tools.DelFiles("../H3DLog")
# 结束正在运行的unity进程; TODO: 暂屏蔽
# proce = "Unity.exe"
# os.system('taskkill /IM %s /F' % proce)
export_file = self.export_path + "/framw_1.0.0_100100.apk"
if Path(export_file).is_file():
print("%s exist, delete" % export_file)
os.remove(export_file)
# os.chmod( self.unity_log_path, stat.S_IWRITE )
# f=open(self.unity_log_path,'wb+')
# f.truncate()
build_path = os.getcwd()
work_path = os.getcwd() + "/.."
os.chdir(work_path)
unity_proj_path = os.getcwd()
os.chdir("..")
run_cmd = '"{}" -quit -batchmode -logFile - -projectPath {} -executeMethod {} -buildName {} -buildTarget Android'\
.format(self.unity_exe_path, unity_proj_path, self.unity_method_name, self.buld_player_name)
print(run_cmd)
sys.stdout.flush()
ret = os.system(run_cmd)
# time.sleep(1)
# content = f.read()
# content = content.decode("utf8","ignore")
# print(content)
# f.close()
# if re.search("Build Failed", content):
# print("build failed!")
# sys.stdout.flush()
# ret = -1
if ret > 0:
ret = -ret
os.chdir(build_path)
if False == Path(self.local_name).is_file():
print("self.local_name is not exist, %s" % self.local_name)
sys.stdout.flush()
return -1
return ret
def Upload(self, now, p4_number, p4_author):
if False == Path(self.local_name).is_file():
print("local_name is not exist, %s" % self.local_name)
sys.stdout.flush()
return -1
upload_name = self.upload_name_prex + "_" + self.build_version + "_" + now + "_" + "p4:" + p4_number + "_" + p4_author + "." + self.suffix
tools.UploadNexus(self.upload_path, self.local_name, upload_name)
tools.NoticeUpload(self.notice_webhook, self.upload_path, upload_name, p4_number, p4_author)
return 0
def Run(self):
now = tools.GetTime()
p4_number, p4_author = tools.GetP4Info(self.p4path)
ret = self.Build()
if (0 != ret):
print("Build fail, ret = ", ret)
sys.stdout.flush()
return ret
ret = self.Upload(now, p4_number, p4_author)
if (0 != ret):
print("Upload fail, ret = ", ret)
return ret
return ret
if __name__ == '__main__':
if (10 > len(sys.argv)):
print("args err! not unity_exe_path and buld_player_name")
os._exit(-1)
unity_exe_path = sys.argv[1]
buld_player_name = sys.argv[2]
p4path = sys.argv[3]
local_name = sys.argv[4]
upload_name_prex = sys.argv[5]
upload_path = sys.argv[6]
notice_webhook = sys.argv[7]
build_version = sys.argv[8]
suffix = sys.argv[9]
print("unity_exe_path : %s" % unity_exe_path)
print("buld_player_name : %s" % buld_player_name)
print("p4path : %s" % p4path)
print("local_name : %s" % local_name)
print("upload_name_prex : %s" % upload_name_prex)
print("upload_path : %s" % upload_path)
print("notice_webhook : %s" % notice_webhook)
print("build_version : %s" % build_version)
print("suffix : %s" % suffix)
sys.stdout.flush()
if False == Path(unity_exe_path).is_file():
print("unity_exe_path is not exist, %s" % unity_exe_path)
os._exit(-2)
process = CIProcess(unity_exe_path, buld_player_name, p4path, local_name, upload_name_prex, upload_path, notice_webhook, build_version, suffix)
# 超时控制30分钟
# ret = task.Start(30 * 60, process)
ret = process.Run()
print("ret:%d" % ret)
sys.stdout.flush()
os._exit(ret)