forked from Topshelf/Topshelf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rakefile.rb
342 lines (305 loc) · 17.4 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
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
COPYRIGHT = "Copyright 2012 Chris Patterson, Dru Sellers, Travis Smith, All rights reserved."
require File.dirname(__FILE__) + "/build_support/BuildUtils.rb"
require File.dirname(__FILE__) + "/build_support/util.rb"
include FileTest
require 'albacore'
require File.dirname(__FILE__) + "/build_support/versioning.rb"
PRODUCT = 'Topshelf'
CLR_TOOLS_VERSION = 'v4.0.30319'
OUTPUT_PATH = 'bin/Release'
props = {
:src => File.expand_path("src"),
:nuget => File.join(File.expand_path("src"), ".nuget", "nuget.exe"),
:output => File.expand_path("build_output"),
:artifacts => File.expand_path("build_artifacts"),
:lib => File.expand_path("lib"),
:projects => ["Topshelf"],
:keyfile => File.expand_path("Topshelf.snk")
}
desc "Cleans, compiles, il-merges, unit tests, prepares examples, packages zip"
task :all => [:default, :package]
desc "**Default**, compiles and runs tests"
task :default => [:clean, :nuget_restore, :compile, :package]
desc "Update the common version information for the build. You can call this task without building."
assemblyinfo :global_version do |asm|
# Assembly file config
asm.product_name = PRODUCT
asm.description = "Topshelf is an open source project for hosting services without friction. By referencing Topshelf, your console application *becomes* a service installer with a comprehensive set of command-line options for installing, configuring, and running your application as a service."
asm.version = FORMAL_VERSION
asm.file_version = FORMAL_VERSION
asm.custom_attributes :AssemblyInformationalVersion => "#{BUILD_VERSION}",
:ComVisibleAttribute => false,
:CLSCompliantAttribute => true
asm.copyright = COPYRIGHT
asm.output_file = 'src/SolutionVersion.cs'
asm.namespaces "System", "System.Reflection", "System.Runtime.InteropServices"
end
desc "Prepares the working directory for a new build"
task :clean do
FileUtils.rm_rf props[:output]
waitfor { !exists?(props[:output]) }
FileUtils.rm_rf props[:artifacts]
waitfor { !exists?(props[:artifacts]) }
Dir.mkdir props[:output]
Dir.mkdir props[:artifacts]
end
desc "Cleans, versions, compiles the application and generates build_output/."
task :compile => [:versioning, :global_version, :build4, :tests4, :copy4, :build4un, :copy4un, :build35, :tests35, :copy35]
task :copy35 => [:build35] do
copyOutputFiles File.join(props[:src], "Topshelf/bin/Release/v3.5"), "Topshelf.{dll,pdb,xml}", File.join(props[:output], 'net-3.5')
copyOutputFiles File.join(props[:src], "Topshelf.Log4Net/bin/Release/v3.5"), "Topshelf.Log4Net.{dll,pdb,xml}", File.join(props[:output], 'net-3.5')
copyOutputFiles File.join(props[:src], "Topshelf.NLog/bin/Release/v3.5"), "Topshelf.NLog.{dll,pdb,xml}", File.join(props[:output], 'net-3.5')
copyOutputFiles File.join(props[:src], "Topshelf.Rehab/bin/Release/v3.5"), "Topshelf.Rehab.{dll,pdb,xml}", File.join(props[:output], 'net-3.5')
copyOutputFiles File.join(props[:src], "Topshelf.Supervise/bin/Release/v3.5"), "Topshelf.Supervise.{dll,pdb,xml}", File.join(props[:output], 'net-3.5')
end
task :copy4 => [:build4] do
copyOutputFiles File.join(props[:src], "Topshelf/bin/Release"), "Topshelf.{dll,pdb,xml}", File.join(props[:output], 'net-4.0-full')
copyOutputFiles File.join(props[:src], "Topshelf.Log4Net/bin/Release"), "Topshelf.Log4Net.{dll,pdb,xml}", File.join(props[:output], 'net-4.0-full')
copyOutputFiles File.join(props[:src], "Topshelf.NLog/bin/Release"), "Topshelf.NLog.{dll,pdb,xml}", File.join(props[:output], 'net-4.0-full')
copyOutputFiles File.join(props[:src], "Topshelf.Rehab/bin/Release"), "Topshelf.Rehab.{dll,pdb,xml}", File.join(props[:output], 'net-4.0-full')
copyOutputFiles File.join(props[:src], "Topshelf.Supervise/bin/Release"), "Topshelf.Supervise.{dll,pdb,xml}", File.join(props[:output], 'net-4.0-full')
end
task :copy4un => [:build4un] do
copyOutputFiles File.join(props[:src], "Topshelf.Elmah/bin/Release"), "Topshelf.Elmah.{dll,pdb,xml}", File.join(props[:output], 'net-4.0-full')
copyOutputFiles File.join(props[:src], "Topshelf.Serilog/bin/Release"), "Topshelf.Serilog.{dll,pdb,xml}", File.join(props[:output], 'net-4.0-full')
end
desc "Only compiles the application."
msbuild :build35 do |msb|
msb.properties :Configuration => "Release35",
:Platform => 'Any CPU',
:TargetFrameworkVersion => "v3.5"
msb.use :net4
msb.targets :Rebuild
msb.properties[:SignAssembly] = 'true'
msb.properties[:AssemblyOriginatorKeyFile] = props[:keyfile]
msb.solution = 'src/Topshelf.sln'
end
desc "Only compiles the application."
msbuild :build4 do |msb|
msb.properties :Configuration => "Release",
:Platform => 'Any CPU'
msb.use :net4
msb.targets :Rebuild
msb.properties[:SignAssembly] = 'true'
msb.properties[:AssemblyOriginatorKeyFile] = props[:keyfile]
msb.solution = 'src/Topshelf.sln'
end
desc "Only compiles the application."
msbuild :build4un do |msb|
msb.properties :Configuration => "ReleaseUnsigned",
:Platform => 'Any CPU'
msb.use :net4
msb.targets :Build
msb.solution = 'src/Topshelf.sln'
end
def copyOutputFiles(fromDir, filePattern, outDir)
FileUtils.mkdir_p outDir unless exists?(outDir)
Dir.glob(File.join(fromDir, filePattern)){|file|
copy(file, outDir) if File.file?(file)
}
end
desc "Runs unit tests"
nunit :tests35 => [:build35] do |nunit|
nunit.command = File.join('src', 'packages','NUnit.Runners.2.6.3', 'tools', 'nunit-console.exe')
nunit.parameters = "/framework=#{CLR_TOOLS_VERSION}", '/nothread', '/nologo', '/labels', "\"/xml=#{File.join(props[:artifacts], 'nunit-test-results-net-3.5.xml')}\""
nunit.assemblies = FileList[File.join(props[:src], "Topshelf.Tests/bin/Release", "Topshelf.Tests.dll")]
end
desc "Runs unit tests"
nunit :tests4 => [:build4] do |nunit|
nunit.command = File.join('src', 'packages','NUnit.Runners.2.6.3', 'tools', 'nunit-console.exe')
nunit.parameters = "/framework=#{CLR_TOOLS_VERSION}", '/nothread', '/nologo', '/labels', "\"/xml=#{File.join(props[:artifacts], 'nunit-test-results-net-4.0.xml')}\""
nunit.assemblies = FileList[File.join(props[:src], "Topshelf.Tests/bin/Release", "Topshelf.Tests.dll")]
end
task :package => [:nuget, :zip_output]
desc "ZIPs up the build results."
zip :zip_output => [:versioning] do |zip|
zip.dirs = [props[:output]]
zip.output_path = File.join(props[:artifacts], "Topshelf-#{NUGET_VERSION}.zip")
end
desc "restores missing packages"
msbuild :nuget_restore do |msb|
msb.use :net4
msb.targets :RestorePackages
msb.solution = File.join(props[:src], "Topshelf.Tests", "Topshelf.Tests.csproj")
end
desc "restores missing packages"
msbuild :nuget_restore do |msb|
msb.use :net4
msb.targets :RestorePackages
msb.solution = File.join(props[:src], "Topshelf.Log4Net", "Topshelf.Log4Net.csproj")
end
desc "restores missing packages"
msbuild :nuget_restore do |msb|
msb.use :net4
msb.targets :RestorePackages
msb.solution = File.join(props[:src], "Topshelf.NLog", "Topshelf.NLog.csproj")
end
desc "restores missing packages"
msbuild :nuget_restore do |msb|
msb.use :net4
msb.targets :RestorePackages
msb.solution = File.join(props[:src], "Topshelf.Serilog", "Topshelf.Serilog.csproj")
end
desc "Builds the nuget package"
task :nuget => [:versioning, :create_nuspec] do
sh "#{props[:nuget]} pack #{props[:artifacts]}/Topshelf.nuspec /Symbols /OutputDirectory #{props[:artifacts]}"
sh "#{props[:nuget]} pack #{props[:artifacts]}/Topshelf.Log4Net.nuspec /Symbols /OutputDirectory #{props[:artifacts]}"
sh "#{props[:nuget]} pack #{props[:artifacts]}/Topshelf.NLog.nuspec /Symbols /OutputDirectory #{props[:artifacts]}"
sh "#{props[:nuget]} pack #{props[:artifacts]}/Topshelf.Elmah.nuspec /Symbols /OutputDirectory #{props[:artifacts]}"
sh "#{props[:nuget]} pack #{props[:artifacts]}/Topshelf.Serilog.nuspec /Symbols /OutputDirectory #{props[:artifacts]}"
sh "#{props[:nuget]} pack #{props[:artifacts]}/Topshelf.Rehab.nuspec /Symbols /OutputDirectory #{props[:artifacts]}"
sh "#{props[:nuget]} pack #{props[:artifacts]}/Topshelf.Supervise.nuspec /Symbols /OutputDirectory #{props[:artifacts]}"
end
nuspec :create_nuspec do |nuspec|
nuspec.id = 'Topshelf'
nuspec.version = NUGET_VERSION
nuspec.authors = ['Chris Patterson', 'Dru Sellers', 'Travis Smith']
nuspec.summary = 'Topshelf, Friction-free Windows Services'
nuspec.description = 'Topshelf is an open source project for hosting services without friction. By referencing Topshelf, your console application *becomes* a service installer with a comprehensive set of command-line options for installing, configuring, and running your application as a service.'
nuspec.title = 'Topshelf'
nuspec.project_url = 'http://github.com/Topshelf/Topshelf'
nuspec.icon_url = 'http://topshelf-project.com/wp-content/themes/pandora/slide.1.png'
nuspec.language = "en-US"
nuspec.license_url = "http://www.apache.org/licenses/LICENSE-2.0"
nuspec.require_license_acceptance
nuspec.output_file = File.join(props[:artifacts], 'Topshelf.nuspec')
add_files props[:output], 'Topshelf.{dll,pdb,xml}', nuspec
nuspec.file(File.join(props[:src], "Topshelf\\**\\*.cs").gsub("/","\\"), "src")
end
nuspec :create_nuspec do |nuspec|
nuspec.id = 'Topshelf.Log4Net'
nuspec.version = NUGET_VERSION
nuspec.authors = ['Chris Patterson', 'Dru Sellers', 'Travis Smith']
nuspec.summary = 'Topshelf, Friction-free Windows Services'
nuspec.description = 'Log4Net Logging Integration for Topshelf. Topshelf is an open source project for hosting services without friction. By referencing Topshelf, your console application *becomes* a service installer with a comprehensive set of command-line options for installing, configuring, and running your application as a service.'
nuspec.title = 'Topshelf.Log4Net'
nuspec.project_url = 'http://github.com/Topshelf/Topshelf'
nuspec.icon_url = 'http://topshelf-project.com/wp-content/themes/pandora/slide.1.png'
nuspec.language = "en-US"
nuspec.license_url = "http://www.apache.org/licenses/LICENSE-2.0"
nuspec.require_license_acceptance
nuspec.dependency "Topshelf", NUGET_VERSION
nuspec.dependency "Log4Net", "2.0.4"
nuspec.output_file = File.join(props[:artifacts], 'Topshelf.Log4Net.nuspec')
add_files props[:output], 'Topshelf.Log4Net.{dll,pdb,xml}', nuspec
nuspec.file(File.join(props[:src], "Topshelf.Log4Net\\**\\*.cs").gsub("/","\\"), "src")
end
nuspec :create_nuspec do |nuspec|
nuspec.id = 'Topshelf.NLog'
nuspec.version = NUGET_VERSION
nuspec.authors = ['Chris Patterson', 'Dru Sellers', 'Travis Smith']
nuspec.summary = 'Topshelf, Friction-free Windows Services'
nuspec.description = 'NLog Logging Integration for Topshelf. Topshelf is an open source project for hosting services without friction. By referencing Topshelf, your console application *becomes* a service installer with a comprehensive set of command-line options for installing, configuring, and running your application as a service.'
nuspec.title = 'Topshelf.NLog'
nuspec.project_url = 'http://github.com/Topshelf/Topshelf'
nuspec.icon_url = 'http://topshelf-project.com/wp-content/themes/pandora/slide.1.png'
nuspec.language = "en-US"
nuspec.license_url = "http://www.apache.org/licenses/LICENSE-2.0"
nuspec.require_license_acceptance
nuspec.dependency "Topshelf", NUGET_VERSION
nuspec.dependency "NLog", "4.2.2"
nuspec.output_file = File.join(props[:artifacts], 'Topshelf.NLog.nuspec')
add_files props[:output], 'Topshelf.NLog.{dll,pdb,xml}', nuspec
nuspec.file(File.join(props[:src], "Topshelf.NLog\\**\\*.cs").gsub("/","\\"), "src")
end
nuspec :create_nuspec do |nuspec|
nuspec.id = 'Topshelf.Elmah'
nuspec.version = NUGET_VERSION
nuspec.authors = ['Brian Wilson']
nuspec.summary = 'Topshelf Elmah, Elmah Logging for Topshelf'
nuspec.description = 'Elmah Logging Integration for Topshelf. Topshelf is an open source project for hosting services without friction. By referencing Topshelf, your console application *becomes* a service installer with a comprehensive set of command-line options for installing, configuring, and running your application as a service.'
nuspec.title = 'Topshelf.Elmah'
nuspec.project_url = 'http://github.com/Topshelf/Topshelf'
nuspec.icon_url = 'http://topshelf-project.com/wp-content/themes/pandora/slide.1.png'
nuspec.language = "en-US"
nuspec.license_url = "http://www.apache.org/licenses/LICENSE-2.0"
nuspec.require_license_acceptance
nuspec.dependency "Topshelf", NUGET_VERSION
nuspec.dependency "elmah.corelibrary", "1.2.2"
nuspec.output_file = File.join(props[:artifacts], 'Topshelf.Elmah.nuspec')
add_files props[:output], 'Topshelf.Elmah.{dll,pdb,xml}', nuspec
nuspec.file(File.join(props[:src], "Topshelf.Elmah\\**\\*.cs").gsub("/","\\"), "src")
end
nuspec :create_nuspec do |nuspec|
nuspec.id = 'Topshelf.Serilog'
nuspec.version = NUGET_VERSION
nuspec.authors = ['Mogens Heller Grabe']
nuspec.summary = 'Topshelf Serilog, interfaces to Serilog'
nuspec.description = 'Serilog Integration for Topshelf. Topshelf is an open source project for hosting services without friction. By referencing Topshelf, your console application *becomes* a service installer with a comprehensive set of command-line options for installing, configuring, and running your application as a service.'
nuspec.title = 'Topshelf.Serilog'
nuspec.project_url = 'http://github.com/Topshelf/Topshelf'
nuspec.icon_url = 'http://topshelf-project.com/wp-content/themes/pandora/slide.1.png'
nuspec.language = "en-US"
nuspec.license_url = "http://www.apache.org/licenses/LICENSE-2.0"
nuspec.require_license_acceptance
nuspec.dependency "Topshelf", NUGET_VERSION
nuspec.dependency "Serilog", "1.5.14"
nuspec.output_file = File.join(props[:artifacts], 'Topshelf.Serilog.nuspec')
add_files props[:output], 'Topshelf.Serilog.{dll,pdb,xml}', nuspec
nuspec.file(File.join(props[:src], "Topshelf.Serilog\\**\\*.cs").gsub("/","\\"), "src")
end
nuspec :create_nuspec do |nuspec|
nuspec.id = 'Topshelf.Rehab'
nuspec.version = NUGET_VERSION
nuspec.authors = ['Chris Patterson', 'Dru Sellers', 'Travis Smith']
nuspec.summary = 'Topshelf, Friction-free Windows Services'
nuspec.description = 'Rehab provides automatic updates to services. Topshelf is an open source project for hosting services without friction. By referencing Topshelf, your console application *becomes* a service installer with a comprehensive set of command-line options for installing, configuring, and running your application as a service.'
nuspec.title = 'Topshelf.Rehab'
nuspec.project_url = 'http://github.com/Topshelf/Topshelf'
nuspec.icon_url = 'http://topshelf-project.com/wp-content/themes/pandora/slide.1.png'
nuspec.language = "en-US"
nuspec.license_url = "http://www.apache.org/licenses/LICENSE-2.0"
nuspec.require_license_acceptance
nuspec.dependency "Topshelf", NUGET_VERSION
nuspec.output_file = File.join(props[:artifacts], 'Topshelf.Rehab.nuspec')
add_files props[:output], 'Topshelf.Rehab.{dll,pdb,xml}', nuspec
nuspec.file(File.join(props[:src], "Topshelf.Rehab\\**\\*.cs").gsub("/","\\"), "src")
end
nuspec :create_nuspec do |nuspec|
nuspec.id = 'Topshelf.Supervise'
nuspec.version = NUGET_VERSION
nuspec.authors = ['Chris Patterson', 'Dru Sellers', 'Travis Smith']
nuspec.summary = 'Topshelf, Supervised Services'
nuspec.description = 'Supervise provides automatic recovery, memory and CPU monitoring, and scheduled restarting to services. Topshelf is an open source project for hosting services without friction. By referencing Topshelf, your console application *becomes* a service installer with a comprehensive set of command-line options for installing, configuring, and running your application as a service.'
nuspec.title = 'Topshelf.Supervise'
nuspec.project_url = 'http://github.com/Topshelf/Topshelf'
nuspec.icon_url = 'http://topshelf-project.com/wp-content/themes/pandora/slide.1.png'
nuspec.language = "en-US"
nuspec.license_url = "http://www.apache.org/licenses/LICENSE-2.0"
nuspec.require_license_acceptance
nuspec.dependency "Topshelf", NUGET_VERSION
nuspec.output_file = File.join(props[:artifacts], 'Topshelf.Supervise.nuspec')
add_files props[:output], 'Topshelf.Supervise.{dll,pdb,xml}', nuspec
nuspec.file(File.join(props[:src], "Topshelf.Supervise\\**\\*.cs").gsub("/","\\"), "src")
end
def project_outputs(props)
props[:projects].map{ |p| "src/#{p}/bin/#{BUILD_CONFIG}/#{p}.dll" }.
concat( props[:projects].map{ |p| "src/#{p}/bin/#{BUILD_CONFIG}/#{p}.exe" } ).
find_all{ |path| exists?(path) }
end
def get_commit_hash_and_date
begin
commit = `git log -1 --pretty=format:%H`
git_date = `git log -1 --date=iso --pretty=format:%ad`
commit_date = DateTime.parse( git_date ).strftime("%Y-%m-%d %H%M%S")
rescue
commit = "git unavailable"
end
[commit, commit_date]
end
def add_files stage, what_dlls, nuspec
[['net35', 'net-3.5'], ['net40', 'net-4.0'], ['net40-full', 'net-4.0-full']].each{|fw|
takeFrom = File.join(stage, fw[1], what_dlls)
Dir.glob(takeFrom).each do |f|
nuspec.file(f.gsub("/", "\\"), "lib\\#{fw[0]}")
end
}
end
def waitfor(&block)
checks = 0
until block.call || checks >10
sleep 0.5
checks += 1
end
raise 'Waitfor timeout expired. Make sure that you aren\'t running something from the build output folders, or that you have browsed to it through Explorer.' if checks > 10
end