-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
179 lines (122 loc) · 4.19 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
require_relative 'common'
require_relative 'git'
require_relative 'credentials'
task :init do
$git_repo = '[email protected]:SpaceMadness/lunar-unity-plugin.git'
$git_branch = 'develop'
$dir_temp = File.expand_path 'temp'
$dir_repo = "#{$dir_temp}/repo"
$dir_repo_project = "#{$dir_repo}/Project"
$dir_tools = resolve_path File.expand_path('tools')
$dir_tools_copyrighter = resolve_path "#{$dir_tools}/copyrighter"
end
task :clean => [:init] do
FileUtils.rmtree $dir_temp
end
task :clone_repo => [:init] do
# cleanup
FileUtils.rmtree $dir_repo
# clone
Git.clone $git_repo, $git_branch, $dir_repo
end
task :resolve_version => [:init] do
def extract_package_version(dir_project)
file_version = resolve_path "#{dir_project}/Assets/LunarPlugin/Scripts/CVersion.cs"
source = File.read file_version
source =~ /VERSION\s+=\s+"(\d+\.\d+.\d+b?)"/
return not_nil $1
end
$package_version = extract_package_version(resolve_path $dir_repo_project)
print_header "Package version: #{$package_version}"
end
task :fix_projects => [:init, :resolve_version] do
Dir.chdir $dir_repo do
files = []
# copyrights
files = files.concat fix_copyrights(resolve_path($dir_repo_project), $dir_tools_copyrighter)
# push changes
Git.commit_and_push $dir_repo, $git_branch, files if files.length > 0
end
end
desc 'Release package'
task :release_package => [:clean, :clone_repo, :fix_projects] do
# call internal builder
dir_builder = resolve_path "#{$dir_repo}/Builder"
Dir.chdir dir_builder do
load File.expand_path 'Rakefile'
Rake::Task['lunar:export_unity_package'].invoke
end
file_package = resolve_path Dir["#{$dir_repo}/Builder/temp/packages/lunar-*.unitypackage"].first
# Merge changes to master
Git.git_merge $dir_repo, $git_branch, 'master'
# Create release
github_create_release $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
github_release_bin = resolve_path "#{$dir_tools}/github/github-release"
Dir.chdir dir_repo do
name = "SDK v#{version}"
tag = version
repo_name = git_get_repo_name '.'
fail_script_unless repo_name, "Unable to extract repo name: #{dir_repo}"
# delete old release
cmd = %("#{github_release_bin}" delete)
cmd << %( -s #{$github_access_token})
cmd << %( -u #{$github_owner})
cmd << %( -r #{repo_name})
cmd << %( -t "#{tag}")
exec_shell cmd, "Can't remove old release", :dont_fail_on_error => true
# create a release
release_notes_strings = get_release_notes dir_repo, version
release_notes = release_notes_strings.join('')
cmd = %("#{github_release_bin}" release)
cmd << %( -s #{$github_access_token})
cmd << %( -u #{$github_owner})
cmd << %( -r #{repo_name})
cmd << %( -t "#{tag}")
cmd << %( -n "#{name}")
cmd << %( -d "#{release_notes}")
exec_shell cmd, "Can't push release"
# uploading package
cmd = %("#{github_release_bin}" upload)
cmd << %( -s #{$github_access_token})
cmd << %( -u #{$github_owner})
cmd << %( -r #{repo_name})
cmd << %( -t "#{tag}")
cmd << %( -n "#{File.basename(package_zip)}")
cmd << %( -f "#{File.expand_path(package_zip)}")
exec_shell cmd, "Can't upload package asset"
end
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
############################################################
def get_release_notes(dir_repo, version)
Dir.chdir dir_repo do
file_release_notes = 'CHANGELOG.md'
fail_script_unless_file_exists file_release_notes
lines = File.readlines file_release_notes
notes = []
block_found = false
lines.each { |line|
if (block_found)
if (line.start_with? '*')
notes.push line
elsif line.start_with? '##'
break
end
elsif line.start_with? "## v#{version}"
block_found = true
end
}
return notes
end
end