forked from MassTransit/Automatonymous
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rakefile.rb
298 lines (257 loc) · 12.6 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
COPYRIGHT = "Copyright 2011-2013 Chris Patterson, All rights reserved."
include FileTest
require 'albacore'
require 'semver'
internal_files = Dir[File.join(File.expand_path("src"), 'Automatonymous/Internals/**/*.cs')]
if(!internal_files.any?)
#you didn't git submodule update --init - here let me help you
sh 'git submodule update --init' unless internal_files.any?
end
PRODUCT = 'Automatonymous'
CLR_TOOLS_VERSION = 'v4.0.30319'
OUTPUT_PATH = 'bin/Release'
NETCORE45_FRAMEWORK = '.NET Framework, Version=v4.5'
props = {
:src => File.expand_path("src"),
:output => File.expand_path("build_output"),
:artifacts => File.expand_path("build_artifacts"),
:projects => ["Automatonymous"],
:lib => File.expand_path("lib"),
:keyfile => File.expand_path("Automatonymous.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, :tests, :compile_net45fx, :nuget]
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 = "Automatonymous is an open source state machine library."
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, :build] do
copyOutputFiles File.join(props[:src], "Automatonymous/bin/Release"), "Automatonymous.{dll,pdb,xml}", File.join(props[:output], 'net-4.0')
copyOutputFiles File.join(props[:src], "MassTransit/Automatonymous.MassTransitIntegration/bin/Release"), "Automatonymous.MassTransitIntegration.{dll,pdb,xml}", File.join(props[:output], 'net-4.0')
copyOutputFiles File.join(props[:src], "Automatonymous.NHibernateIntegration/bin/Release"), "Automatonymous.NHibernateIntegration.{dll,pdb,xml}", File.join(props[:output], 'net-4.0')
copyOutputFiles File.join(props[:src], "Automatonymous.Visualizer/bin/Release"), "Automatonymous.Visualizer.{dll,pdb,xml}", File.join(props[:output], 'net-4.0')
end
desc "Cleans, versions, compiles the application and generates build_output/."
task :compile_net45fx => [:global_version, :build_net45fx] do
copyOutputFiles File.join(props[:src], "Automatonymous/bin/Release/win8"), "Automatonymous.{dll,pdb,xml}", File.join(props[:output], 'win8')
end
desc "Only compiles the application."
msbuild :build do |msb|
msb.properties :Configuration => "Release",
:Platform => 'Any CPU'
msb.use :net4
msb.targets :Clean, :Build
msb.properties[:SignAssembly] = 'true'
msb.properties[:AssemblyOriginatorKeyFile] = props[:keyfile]
msb.solution = 'src/Automatonymous.sln'
end
desc "Only compiles the application for .NET 4.5 FX CORE."
msbuild :build_net45fx do |msb|
msb.properties :Configuration => "Release45",
:SignAssembly => 'true',
:AssemblyOriginatorKeyFile => props[:keyfile]
msb.use :net4
msb.targets :Clean, :Build
msb.solution = 'src/Automatonymous/Automatonymous.csproj'
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 :tests => [:compile] do |nunit|
nunit.command = File.join('src', 'packages','NUnit.Runners.2.6.3', 'tools', 'nunit-console.exe')
nunit.options = "/framework=#{CLR_TOOLS_VERSION}", '/nothread', '/nologo', '/labels', "\"/xml=#{File.join(props[:artifacts], 'nunit-test-results.xml')}\""
nunit.assemblies = FileList["tests/Automatonymous.Tests.dll", File.join(props[:src], "MassTransit/MassTransit.AutomatonymousTests/bin/Release", "MassTransit.AutomatonymousTests.dll"), File.join(props[:src], "NHibernate.AutomatonymousTests/bin/Release", "NHibernate.AutomatonymousTests.dll")]
end
task :package => [:nuget]
desc "ZIPs up the build results."
zip :zip_output do |zip|
zip.directories_to_zip = [props[:stage]]
zip.output_file = "Automatonymous-#{NUGET_VERSION}.zip"
zip.output_path = [props[:artifacts]]
end
desc "restores missing packages"
msbuild :nuget_restore do |msb|
msb.use :net4
msb.targets :RestorePackages
msb.solution = File.join(props[:src], "Automatonymous.Tests", "Automatonymous.Tests.csproj")
end
desc "restores missing packages"
msbuild :nuget_restore do |msb|
msb.use :net4
msb.targets :RestorePackages
msb.solution = File.join(props[:src], "MassTransit", "MassTransit.AutomatonymousTests", "MassTransit.AutomatonymousTests.csproj")
end
desc "restores missing packages"
msbuild :nuget_restore do |msb|
msb.use :net4
msb.targets :RestorePackages
msb.solution = File.join(props[:src], "MassTransit", "Automatonymous.MassTransitIntegration", "Automatonymous.MassTransitIntegration.csproj")
end
desc "restores missing packages"
msbuild :nuget_restore do |msb|
msb.use :net4
msb.targets :RestorePackages
msb.solution = File.join(props[:src], "Automatonymous.NHibernateIntegration", "Automatonymous.NHibernateIntegration.csproj")
end
desc "restores missing packages"
msbuild :nuget_restore do |msb|
msb.use :net4
msb.targets :RestorePackages
msb.solution = File.join(props[:src], "NHibernate.AutomatonymousTests", "NHibernate.AutomatonymousTests.csproj")
end
desc "restores missing packages"
msbuild :nuget_restore do |msb|
msb.use :net4
msb.targets :RestorePackages
msb.solution = File.join(props[:src], "Automatonymous.Visualizer", "Automatonymous.Visualizer.csproj")
end
desc "Builds the nuget package"
task :nuget => ['create_nuspec', 'create_nuspec_masstransit', 'create_nuspec_nhibernate', 'create_nuspec_quickgraph'] do
sh "#{File.join(props[:src],'.nuget','nuget.exe')} pack #{props[:artifacts]}/Automatonymous.nuspec /Symbols /OutputDirectory #{props[:artifacts]}"
sh "#{File.join(props[:src],'.nuget','nuget.exe')} pack #{props[:artifacts]}/Automatonymous.MassTransit.nuspec /Symbols /OutputDirectory #{props[:artifacts]}"
sh "#{File.join(props[:src],'.nuget','nuget.exe')} pack #{props[:artifacts]}/Automatonymous.NHibernate.nuspec /Symbols /OutputDirectory #{props[:artifacts]}"
sh "#{File.join(props[:src],'.nuget','nuget.exe')} pack #{props[:artifacts]}/Automatonymous.Visualizer.nuspec /Symbols /OutputDirectory #{props[:artifacts]}"
end
nuspec :create_nuspec do |nuspec|
nuspec.id = 'Automatonymous'
nuspec.version = NUGET_VERSION
nuspec.authors = 'Chris Patterson'
nuspec.description = 'Automatonymous is a state machine library for .NET'
nuspec.title = 'Automatonymous'
nuspec.projectUrl = 'http://github.com/MassTransit/Automatonymous'
nuspec.language = "en-US"
nuspec.licenseUrl = "http://www.apache.org/licenses/LICENSE-2.0"
nuspec.requireLicenseAcceptance = "false"
nuspec.dependency "Taskell", "0.1.2"
nuspec.output_file = File.join(props[:artifacts], 'Automatonymous.nuspec')
add_files props[:output], 'Automatonymous.{dll,pdb,xml}', nuspec
nuspec.file(File.join(props[:src], "Automatonymous\\**\\*.cs").gsub("/","\\"), "src")
end
nuspec :create_nuspec_masstransit do |nuspec|
nuspec.id = 'Automatonymous.MassTransit'
nuspec.version = NUGET_VERSION
nuspec.authors = 'Chris Patterson'
nuspec.description = 'Integration assembly to support Automatonymous sagas, a state machine library for .NET'
nuspec.title = 'Automatonymous.MassTransit'
nuspec.projectUrl = 'http://github.com/MassTransit/Automatonymous'
nuspec.language = "en-US"
nuspec.licenseUrl = "http://www.apache.org/licenses/LICENSE-2.0"
nuspec.requireLicenseAcceptance = "false"
nuspec.dependency "MassTransit", "2.9.5"
nuspec.dependency "Taskell", "0.1.2"
nuspec.dependency "Automatonymous", NUGET_VERSION
nuspec.output_file = File.join(props[:artifacts], 'Automatonymous.MassTransit.nuspec')
add_files props[:output], 'Automatonymous.MassTransitIntegration.{dll,pdb,xml}', nuspec
nuspec.file(File.join(props[:src], "MassTransit\\Automatonymous.MassTransitIntegration\\**\\*.cs").gsub("/","\\"), "src")
end
nuspec :create_nuspec_nhibernate do |nuspec|
nuspec.id = 'Automatonymous.NHibernate'
nuspec.version = NUGET_VERSION
nuspec.authors = 'Chris Patterson'
nuspec.description = 'Integration assembly to support Automatonymous NHibernate, a state machine library for .NET'
nuspec.title = 'Automatonymous.NHibernate'
nuspec.projectUrl = 'http://github.com/MassTransit/Automatonymous'
nuspec.language = "en-US"
nuspec.licenseUrl = "http://www.apache.org/licenses/LICENSE-2.0"
nuspec.requireLicenseAcceptance = "false"
nuspec.dependency "NHibernate", "3.3.3"
nuspec.dependency "Automatonymous", NUGET_VERSION
nuspec.output_file = File.join(props[:artifacts], 'Automatonymous.NHibernate.nuspec')
add_files props[:output], 'Automatonymous.NHibernateIntegration.{dll,pdb,xml}', nuspec
nuspec.file(File.join(props[:src], "Automatonymous.NHibernateIntegration\\**\\*.cs").gsub("/","\\"), "src")
end
nuspec :create_nuspec_quickgraph do |nuspec|
nuspec.id = 'Automatonymous.Visualizer'
nuspec.version = NUGET_VERSION
nuspec.authors = 'Chris Patterson'
nuspec.description = 'Visualization assembly to support Automatonymous, a state machine library for .NET'
nuspec.title = 'Automatonymous.Visualizer'
nuspec.projectUrl = 'http://github.com/MassTransit/Automatonymous'
nuspec.language = "en-US"
nuspec.licenseUrl = "http://www.apache.org/licenses/LICENSE-2.0"
nuspec.requireLicenseAcceptance = "false"
nuspec.dependency "QuickGraph", "3.6.61119"
nuspec.dependency "Automatonymous", NUGET_VERSION
nuspec.output_file = File.join(props[:artifacts], 'Automatonymous.Visualizer.nuspec')
add_files props[:output], 'Automatonymous.Visualizer.{dll,pdb,xml}', nuspec
nuspec.file(File.join(props[:src], "Automatonymous.Visualizer\\**\\*.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 add_files stage, what_dlls, nuspec
[['net40', 'net-4.0'], ['.NETCore45', 'win8']].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 commit_data
begin
commit = `git rev-parse --short HEAD`.chomp()[0,6]
git_date = `git log -1 --date=iso --pretty=format:%ad`
commit_date = DateTime.parse( git_date ).strftime("%Y-%m-%d %H%M%S")
rescue Exception => e
puts e.inspect
commit = (ENV['BUILD_VCS_NUMBER'] || "000000")[0,6]
commit_date = Time.new.strftime("%Y-%m-%d %H%M%S")
end
[commit, commit_date]
end
task :versioning do
ver = SemVer.find
revision = (ENV['BUILD_NUMBER'] || ver.patch).to_i
var = SemVer.new(ver.major, ver.minor, revision, ver.special)
# extensible number w/ git hash
ENV['BUILD_VERSION'] = BUILD_VERSION = ver.format("%M.%m.%p%s") + ".#{commit_data()[0]}"
# nuget (not full semver 2.0.0-rc.1 support) see http://nuget.codeplex.com/workitem/1796
ENV['NUGET_VERSION'] = NUGET_VERSION = ver.format("%M.%m.%p%s")
# purely M.m.p format
ENV['FORMAL_VERSION'] = FORMAL_VERSION = "#{ SemVer.new(ver.major, ver.minor, revision).format "%M.%m.%p"}"
puts "##teamcity[buildNumber '#{BUILD_VERSION}']" # tell teamcity our decision
end
def add_files stage, what_dlls, nuspec
[['net40', 'net-4.0'], ['.NETCore45', 'win8']].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