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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# 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
ssh_host_gitee = 'gitee.com'
if !gitee_repo.empty? && gitee_repo.start_with?('fundesignexport')
ssh_host_gitee = 'gitee-fununitydraw'
elsif !gitee_repo.empty? && gitee_repo.start_with?('gooddesignexport')
ssh_host_gitee = 'gitee-joyunitydraw'
else
ssh_host_gitee = 'gitee.com'
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 ||= 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" : "git@#{ssh_host_gitee}:#{@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" : "git@#{ssh_host_gitee}:#{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'))
languages_path = File.join(gitee_repo_local_path, 'Common/Language')
if Dir.exist?(languages_path)
FileUtils.cp_r(languages_path, resources_dir)
else
puts "⚠️ 跳过复制:#{languages_path} 不存在"
end
else
FileUtils.mv(File.join(gitee_repo_local_path, 'Resources'), resources_dir)
end
fgui_dir = File.join(resources_dir, 'FGUI')
if File.exist?(File.join(fgui_dir, 'Code'))
FileUtils.rm_rf(File.join(fgui_dir, 'Code'))
end
unity_path = find_unity_path(runner_dir)
puts "运行Unity截图任务..."
FileUtils.chdir(runner_dir)
system("mkdir -p ~/UnityTemp && TMPDIR=~/UnityTemp #{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 {} \\;")
puts "运行后处理脚本..."
env_prefixes = ["GITEE_"]
env_flags = ENV
.select { |k, _| env_prefixes.any? { |prefix| k.start_with?(prefix) } }
.map { |k, _| "-e #{k}" }
.join(" ")
= {
"BUILD_FROM_PRO" => gitee_repo_name,
"BUILD_FROM_REPO" => gitee_repo
}
.each { |k, v| ENV[k] = v }
cmd = <<~CMD
cd #{runner_dir} && \
docker run --rm #{env_flags} \
-v "$(pwd):/app" \
-w /app \
node:22.0.0 bash -c "cd Scripts && yarn install && npx ts-node index.ts"
CMD
system(cmd)
puts "执行命令:\n#{cmd}"
end
|