添加通过git hash来判断资源修改的方法
parent
6c94f5d1fd
commit
2b086a8632
|
|
@ -25,6 +25,27 @@ from optparse import OptionParser
|
||||||
from ipm.wechat_alert import wechat_alert
|
from ipm.wechat_alert import wechat_alert
|
||||||
alert = wechat_alert()
|
alert = wechat_alert()
|
||||||
|
|
||||||
|
input_old_hash = ''
|
||||||
|
input_new_hash = ''
|
||||||
|
modifyLevelStr = ''
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
input_old_hash = sys.argv[1]
|
||||||
|
if input_old_hash == 'none' or input_old_hash == '_':
|
||||||
|
input_old_hash = ''
|
||||||
|
if len(sys.argv) > 2:
|
||||||
|
input_new_hash = sys.argv[2]
|
||||||
|
if input_new_hash == 'none' or input_new_hash == '_':
|
||||||
|
input_new_hash = ''
|
||||||
|
if len(sys.argv) > 3:
|
||||||
|
modifyLevelStr = sys.argv[3]
|
||||||
|
|
||||||
|
env = config.machine_env_config.Local_Path.value
|
||||||
|
workspace_path = env['workspace_path']
|
||||||
|
unity_install_path = env['unity_install_path']
|
||||||
|
art_proj_path = config.getArtProjPath(env)
|
||||||
|
asset_build_proj_path = config.getAssetsBuildProjPath(env)
|
||||||
|
unity_proj_path = config.getUnityProjPath(env)
|
||||||
|
|
||||||
# 主机IP
|
# 主机IP
|
||||||
IP = ""
|
IP = ""
|
||||||
# Unity执行文件路径
|
# Unity执行文件路径
|
||||||
|
|
@ -46,6 +67,110 @@ def check_dir(path):
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
|
|
||||||
|
git_commit_hash_file = os.path.join(workspace_path, 'find_object_git_commit_hash.txt')
|
||||||
|
git_hash_change_record_file = os.path.join(workspace_path, 'find_object_git_hash_change_record.txt')
|
||||||
|
|
||||||
|
def isGitCommitFileExist():
|
||||||
|
return os.path.exists(git_commit_hash_file)
|
||||||
|
|
||||||
|
def writeGitCommitLog(git_log_hash):
|
||||||
|
# 写入git_commit.txt文件
|
||||||
|
with open(git_commit_hash_file, 'w') as f:
|
||||||
|
f.write(git_log_hash)
|
||||||
|
|
||||||
|
def recordNewGitHash(git_log_hash):
|
||||||
|
# 文件末尾新增一行记录新的git hash
|
||||||
|
with open(git_hash_change_record_file, 'a') as f:
|
||||||
|
f.write(git_log_hash + '\n')
|
||||||
|
|
||||||
|
def isRecordGitHashFileExist():
|
||||||
|
return os.path.exists(git_hash_change_record_file)
|
||||||
|
|
||||||
|
def getCurrentGitHash():
|
||||||
|
current_commit_hash = ''
|
||||||
|
if isGitCommitFileExist():
|
||||||
|
with open(git_commit_hash_file, 'r') as f:
|
||||||
|
current_commit_hash = f.read()
|
||||||
|
print(f"current hash:{current_commit_hash}")
|
||||||
|
return current_commit_hash
|
||||||
|
|
||||||
|
def getNewGitHash():
|
||||||
|
sh1 = f"cd {art_proj_path}"
|
||||||
|
sh2 = f"git log -1 --pretty=format:\"%H\""
|
||||||
|
f = os.popen(f"{sh1} && {sh2}")
|
||||||
|
new_commit_hash = f.read()
|
||||||
|
print(f"new hash:{new_commit_hash}")
|
||||||
|
return new_commit_hash
|
||||||
|
|
||||||
|
# endregion
|
||||||
|
|
||||||
|
def getModifyPic(git_dir):
|
||||||
|
pass
|
||||||
|
if input_old_hash != '' and input_new_hash != '':
|
||||||
|
current_commit_hash = input_old_hash
|
||||||
|
new_commit_hash = input_new_hash
|
||||||
|
else:
|
||||||
|
current_commit_hash = getCurrentGitHash()
|
||||||
|
new_commit_hash = getNewGitHash()
|
||||||
|
if not isGitCommitFileExist():
|
||||||
|
writeGitCommitLog(new_commit_hash)
|
||||||
|
current_commit_hash = new_commit_hash
|
||||||
|
if not isRecordGitHashFileExist():
|
||||||
|
recordNewGitHash(new_commit_hash)
|
||||||
|
if current_commit_hash == new_commit_hash:
|
||||||
|
config.notification_helper.append_msg("当前commit hash与新commit hash相同,不需要构建")
|
||||||
|
return None
|
||||||
|
sh1 = f"cd {git_dir}"
|
||||||
|
sh2 = f"git log {new_commit_hash}...{current_commit_hash} --name-status"
|
||||||
|
f = os.popen(f"{sh1} && {sh2}")
|
||||||
|
modify_content_lines = f.readlines()
|
||||||
|
return modify_content_lines
|
||||||
|
|
||||||
|
|
||||||
|
def getModifyIdList(modify_content_lines):
|
||||||
|
assetLevelIdList = []
|
||||||
|
# thumLevelIdList = []
|
||||||
|
if modify_content_lines is None:
|
||||||
|
return assetLevelIdList#, thumLevelIdList
|
||||||
|
|
||||||
|
for line in modify_content_lines:
|
||||||
|
levelId = None
|
||||||
|
if line.startswith('D'):
|
||||||
|
continue
|
||||||
|
if '.zip' not in line:
|
||||||
|
continue
|
||||||
|
if '\t' in line and '\n' in line:
|
||||||
|
levelId = line.split('\t')[-1].split('/')[-1].split('.')[0]
|
||||||
|
else:
|
||||||
|
levelId = line.split('/')[-1].split('.')[0]
|
||||||
|
|
||||||
|
if levelId is None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if '.zip' in line and levelId not in assetLevelIdList:
|
||||||
|
assetLevelIdList.append(levelId)
|
||||||
|
|
||||||
|
# if '.jpg' in line and levelId not in thumLevelIdList:
|
||||||
|
# thumLevelIdList.append(levelId)
|
||||||
|
return assetLevelIdList#, thumLevelIdList
|
||||||
|
|
||||||
|
|
||||||
|
def generateLevelIdListByGitLog():
|
||||||
|
pass
|
||||||
|
global _levelModifiedIdList_
|
||||||
|
modify_content_lines = getModifyPic(art_proj_path)
|
||||||
|
_levelModifiedIdList_ = getModifyIdList(modify_content_lines)
|
||||||
|
if len(modifyLevelStr) > 0:
|
||||||
|
manual_modify_level_list = modifyLevelStr.split('#')
|
||||||
|
for level_id in manual_modify_level_list:
|
||||||
|
# asset_file = os.path.join(art_proj_path, 'LevelPackages', f'{level_id}.unitypackage')
|
||||||
|
# if not os.path.exists(asset_file):
|
||||||
|
# config.notification_helper.append_msg(f'{level_id}资源文件不存在,无法打包')
|
||||||
|
if level_id not in _levelModifiedIdList_:
|
||||||
|
_levelModifiedIdList_.append(level_id)
|
||||||
|
|
||||||
|
print(f'资源修改列表:{str(_levelModifiedIdList_)}')
|
||||||
|
config.notification_helper.append_msg(f"构建资源列表: {str(_levelModifiedIdList_)}")
|
||||||
|
|
||||||
def build_package(opts, modify_files):
|
def build_package(opts, modify_files):
|
||||||
"""
|
"""
|
||||||
|
|
@ -113,6 +238,7 @@ def check_params(opts):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
# region 创建打包的命令参数
|
||||||
parser = OptionParser()
|
parser = OptionParser()
|
||||||
# parser.add_option("-v", "--appversion", dest="appversion", help=('app版本, 显示在app详情内的'))
|
# parser.add_option("-v", "--appversion", dest="appversion", help=('app版本, 显示在app详情内的'))
|
||||||
# parser.add_option("-r", "--resversion", dest="resversion", help=('资源版本版本'))
|
# parser.add_option("-r", "--resversion", dest="resversion", help=('资源版本版本'))
|
||||||
|
|
@ -132,15 +258,16 @@ if __name__ == '__main__':
|
||||||
opts.buildtype = "BuildBundle"
|
opts.buildtype = "BuildBundle"
|
||||||
|
|
||||||
# 本地自测适用
|
# 本地自测适用
|
||||||
# opts.aab = "false"
|
opts.aab = "false"
|
||||||
# opts.mode = "Debug"
|
opts.mode = "Debug"
|
||||||
# opts.platform = "Android"
|
opts.platform = "Android"
|
||||||
# opts.assets = "/Users/a0729/gogs.git/find-vertical-art"
|
opts.assets = "/Users/a0729/gogs.git/find-vertical-art"
|
||||||
# opts.resources = "/Users/a0729/gogs.git/find-vertical-bundle-resource"
|
opts.resources = "/Users/a0729/gogs.git/find-vertical-bundle-resource"
|
||||||
# opts.unityexe = "/Applications/Unity/Hub/Editor/2021.3.32f1/Unity.app/Contents/MacOS/Unity"
|
opts.unityexe = "/Applications/Unity/Hub/Editor/2021.3.32f1/Unity.app/Contents/MacOS/Unity"
|
||||||
# opts.log = "log/build.log"
|
opts.log = "log/build.log"
|
||||||
# opts.upload = "false"
|
opts.upload = "false"
|
||||||
# opts.special = "main_30point_ws20250422_1"
|
# opts.special = "main_30point_ws20250422_1"
|
||||||
|
opts.special = "0"
|
||||||
#
|
#
|
||||||
|
|
||||||
is_upload = True if opts.upload == "true" else False
|
is_upload = True if opts.upload == "true" else False
|
||||||
|
|
@ -158,6 +285,7 @@ if __name__ == '__main__':
|
||||||
if opts.unityexe != "":
|
if opts.unityexe != "":
|
||||||
UNITY_PATH = opts.unityexe
|
UNITY_PATH = opts.unityexe
|
||||||
RESOURCE_ROOT = os.path.abspath(os.path.join(curr_dir, "../../Bundles"))
|
RESOURCE_ROOT = os.path.abspath(os.path.join(curr_dir, "../../Bundles"))
|
||||||
|
# endregion
|
||||||
|
|
||||||
mainPlayType = MainPlayType()
|
mainPlayType = MainPlayType()
|
||||||
# region 清空各玩法软链接资源列表
|
# region 清空各玩法软链接资源列表
|
||||||
|
|
@ -188,22 +316,30 @@ if __name__ == '__main__':
|
||||||
os.remove(os.path.join(root, file))
|
os.remove(os.path.join(root, file))
|
||||||
# endregion
|
# endregion
|
||||||
|
|
||||||
|
# region 检索需要需要打包的关卡
|
||||||
modify_files = []
|
modify_files = []
|
||||||
if opts.special != "0":
|
if opts.special != "0":
|
||||||
modify_files = opts.special.split(",")
|
modify_files = opts.special.split(",")
|
||||||
else:
|
else:
|
||||||
# 获取最近6小时内的提交记录,用于解析psd
|
# 获取最近6小时内的提交记录,用于解析psd
|
||||||
platform = "android" if opts.platform == "Android" else "ios"
|
# platform = "android" if opts.platform == "Android" else "ios"
|
||||||
with open(os.path.join(opts.assets, f"git_{platform}_commit_change_files.txt"), "r") as f:
|
# with open(os.path.join(opts.assets, f"git_{platform}_commit_change_files.txt"), "r") as f:
|
||||||
lines = f.readlines()
|
# lines = f.readlines()
|
||||||
for aline in lines:
|
# for aline in lines:
|
||||||
aline = aline.replace("\"", "").replace("\n", "").replace("\r", "")
|
# aline = aline.replace("\"", "").replace("\n", "").replace("\r", "")
|
||||||
if aline.endswith(".zip"):
|
# if aline.endswith(".zip"):
|
||||||
base_dir = aline.split("/")[0]
|
# base_dir = aline.split("/")[0]
|
||||||
file_name = os.path.basename(aline)
|
# file_name = os.path.basename(aline)
|
||||||
asset_id = file_name.split(".")[0]
|
# asset_id = file_name.split(".")[0]
|
||||||
if asset_id not in modify_files:
|
# if asset_id not in modify_files:
|
||||||
modify_files.append(asset_id)
|
# modify_files.append(asset_id)
|
||||||
|
|
||||||
|
#获取git 提交来得到修改的关卡
|
||||||
|
generateLevelIdListByGitLog()
|
||||||
|
if len(_levelModifiedIdList_) <= 0:
|
||||||
|
config.notification_helper.append_msg('没有需要构建的资源')
|
||||||
|
else:
|
||||||
|
modify_files = _levelModifiedIdList_
|
||||||
print(f"modify_files = {modify_files}")
|
print(f"modify_files = {modify_files}")
|
||||||
# alert.alert(f"构建资源列表:{str(modify_files)}")
|
# alert.alert(f"构建资源列表:{str(modify_files)}")
|
||||||
tmstp1 = time.time()
|
tmstp1 = time.time()
|
||||||
|
|
@ -216,8 +352,9 @@ if __name__ == '__main__':
|
||||||
tmstp2 = time.time()
|
tmstp2 = time.time()
|
||||||
print(f"{len(modify_files)}个资源, 解析psd耗时:{tmstp2 - tmstp1}")
|
print(f"{len(modify_files)}个资源, 解析psd耗时:{tmstp2 - tmstp1}")
|
||||||
config.notification_helper.append_msg(f"解析{len(modify_files)}个psd资源耗时:{(tmstp2 - tmstp1):.0f}s")
|
config.notification_helper.append_msg(f"解析{len(modify_files)}个psd资源耗时:{(tmstp2 - tmstp1):.0f}s")
|
||||||
|
# endregion
|
||||||
|
|
||||||
# 建立需要打包的资源软连接
|
# region 建立需要打包的资源软连接
|
||||||
metas = []
|
metas = []
|
||||||
for asset_id in modify_files:
|
for asset_id in modify_files:
|
||||||
asset_gameplay = None
|
asset_gameplay = None
|
||||||
|
|
@ -254,8 +391,9 @@ if __name__ == '__main__':
|
||||||
else:
|
else:
|
||||||
metas.append(["Thum/{}".format(asset_gameplay), dest])
|
metas.append(["Thum/{}".format(asset_gameplay), dest])
|
||||||
print(f"{asset_gameplay}玩法,{asset_id}资源建立软链接")
|
print(f"{asset_gameplay}玩法,{asset_id}资源建立软链接")
|
||||||
|
# endregion
|
||||||
|
|
||||||
# 获取资源不同点个数
|
# region 获取资源不同点个数
|
||||||
asset_find_num_dict = {}
|
asset_find_num_dict = {}
|
||||||
for asset_id in modify_files:
|
for asset_id in modify_files:
|
||||||
asset_gameplay = None
|
asset_gameplay = None
|
||||||
|
|
@ -277,8 +415,9 @@ if __name__ == '__main__':
|
||||||
print(f"关卡资源ID asset_gameplay:{asset_gameplay},asset_id={asset_id} 不存在titem目录")
|
print(f"关卡资源ID asset_gameplay:{asset_gameplay},asset_id={asset_id} 不存在titem目录")
|
||||||
asset_find_num_dict[asset_id] = find_num
|
asset_find_num_dict[asset_id] = find_num
|
||||||
print(f"关卡资源ID asset_id = {asset_id}, 寻找物品个数find_num = {find_num}")
|
print(f"关卡资源ID asset_id = {asset_id}, 寻找物品个数find_num = {find_num}")
|
||||||
|
# endregion
|
||||||
|
|
||||||
# 开始打包
|
# region 开始打包 以及上传资源
|
||||||
tmBuildPackage1 = time.time()
|
tmBuildPackage1 = time.time()
|
||||||
is_build_success, ab_path = build_package(opts, modify_files)
|
is_build_success, ab_path = build_package(opts, modify_files)
|
||||||
tmBuildPackage2 = time.time()
|
tmBuildPackage2 = time.time()
|
||||||
|
|
@ -299,12 +438,14 @@ if __name__ == '__main__':
|
||||||
tmUpdateSheet2 = time.time()
|
tmUpdateSheet2 = time.time()
|
||||||
config.notification_helper.append_msg(f"{opts.platform}平台所有资源表更新完成!")
|
config.notification_helper.append_msg(f"{opts.platform}平台所有资源表更新完成!")
|
||||||
print(f"{len(modify_files)}个资源, 更新文档耗时:{tmUpdateSheet2 - tmUpdateSheet1}")
|
print(f"{len(modify_files)}个资源, 更新文档耗时:{tmUpdateSheet2 - tmUpdateSheet1}")
|
||||||
|
# endregion
|
||||||
|
|
||||||
# 打包完成后,将meta文件保存到opts.resources
|
# region 打包完成后,将meta文件保存到opts.resources
|
||||||
for meta in metas:
|
for meta in metas:
|
||||||
print(f"meta = {meta}")
|
print(f"meta = {meta}")
|
||||||
print(f"copy {meta[1]} to {os.path.join(opts.resources, 'Raw', meta[0])}")
|
print(f"copy {meta[1]} to {os.path.join(opts.resources, 'Raw', meta[0])}")
|
||||||
shutil.copy(meta[1], os.path.join(opts.resources, 'Raw', meta[0]))
|
shutil.copy(meta[1], os.path.join(opts.resources, 'Raw', meta[0]))
|
||||||
|
# endregion
|
||||||
|
|
||||||
config.notification_helper.append_end_msg()
|
config.notification_helper.append_end_msg()
|
||||||
alert.alert(config.notification_helper.get_msg(), config.notification_helper.get_people_list())
|
alert.alert(config.notification_helper.get_msg(), config.notification_helper.get_people_list())
|
||||||
|
|
|
||||||
|
|
@ -71,5 +71,26 @@ meta_spriteatlas = 'spriteatlas'
|
||||||
meta_hash = 'hash'
|
meta_hash = 'hash'
|
||||||
meta_md5 = 'md5'
|
meta_md5 = 'md5'
|
||||||
|
|
||||||
|
# 机器环境配置
|
||||||
|
class machine_env_config(enum.Enum):
|
||||||
|
# 成都MacStudio打包机
|
||||||
|
CD_MAC_STUDIO = {
|
||||||
|
# differences工程环境路径
|
||||||
|
"workspace_path": "/Volumes/Predator/find-vertical",
|
||||||
|
# unity安装路径
|
||||||
|
"unity_install_path": "/Applications/Unity/Hub/Editor/2020.3.32f1/Unity.app/Contents/MacOS/Unity",
|
||||||
|
}
|
||||||
|
Local_Path = {
|
||||||
|
"workspace_path": "/Users/a0729/gogs.git",
|
||||||
|
"unity_install_path": "/Applications/Unity/Hub/Editor/2021.3.32f1/Unity.app/Contents/MacOS/Unity",
|
||||||
|
}
|
||||||
|
|
||||||
|
def getArtProjPath(env: machine_env_config):
|
||||||
|
return env['workspace_path'] + '/find-vertical-art'
|
||||||
|
|
||||||
|
def getAssetsBuildProjPath(env: machine_env_config):
|
||||||
|
return env['workspace_path'] + '/find-vertical-bundle-builder'
|
||||||
|
|
||||||
|
def getUnityProjPath(env: machine_env_config):
|
||||||
|
return getAssetsBuildProjPath(env) + '/find-vertical-bundle-resource'
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue