-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
executable file
·244 lines (161 loc) · 7.18 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
require 'fileutils'
require_relative 'common'
require_relative 'git_hub'
require_relative 'git_repo'
require_relative 'credentials'
require_relative 'unity_project'
require_relative 'platform'
include Builder
namespace :builder do
task :init do
$builder_publish_unity = resolve_path Platform.unity_publish
$builder_git_repo = 'https://github.com/SpaceMadness/lunar-unity-console.git'
$builder_git_branch = 'develop'
$builder_git_repo_publisher = 'https://github.com/SpaceMadness/lunar-unity-console-publisher.git'
$builder_git_branch_publisher = 'master'
$builder_dir_temp = File.expand_path 'temp'
$builder_dir_packages = "#{$builder_dir_temp}/packages"
$builder_dir_publisher = "#{$builder_dir_temp}/publisher"
$builder_dir_samples = "#{$builder_dir_temp}/samples"
$builder_dir_repo = "#{$builder_dir_temp}/repo"
$builder_dir_test_project = File.expand_path 'TestProject'
$builder_dir_repo_project = "#{$builder_dir_repo}/Project"
$builder_dir_repo_project_plugin = "#{$builder_dir_repo_project}/Assets/LunarConsole"
$builder_dir_tools = resolve_path File.expand_path('tools')
$builder_dir_tools_copyrighter = resolve_path "#{$builder_dir_tools}/copyrighter"
end
task :clean => [:init] do
FileUtils.rmtree $builder_dir_temp
end
task :free do
$plugin_configuration = 'free'
end
task :full do
$plugin_configuration = 'full'
end
task :clone_repo => [:init] do
# cleanup
FileUtils.rmtree $builder_dir_repo
# clone
GitRepo.clone $builder_git_repo, $builder_git_branch, $builder_dir_repo
end
task :resolve_version => [:init] do
def extract_package_version(dir_project)
file_version = resolve_path "#{dir_project}/Scripts/Constants.cs"
source = File.read file_version
source =~ /Version\s+=\s+"(\d+\.\d+.\d+\w?)"/
return not_nil $1
end
$package_version = extract_package_version(resolve_path $builder_dir_repo_project_plugin)
print_header "Package version: #{$package_version}"
end
task :fix_projects => [:init, :resolve_version] do
Dir.chdir $builder_dir_repo do
files = []
# copyrights
files = files.concat fix_copyrights(
resolve_path($builder_dir_repo),
$builder_dir_tools_copyrighter,
:types => ['.cs', '.h', '.m', '.mm', '.c', '.cpp', '.java'],
:ignored_files => [ 'Plist.cs', 'XCodeEditor-for-Unity', 'SimpleJSON.cs' ]
)
# push changes
GitRepo.commit_and_push($builder_dir_repo, $builder_git_branch, "Updated copyrights", files) if files.length > 0
end
end
desc 'Build package on existing source'
task :build_package_no_clean => [:init] do
# call internal builder
dir_builder = resolve_path "#{$builder_dir_repo}/Builder"
Dir.chdir dir_builder do
load File.expand_path 'Rakefile'
Rake::Task["lunar:export_unity_package_#{$plugin_configuration}"].invoke
end
file_package = resolve_path Dir["#{$builder_dir_repo}/Builder/temp/packages/lunar-console-*.unitypackage"].first
FileUtils.rm_rf $builder_dir_packages
FileUtils.makedirs $builder_dir_packages
FileUtils.cp file_package, "#{$builder_dir_packages}/"
end
task :build_package => [:clean, :clone_repo, :fix_projects, :build_package_no_clean]
desc 'Clean up test project'
task :clean_test_project => [:init] do
print_header 'Clean up project...'
Dir.chdir $builder_dir_test_project do
exec_shell 'git clean -x -f -d', "Can't clean project"
end
exec_shell "git checkout -- \"#{$builder_dir_test_project}\"", "Can't reset project"
end
desc 'Prepare test project'
task :prepare_test_project => [:clean_test_project] do
file_package = resolve_path Dir["#{$builder_dir_packages}/lunar-console-*.unitypackage"].first
project = UnityProject.new $builder_dir_test_project
print_header 'Importing package...'
project.import_package file_package
print_header 'Integrating package...'
project.exec_unity_method 'LunarConsoleBuilder.Builder.IntegratePlugin'
print_header 'Enabling package...'
project.exec_unity_method 'LunarConsoleEditorInternal.Installer.EnablePlugin'
end
desc 'Builds test project'
task :build_test_project => [:build_package, :prepare_test_project] do
project = UnityProject.new $builder_dir_test_project
print_header 'Exporting apps...'
project.exec_unity_method 'LunarConsoleBuilder.Builder.BuildAll'
ios_app = resolve_path build_ios_app("#{$builder_dir_test_project}/Build/iOS", 'Unity-iPhone', 'Release', 'Unity-iPhone')
android_app = resolve_path Dir["#{$builder_dir_test_project}/Build/Android/*.apk"].first
FileUtils.rm_rf $builder_dir_samples
FileUtils.mkpath $builder_dir_samples
FileUtils.cp_r ios_app, "#{$builder_dir_samples}/"
FileUtils.cp_r android_app, "#{$builder_dir_samples}/"
end
task :prepare_publisher_project => [:build_package] do
package = resolve_path Dir["#{$builder_dir_packages}/lunar-console-*.unitypackage"].first
print_header 'Cloning publisher project...'
GitRepo.clone $builder_git_repo_publisher, $builder_git_branch_publisher, $builder_dir_publisher
print_header 'Preparing publisher project...'
# import plugin package
project = UnityProject.new $builder_dir_publisher, $builder_publish_unity
project.import_package package
# copy readme
readme_src = resolve_path 'package_readme.txt'
readme_dst = "#{$builder_dir_publisher}/Assets/LunarConsole/readme.txt"
FileUtils.cp readme_src, readme_dst
project.open
end
desc 'Prepares publisher project for FREE release'
task :prepare_publisher_project_free => [:free, :prepare_publisher_project]
desc 'Prepares publisher project for FULL release'
task :prepare_publisher_project_full => [:full, :prepare_publisher_project]
desc 'Release package'
task :release_package => [:free, :build_package] do
file_package = resolve_path Dir["#{$builder_dir_packages}/lunar-console-*.unitypackage"].first
# Merge changes to master
GitRepo.git_merge $builder_dir_repo, $builder_git_branch, 'master'
# Create release
github_create_release $builder_dir_repo, $package_version, file_package
end
def github_create_release(dir_repo, version, package_zip)
fail_script_unless_file_exists dir_repo
fail_script_unless_file_exists package_zip
# extracting changelog
release_notes = get_release_notes dir_repo, @version
# preparing release commit
repo = GitRepo.new dir_repo
release_name = "Lunar Console v#{version}"
release_tag = version
print_header 'Creating release tag...'
repo.tag release_tag
repo.push 'master', tags: true
# creating pull request
print_header 'Creating draft GitHub release...'
GitHub.create_release dir_repo, release_tag, release_name, release_notes, File.expand_path(package_zip)
end
############################################################
def git_get_repo_name(dir_repo)
Dir.chdir dir_repo do
file_config = '.git/config'
config = File.read file_config
return extract_regex config, %r#url = git@github\.com:.*?/(.*?).git#
end
end
end