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
# File 'lib/easyci/command/unitydraw.rb', line 26

def run
  puts "开始Unity项目绘制流程..." 
  
  work_dir = File.expand_path('~/gitee_draw')
  gitee_repo = ENV['GITEE_REPO'] || 'fundesignexport/MagicSortDemoDesignExport'
  gitee_branch = ENV['GITEE_BRANCH'] || 'master'

  # 如果未提供runner-repo参数,使用默认值
  @runner_repo ||= ENV['GITEE_REPO'] || 'bestwebprimary/FGUIWorkRunner'

  if gitee_repo.empty? || gitee_branch.empty?
    puts "GITEE_REPO 和 GITEE_BRANCH 不能为空"
    exit 1
  end

  
  puts "gitee_repo: #{gitee_repo}"
  puts "gitee_branch: #{gitee_branch}"
  puts "work_dir: #{work_dir}"

  # 清理工作目录
  FileUtils.mkdir_p(work_dir)
  runner_dir = File.join(work_dir, 'FGUIWorkRunner')
  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 #{gitee_branch} #{git_url} FGUIWorkRunner")
  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
  puts "下载截图仓库..." 
  git_url = @use_https ? "https://gitee.com/#{gitee_repo}.git" : "[email protected]:#{gitee_repo}.git"
  puts "git_url: #{git_url}"
  clone_result = system("cd #{runner_dir} && git clone --depth 1 -b #{gitee_branch} #{git_url} Assets/Resources")

  unless clone_result
    puts "克隆Assets仓库失败,请检查网络和权限设置"
    exit 1
  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 && 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