-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathrakefile.rb
177 lines (147 loc) · 5.39 KB
/
rakefile.rb
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 'open-uri'
require 'openssl'
require_relative 'scripts/utils'
require_relative 'scripts/wix'
require_relative 'scripts/copy-dependencies'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
MANUFACTURER = 'Open Systems Pharmacology'
PRODUCT_NAME = "#{MANUFACTURER} Suite"
GITHUB_NAME = 'open-systems-pharmacology'
APPVEYOR_ACCOUNT_NAME = 'open-systems-pharmacology-ci'
VARIABLES = {}
MSI = {}
desc "Create suite setup"
task :create_setup,[:product_version, :branch_name] do |t, args|
@product_version = args.product_version
@branch_name = args.branch_name || 'develop'
release_version_split = @product_version.split('.')
@product_release_version = "#{release_version_split[0]}.#{release_version_split[1]}"
@product_full_version = "#{@product_release_version}.#{release_version_split[2]}"
@product_full_name = "#{PRODUCT_NAME} #{@product_full_version}"
VARIABLES[:ProductName] = PRODUCT_NAME
VARIABLES[:Manufacturer] = MANUFACTURER
VARIABLES[:ProductFullName] = @product_full_name
VARIABLES[:ProductVersion] = @product_version
VARIABLES[:ProductFullVersion] = @product_full_version
MSI[:pksim] = create_package('pk-sim', 'PK-Sim')
MSI[:mobi] = create_package('mobi', 'MoBi')
MSI[:validator] = create_package('installationvalidator', 'InstallationValidator')
Rake::Task['downlad_all_packages'].invoke
create_versions_file
create_setup compressed:'no', output_name:'OSPSuite-WebInstall'
create_setup compressed:'yes', output_name:'OSPSuite-Full'
end
def create_versions_file
version_file = File.join(output_dir,'versions.txt')
File.open(version_file, 'w') do |file|
MSI.each do |key, package|
file.puts "#{package[:git_repository]}: #{package[:file_name]}"
end
end
end
def create_package(appveyor_project_name, git_repository, artifact_name: 'setup.zip', version: @product_version, branch: @branch_name, uri:nil)
compressed = artifact_name.include? '.zip'
git_repo = git_repository || appveyor_project_name
return {
appveyor_project_name: appveyor_project_name,
artifact_name: artifact_name,
branch: branch,
compressed: compressed,
git_repository: git_repo,
version: version,
uri:uri
}
end
def run_candle(compressed)
all_variables = VARIABLES.each.collect do |k, v|
"-d#{k}=#{v}"
end
command_line = %W[#{deploy_dir}/bundle.wxs -dCompressed=#{compressed} -ext WixUtilExtension -ext WixNetFxExtension -ext WixBalExtension -o #{deploy_dir}/]
Utils.run_cmd(Wix.candle, command_line + all_variables)
end
desc "Runs the light command that actually creates the msi package"
def run_light(exe)
command_line = %W[#{deploy_dir}/Bundle.wixobj -o #{exe} -nologo -ext WixUIExtension -ext WixNetFxExtension -ext WixBalExtension -spdb -b #{deploy_dir}/ -cultures:en-us]
Utils.run_cmd(Wix.light, command_line)
end
def create_setup(compressed:'yes', output_name:'OSPSuite')
exe = File.join(output_dir,"#{output_name}.#{@product_full_version}.exe")
run_candle compressed
run_light exe
end
desc "Get a file from a remote server"
task :downlad_all_packages => :clean do
threads = MSI.each_key.collect do |msi|
Thread.new(msi) do |_msi|
prepare_msi(_msi)
end
end
threads.map(&:join)
end
desc "cleanup files before starting compilation"
task :clean do
FileUtils.rm_rf deploy_dir
FileUtils.mkdir_p deploy_dir
FileUtils.mkdir_p output_dir
copy_depdencies current_dir, deploy_dir do
copy_files 'setup', '*'
end
end
def prepare_msi(msi)
package = MSI[msi]
file = download package
puts file
package[:file_name] = retrieve_package_name(file, package)
download_path = "https://systems-biology.com/fileadmin/sb_ftp/OSP_Updates/#{package[:file_name]}"
VARIABLES["#{msi}DownloadPath"] = download_path
VARIABLES[msi] = package[:file_name]
end
def download(package)
file_name = package[:artifact_name]
uri = "https://ci.appveyor.com/api/projects/#{APPVEYOR_ACCOUNT_NAME}/#{package[:appveyor_project_name]}/artifacts/#{file_name}?branch=#{package[:branch]}"
#Path of package is predefined. This is typically the case for a hotfix when some packages should be fixed
uri = package[:uri] if package[:uri]
download_file package[:appveyor_project_name], file_name, uri
end
def download_file(project_name, file_name, uri)
download_dir = File.join(deploy_dir, project_name)
FileUtils.mkdir_p download_dir
file = File.join(download_dir, file_name)
puts "Downloading #{file_name} from #{uri} under #{file}"
open(file, 'wb') do |fo|
fo.print open(uri,:read_timeout => nil).read
end
file
end
def retrieve_package_name(package_full_path, package)
compressed = package[:compressed] || false
artifact_name = package[:artifact_name];
#pointing to real package already return
return artifact_name unless compressed
unzip_dir = unzip(package_full_path)
copy_msi_to_deploy unzip_dir
end
#copy all msi packages defined under dir and return the name of the packages found (should only be one)
def copy_msi_to_deploy(dir)
artifact_name = ''
Dir.glob(File.join(dir, '*.msi')) do |x|
copy x, deploy_dir
artifact_name = File.basename(x)
end
artifact_name
end
def unzip(package_full_path)
unzip_dir = File.dirname(package_full_path)
command_line = %W[e #{package_full_path} -o#{unzip_dir}]
Utils.run_cmd('7z', command_line)
unzip_dir
end
def deploy_dir
File.join(current_dir,'deploy')
end
def output_dir
File.join(current_dir,'output')
end
def current_dir
File.dirname(__FILE__)
end