Class: EasyCI::Command::Unitydraw

Inherits:
EasyCI::Command show all
Defined in:
lib/easyci/command/unitydraw.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Unitydraw

Returns a new instance of Unitydraw.



16
17
18
19
20
# File 'lib/easyci/command/unitydraw.rb', line 16

def initialize(argv)
  super
  @runner_repo = argv.option('runner-repo')
  @use_https = argv.flag?('https', false)
end

Class Method Details

.optionsObject



9
10
11
12
13
14
# File 'lib/easyci/command/unitydraw.rb', line 9

def self.options
  [
    ['--runner-repo=REPO', 'Runner仓库路径,例如:mygroup/FGUIWorkRunner'],
    ['--https', '使用HTTPS方式克隆仓库,默认使用SSH方式'],
  ].concat(super)
end

Instance Method Details

#runObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/easyci/command/unitydraw.rb', line 26

def run
  puts "开始Unity项目绘制流程..." 
  
  gitee_draw_dir = File.expand_path('~/Documents/gitee_draw')
  FileUtils.mkdir_p(gitee_draw_dir)

  gitee_repo = ENV['GITEE_REPO'] || 'fundesignexport/MagicSortDemoDesignExport'
  gitee_repo_name = gitee_repo.split('/').last
  gitee_branch = ENV['GITEE_BRANCH'] || 'master'
  if gitee_repo.empty? || gitee_branch.empty?
    puts "GITEE_REPO 和 GITEE_BRANCH 不能为空"
    exit 1
  end

  work_dir = File.join(gitee_draw_dir, gitee_repo_name)
  if File.exist?(work_dir)
    FileUtils.rm_rf(work_dir)
  end
  FileUtils.mkdir_p(work_dir)
  
  # 如果未提供runner-repo参数,使用默认值
  @runner_repo ||= ENV['RUNNER_REPO'] || 'bestwebprimary/FGUIWorkRunner'
  runner_branch = ENV['RUNNER_BRANCH'] ||'master'
  if @runner_repo.empty? || gitee_branch.empty?
    puts "RUNNER_REPO 和 RUNNER_BRANCH 不能为空"
    exit 1
  end
  runner_repo_name = @runner_repo.split('/').last
  

  puts "@runner_repo: #{@runner_repo}"
  puts "runner_repo_name: #{runner_repo_name}"
  puts "runner_branch: #{@runner_branch}"
  puts "gitee_repo: #{gitee_repo}"
  puts "gitee_repo_name: #{gitee_repo_name}"
  puts "gitee_branch: #{gitee_branch}"
  puts "work_dir: #{work_dir}"

  # 清理工作目录
  
  runner_dir = File.join(work_dir, runner_repo_name)
  FileUtils.rm_rf(runner_dir) if File.exist?(runner_dir)
  git_url = @use_https ? "https://gitee.com/#{@runner_repo}.git" : "[email protected]:#{@runner_repo}.git"
  puts "git_url: #{git_url}"
  clone_runner_result = system("cd #{work_dir} && git clone --depth 1 -b #{runner_branch} #{git_url} #{runner_repo_name}")
  unless clone_runner_result
    puts "克隆Runner仓库失败,请检查网络和权限设置"
    exit 1
  end
  unless File.exist?(runner_dir)
    puts "Runner目录不存在,克隆可能失败"
    exit 1
  end
  
  FileUtils.chdir(runner_dir)
  resources_dir = File.join(runner_dir, 'Assets/Resources')
  if File.exist?(resources_dir)
    FileUtils.rm_rf(resources_dir)
  end
  FileUtils.mkdir_p(File.join(runner_dir, 'Assets'))
  puts "下载截图仓库..." 
  git_url = @use_https ? "https://gitee.com/#{gitee_repo}.git" : "[email protected]:#{gitee_repo}.git"
  puts "git_url: #{git_url}"
  gitee_repo_local_path = File.join(work_dir, gitee_repo_name)
  FileUtils.rm_rf(gitee_repo_local_path) if File.exist?(gitee_repo_local_path)
  clone_result = system("cd #{work_dir} && git clone --depth 1 -b #{gitee_branch} #{git_url} #{gitee_repo_name}")

  unless clone_result
    puts "克隆Assets仓库失败,请检查网络和权限设置"
    exit 1
  end
  
  if !File.exist?(File.join(gitee_repo_local_path, 'Resources'))
    FileUtils.mkdir_p(resources_dir)
    FileUtils.cp_r(File.join(gitee_repo_local_path, '2D', '.'), resources_dir)
    FileUtils.cp_r(File.join(gitee_repo_local_path, 'Common/Font'), File.join(resources_dir, 'Fonts'))
  else
    FileUtils.mv(File.join(gitee_repo_local_path, 'Resources'), resources_dir)
  end

  # 运行Unity截图任务
  unity_path = find_unity_path(runner_dir)
  puts "运行Unity截图任务..." 
  FileUtils.chdir(runner_dir)
  system("#{unity_path} -projectPath  #{runner_dir} -executeMethod SpineAutoImporter.CIRunner -logFile screenshot-log.txt")
  
  # 压缩截图
  puts "开始压缩截图..." 
  system("cd #{runner_dir} && find . -path \"*/Screenshots/*.png\" -exec pngquant --quality=70-95 --ext .png --force {} \\;")
  # 运行Node脚本(如果需要)
  puts "运行后处理脚本..."
  system("cd #{runner_dir} && docker run --rm -v \"$(pwd):/app\" -w /app node:22.0.0 bash -c \"cd Scripts && export BUILD_FROM_PRO=#{gitee_repo_name} && yarn install && npx ts-node index.ts\"")
  
end

#validate!Object



22
23
24
# File 'lib/easyci/command/unitydraw.rb', line 22

def validate!
  super
end