PageRenderTime 26ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/rakefile.rb

https://github.com/adbrowne/fubumvc
Ruby | 234 lines | 179 code | 44 blank | 11 comment | 9 complexity | 7ff8cc9d97637b5a599166919d59e7cb MD5 | raw file
  1. COMPILE_TARGET = ENV['config'].nil? ? "Debug" : ENV['config'] # Keep this in sync w/ VS settings since Mono is case-sensitive
  2. CLR_TOOLS_VERSION = "v4.0.30319"
  3. buildsupportfiles = Dir["#{File.dirname(__FILE__)}/buildsupport/*.rb"]
  4. raise "Run `git submodule update --init` to populate your buildsupport folder." unless buildsupportfiles.any?
  5. buildsupportfiles.each { |ext| load ext }
  6. include FileTest
  7. require 'albacore'
  8. load "VERSION.txt"
  9. RESULTS_DIR = "results"
  10. PRODUCT = "FubuMVC"
  11. COPYRIGHT = 'Copyright 2008-2010 Chad Myers, Jeremy D. Miller, Joshua Flanagan, et al. All rights reserved.';
  12. COMMON_ASSEMBLY_INFO = 'src/CommonAssemblyInfo.cs';
  13. BUILD_DIR = File.expand_path("build")
  14. ARTIFACTS = File.expand_path("artifacts")
  15. @teamcity_build_id = "bt24"
  16. tc_build_number = ENV["BUILD_NUMBER"]
  17. build_revision = tc_build_number || Time.new.strftime('5%H%M')
  18. BUILD_NUMBER = "#{BUILD_VERSION}.#{build_revision}"
  19. props = { :stage => BUILD_DIR, :artifacts => ARTIFACTS }
  20. desc "**Default**, compiles and runs tests"
  21. task :default => [:compile, :unit_test]
  22. desc "Target used for the CI server"
  23. task :ci => [:update_all_dependencies, :default, "template:build", :history, :publish]
  24. desc "Update the version information for the build"
  25. assemblyinfo :version do |asm|
  26. asm_version = BUILD_VERSION + ".0"
  27. begin
  28. commit = `git log -1 --pretty=format:%H`
  29. rescue
  30. commit = "git unavailable"
  31. end
  32. puts "##teamcity[buildNumber '#{BUILD_NUMBER}']" unless tc_build_number.nil?
  33. puts "Version: #{BUILD_NUMBER}" if tc_build_number.nil?
  34. asm.trademark = commit
  35. asm.product_name = PRODUCT
  36. asm.description = BUILD_NUMBER
  37. asm.version = asm_version
  38. asm.file_version = BUILD_NUMBER
  39. asm.custom_attributes :AssemblyInformationalVersion => asm_version
  40. asm.copyright = COPYRIGHT
  41. asm.output_file = COMMON_ASSEMBLY_INFO
  42. end
  43. desc "Prepares the working directory for a new build"
  44. task :clean do
  45. #TODO: do any other tasks required to clean/prepare the working directory
  46. FileUtils.rm_rf props[:stage]
  47. # work around nasty latency issue where folder still exists for a short while after it is removed
  48. waitfor { !exists?(props[:stage]) }
  49. Dir.mkdir props[:stage]
  50. Dir.mkdir props[:artifacts] unless exists?(props[:artifacts])
  51. end
  52. def waitfor(&block)
  53. checks = 0
  54. until block.call || checks >10
  55. sleep 0.5
  56. checks += 1
  57. end
  58. raise 'waitfor timeout expired' if checks > 10
  59. end
  60. desc "Packages the Serenity bottle files"
  61. task :bottle_serenity do
  62. bottles("assembly-pak src/Serenity")
  63. end
  64. desc "Compiles the app"
  65. task :compile => [:restore_if_missing, :clean, :version, :bottle_serenity] do
  66. MSBuildRunner.compile :compilemode => COMPILE_TARGET, :solutionfile => 'src/FubuMVC.sln', :clrversion => CLR_TOOLS_VERSION
  67. #AspNetCompilerRunner.compile :webPhysDir => "src/FubuMVC.HelloWorld", :webVirDir => "localhost/xyzzyplugh"
  68. #copyOutputFiles "src/FubuMVC.StructureMap/bin/#{COMPILE_TARGET}", "*.{dll,pdb}", props[:stage]
  69. #copyOutputFiles "src/FubuMVC.GettingStarted/bin/#{COMPILE_TARGET}", "*.{dll,pdb}", props[:stage]
  70. #copyOutputFiles "src/FubuLocalization/bin/#{COMPILE_TARGET}", "FubuLocalization.{dll,pdb}", props[:stage]
  71. #copyOutputFiles "src/FubuMVC.WebForms/bin/#{COMPILE_TARGET}", "FubuMVC.WebForms.{dll,pdb}", props[:stage]
  72. #copyOutputFiles "src/FubuMVC.Spark/bin/#{COMPILE_TARGET}", "*Spark*.{dll,pdb}", props[:stage]
  73. #copyOutputFiles "src/FubuMVC.Deployers/bin/#{COMPILE_TARGET}", "*Deployers*.{dll,pdb}", props[:stage]
  74. copyOutputFiles "src/fubu/bin/#{COMPILE_TARGET}", "fubu.exe", props[:stage]
  75. copyOutputFiles "src/fubu/bin/#{COMPILE_TARGET}", "Bottles*.{dll,pdb,exe}", props[:stage]
  76. copyOutputFiles "src/fubu/bin/#{COMPILE_TARGET}", "fubu", props[:stage]
  77. target = COMPILE_TARGET.downcase
  78. bottles("create-pak src/FubuMVC.Deployers build/fubumvc-deployers.zip -target #{target}")
  79. outputDir = "src/FubuMVC.Diagnostics/bin"
  80. packer = ILRepack.new :out => "src/FubuMVC.Diagnostics/bin/FubuMVC.Diagnostics.dll", :lib => outputDir
  81. packer.merge :lib => outputDir, :refs => ['FubuMVC.Diagnostics.dll', 'Newtonsoft.Json.dll']
  82. bottles("create-pak src/FubuMVC.Diagnostics build/fubumvc-diagnostics.zip -target #{target}")
  83. end
  84. def copyOutputFiles(fromDir, filePattern, outDir)
  85. Dir.glob(File.join(fromDir, filePattern)){|file|
  86. copy(file, outDir, :preserve => true) if File.file?(file)
  87. }
  88. end
  89. desc "Runs unit tests"
  90. task :test => [:unit_test]
  91. desc "Runs unit tests"
  92. task :unit_test => :compile do
  93. runner = NUnitRunner.new :compilemode => COMPILE_TARGET, :source => 'src', :platform => 'x86'
  94. runner.executeTests ['FubuMVC.Tests', 'FubuMVC.WebForms.Testing', 'FubuMVC.Spark.Tests']
  95. end
  96. desc "Runs the StoryTeller suite of end to end tests. IIS must be running first"
  97. task :storyteller => [:compile] do
  98. storyteller("Storyteller.xml output/st-results.htm")
  99. end
  100. desc "Set up the virtual directories for the HelloWorld applications"
  101. task :virtual_dir => [:compile] do
  102. fubu("createvdir src/FubuMVC.HelloWorld helloworld")
  103. fubu("createvdir src/FubuMVC.HelloFubuSpark hellofubuspark")
  104. end
  105. desc "ZIPs up the build results"
  106. zip :package do |zip|
  107. zip.directories_to_zip = [props[:stage]]
  108. zip.output_file = 'fubumvc.zip'
  109. zip.output_path = [props[:artifacts]]
  110. end
  111. desc "Bundles up the packaged content in FubuFastPack"
  112. task :bundle_getting_started do
  113. fubu("assembly-pak src/FubuMVC.GettingStarted -projfile FubuMVC.GettingStarted.csproj")
  114. end
  115. def self.bottles(args)
  116. bottles = Platform.runtime(Nuget.tool("Bottles.Tools", "BottleRunner.exe"))
  117. sh "#{bottles} #{args}"
  118. end
  119. def self.storyteller(args)
  120. st = Platform.runtime(Nuget.tool("Storyteller", "StorytellerRunner.exe"))
  121. sh "#{st} #{args}"
  122. end
  123. desc "Runs the StoryTeller UI"
  124. task :run_st do
  125. st = Platform.runtime(Nuget.tool("Storyteller", "StorytellerUI.exe"))
  126. sh st
  127. end
  128. def self.fubu(args)
  129. fubu = Platform.runtime("src/fubu/bin/#{COMPILE_TARGET}/fubu.exe")
  130. sh "#{fubu} #{args}"
  131. end
  132. FUBUTEMPLATE_DIR = 'fubuTemplates'
  133. namespace :template do
  134. desc 'Cleans, Updates, and Zips Fubu templates'
  135. task :build => ['template:clean', 'template:update', 'template:slimdown_nuget_pkgs', 'template:zip_all', 'template:build_artifacts_cleanup']
  136. nuget = 'buildsupport/nuget.exe'
  137. desc 'Updates and zips default Fubu templates'
  138. task :zip_all do
  139. # first clear out old templates
  140. Dir['build/*Template.zip'].each {|zip_file| rm_rf zip_file}
  141. Dir["#{FUBUTEMPLATE_DIR}/*/"].each do |template_dir|
  142. Rake::Task['template:zip'].execute template_dir
  143. end
  144. end
  145. zip :zip do |zip, subdir|
  146. folder_name = File.basename subdir
  147. zip.directories_to_zip = [subdir]
  148. zip.output_file = "#{folder_name}Template.zip"
  149. zip.output_path = ['build']
  150. end
  151. desc 'Update Fubu templates dependencies'
  152. task :update do
  153. Dir["#{FUBUTEMPLATE_DIR}/*/"].each do |template_dir|
  154. packages_config = File.join(template_dir, 'src/FUBUPROJECTNAME/packages.config')
  155. dependencies_dir = File.join(template_dir, 'src/packages')
  156. unless File.exists?(packages_config)
  157. puts "No packages.config file for brining in dependencies into template #{template_dir}"
  158. return
  159. end
  160. mkdir_p(dependencies_dir)
  161. # Run nuget here
  162. sh "#{nuget} install #{packages_config} -o #{dependencies_dir} -ExcludeVersion"
  163. cp_r "#{template_dir}src/packages/FubuMVC/content/fubu-content/", "#{template_dir}src/FUBUPROJECTNAME/fubu-content"
  164. end
  165. end
  166. desc 'Cleans nuget install downloading source'
  167. task :slimdown_nuget_pkgs, [:dry_run] do |t, args|
  168. Dir.chdir(FUBUTEMPLATE_DIR) do
  169. files = Dir.glob('*/src/packages/**/src')
  170. nupkg = Dir.glob('*/src/packages/**/*.nupkg')
  171. files << nupkg
  172. args[:dry_run] ? puts(files) : rm_r(files)
  173. end
  174. end
  175. desc 'Cleans matching files in fubuTemplateIgnore.txt'
  176. task :clean, [:dry_run] do |t, args|
  177. Dir.chdir(FUBUTEMPLATE_DIR) do
  178. files = IO.readlines('fubuTemplateIgnore.txt').map{|l| Dir["**/#{l.chomp}"]}.flatten.uniq
  179. args[:dry_run] ? puts(files) : rm_r(files)
  180. end
  181. end
  182. task :build_artifacts_cleanup do
  183. Dir["#{FUBUTEMPLATE_DIR}/*/src/"].each do |template_dir|
  184. nuget_pkg_dirs = File.join(template_dir, 'packages/*/')
  185. fubu_content_dir = File.join(template_dir, 'FUBUPROJECTNAME/fubu-content')
  186. Dir[nuget_pkg_dirs].each {|nuget_pkg_dir| rm_rf nuget_pkg_dir}
  187. rm_rf fubu_content_dir
  188. end
  189. end
  190. end