@@ -111,7 +111,7 @@ def __build_addon(packet: str, addon: str, time_tag: str) -> None:
111111 return
112112 # 新增模块:增加计数,生成临时文件
113113 file_count += 1
114- source_file : str = os .path .join (addon , parts [1 ])
114+ source_file : str = os .path .join (addon , parts [1 ]. replace ( " \\ " , "/" ) )
115115 dist_file : str = os .path .join (dist_dir , f"{ file_count } .lua" )
116116 try :
117117 source_code : str = codecs .open (
@@ -469,13 +469,23 @@ def pathToModule(path: str) -> str:
469469
470470 print ("--------------------------------" )
471471 print ("正在压缩打包..." )
472- # 调用系统命令压缩包(通过 start /wait 保证依次完成)
473- cmd : str = (
474- 'cd ./!src-dist/dist && start /wait /b ../bin/7z.exe a -t7z "'
475- + file_name
476- + '" -xr!manifest.dat -xr!manifest.key -xr!publisher.key -x@.7zipignore'
477- + cmd_suffix
478- )
472+ # 调用系统命令压缩包
473+ if os .name == "nt" :
474+ # Windows: 使用7z.exe命令(通过 start /wait 保证依次完成)
475+ cmd : str = (
476+ 'cd ./!src-dist/dist && start /wait /b ../bin/7z.exe a -t7z "'
477+ + file_name
478+ + '" -xr!manifest.dat -xr!manifest.key -xr!publisher.key -x@.7zipignore'
479+ + cmd_suffix
480+ )
481+ else :
482+ # Linux/macOS: 使用7z命令
483+ cmd : str = (
484+ 'cd ./!src-dist/dist && 7z a -bb0 -bd -bso0 -t7z "'
485+ + file_name
486+ + '" -xr!manifest.dat -xr!manifest.key -xr!publisher.key -x@.7zipignore'
487+ + cmd_suffix
488+ )
479489 os .system (cmd )
480490 print (f'压缩打包完成:"{ file_name } "。' )
481491 if base_hash :
@@ -484,10 +494,88 @@ def pathToModule(path: str) -> str:
484494 print ("全量打包。" )
485495
486496
497+ def __lint (packet : str , packet_path : str , diff_version : Optional [str ] = None ) -> None :
498+ """
499+ 代码检查
500+ """
501+ # 获取当前版本信息
502+ version_info : Dict [str , str ] = __get_version_info (packet , diff_version )
503+ utils .assert_exit (
504+ version_info .get ("current" ) != "" ,
505+ "错误:无法获取当前版本信息,请检查 Base.lua 文件!" ,
506+ )
507+ print (f"当前版本:{ version_info .get ('current' )} " )
508+ print (f"当前提交 hash:{ version_info .get ('current_hash' )} " )
509+ print (f"历史最大版本:{ version_info .get ('max' )} " )
510+ print (f"上一版本:{ version_info .get ('previous' )} " )
511+ print (f"上一版本提交信息:{ version_info .get ('previous_message' )} " )
512+ print (f"上一版本提交 hash:{ version_info .get ('previous_hash' )} " )
513+
514+ # 执行代码检查
515+ # 从上一版本(如果不存在则从最早commit开始)检查 commit message 是否符合规范
516+ print ("\n 正在检查提交信息规范..." )
517+
518+ # 获取起始commit hash
519+ start_hash = version_info .get ("previous_hash" ) or ""
520+ if not start_hash :
521+ # 如果没有上一版本,则获取3个月内最老的commit的hash
522+ start_hash = (
523+ os .popen (
524+ 'git log --since="3 months ago" --format="%H" --reverse | head -n 1'
525+ )
526+ .read ()
527+ .strip ()
528+ )
529+ if not start_hash :
530+ # 如果3个月内没有commit,则获取最新的commit hash
531+ start_hash = os .popen ("git rev-parse HEAD" ).read ().strip ()
532+
533+ # 获取从起始commit到当前的所有commit信息
534+ commits = (
535+ os .popen (f'git log { start_hash } ..HEAD --pretty=format:"%h|%s"' )
536+ .read ()
537+ .strip ()
538+ .split ("\n " )
539+ )
540+
541+ # 定义conventional commit的正则表达式
542+ commit_pattern = re .compile (
543+ r"^(feat|fix|docs|style|refactor|perf|test|chore|build|release)(\([^)]+\))?: .+"
544+ )
545+
546+ has_invalid = False
547+ invalid_commits = []
548+ for commit in commits :
549+ if not commit :
550+ continue
551+ hash_msg = commit .split ("|" )
552+ if len (hash_msg ) != 2 :
553+ continue
554+
555+ commit_hash , message = hash_msg
556+ # 忽略 merge commits
557+ if message .startswith ("Merge " ):
558+ continue
559+
560+ if not commit_pattern .match (message ):
561+ invalid_commits .append (f" - { commit_hash } : { message } " )
562+ has_invalid = True
563+
564+ if has_invalid :
565+ print ("\n 不规范的提交信息:" )
566+ for invalid_commit in invalid_commits :
567+ print (invalid_commit )
568+ utils .exit_with_message (
569+ "\n 错误:存在不符合规范的提交信息!\n 提交信息必须符合格式:<type>[optional scope]: <description>\n 其中type必须是:feat|fix|docs|style|refactor|perf|test|chore|build|release"
570+ )
571+ else :
572+ print ("\n 提交信息规范检查通过!" )
573+
574+
487575def __prepublish (packet : str , packet_path : str , diff_ver : Optional [str ] = None ) -> None :
488576 """
489577 发布前准备工作:
490- - 如果当前在master分支,切换至stable分支、rebse主分支变动并重置提交信息 ;
578+ - 如果当前在master分支,切换至stable分支、rebase主分支变动并重置提交信息 ;
491579 - 如果当前在stable分支且存在未提交变更,则提交release信息;
492580 - 确保工作区干净且当前分支为stable。
493581
@@ -545,11 +633,22 @@ def __pack(packet: str, packet_path: str, version_info: Dict[str, str]) -> None:
545633 time_tag = git .get_head_time_tag ()
546634
547635 # 根据运行环境确定压缩包输出目录
548- dist_root : str = os .path .abspath (os .path .join (get_interface_path (), os .pardir ))
549- if os .path .isfile (os .path .abspath (os .path .join (dist_root , "gameupdater.exe" ))):
550- dist_root = os .path .join (packet_path , "!src-dist" , "dist" )
636+ interface_path = get_interface_path ()
637+ if interface_path is None :
638+ dist_root = os .path .join (
639+ os .path .abspath (__file__ ),
640+ os .pardir ,
641+ os .pardir ,
642+ os .pardir ,
643+ "!src-dist" ,
644+ "dist" ,
645+ )
551646 else :
552- dist_root = os .path .abspath (os .path .join (dist_root , os .pardir , "dist" ))
647+ dist_root : str = os .path .abspath (os .path .join (get_interface_path (), os .pardir ))
648+ if os .path .isfile (os .path .abspath (os .path .join (dist_root , "gameupdater.exe" ))):
649+ dist_root = os .path .join (packet_path , "!src-dist" , "dist" )
650+ else :
651+ dist_root = os .path .abspath (os .path .join (dist_root , os .pardir , "dist" ))
553652
554653 # 如果存在上一个版本,则生成差异包
555654 if version_info .get ("previous_hash" ):
@@ -616,11 +715,16 @@ def run(mode: str, diff_ver: Optional[str] = None, is_source: bool = False) -> N
616715 if mode == "publish" :
617716 __prepublish (packet , packet_path , diff_ver )
618717
718+ if mode == "publish" or mode == "ci" :
719+ __lint (packet , packet_path , diff_ver )
720+
619721 # 执行整体构建打包流程
620722 __build (packet )
621723
622- if mode == "publish" :
724+ if mode == "publish" or mode == "ci" :
623725 __pack (packet , packet_path , version_info )
726+
727+ if mode == "publish" :
624728 os .system ("git checkout master" )
625729
626730 print ("--------------------------------" )
0 commit comments