Created
May 19, 2010 12:53
-
-
Save jonhilt/406268 to your computer and use it in GitHub Desktop.
A simple Rake build script example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'albacore' | |
require 'fileutils' | |
PROJECT_NAME = "Your Project Here" | |
DOT_NET_PATH = "C:/Windows/Microsoft.NET/Framework/v4.0.30319/" | |
NUNIT_PATH = "Tools/nunit/" | |
MSPEC_PATH = "Tools/mspec/" | |
PROJECT_CONFIG = (ENV['PROJECT_CONFIG'] == nil) ? "Debug" : ENV['PROJECT_CONFIG'] | |
COMPANY_NAME = "Your Company Here" | |
BUILD_NUMBER = (ENV['BUILD_NUMBER'] == nil) ? "1.0.0.0" : ENV['BUILD_NUMBER'] | |
COMMON_DIR = "../Common/" | |
CONFIG_DIR = "../Common/Config" | |
SOLUTION_DIR = "../Solutions" | |
SOLUTION = "../Solutions/YourSolution.sln" | |
RESULTS_DIR = "Results" | |
TEST_WORKING_DIR = "#{SOLUTION_DIR}/YourSolution.Tests/bin/#{PROJECT_CONFIG}/" | |
TEST_ASSEMBLY = "YourSolution.Tests.dll" | |
PACKAGE_DIR = "Package" | |
PACKAGE_SOURCE_FILES = "#{SOLUTION_DIR}/YourSolution.WindowsService/bin/#{PROJECT_CONFIG}" | |
DEPLOYABLES_DIR = "Deployables" | |
ZIPFILE_NAME = "#{PROJECT_NAME}-#{PROJECT_CONFIG}-#{BUILD_NUMBER}.zip" | |
ZIPFILE_FULLNAME = "#{DEPLOYABLES_DIR}/#{ZIPFILE_NAME}" | |
desc 'this is the default task' | |
task :default => [:all] do | |
end | |
desc 'runs all tasks' | |
task :all =>[:assemblyinfo,:compile,:run_tests,:mspec,:package,:copy_config,:zip] do | |
end | |
desc "generates our assembly info" | |
assemblyinfo :assemblyinfo do |asm| | |
if(!File.directory? "#{COMMON_DIR}") then Dir.mkdir "#{COMMON_DIR}" end | |
asm.version = "#{BUILD_NUMBER}" | |
asm.company_name = "#{COMPANY_NAME}" | |
asm.product_name = "#{PROJECT_NAME}" | |
asm.output_file = "#{COMMON_DIR}AssemblyInfo.cs" | |
end | |
desc 'compiles the application' | |
task :compile do | |
sh "#{DOT_NET_PATH}msbuild.exe #{SOLUTION} /property:Configuration=#{PROJECT_CONFIG}" | |
end | |
desc 'runs unit tests' | |
nunit :run_tests => [:compile] do |nunit| | |
nunit.path_to_command = "#{NUNIT_PATH}nunit-console.exe" | |
nunit.assemblies "#{TEST_WORKING_DIR}#{TEST_ASSEMBLY}" | |
nunit.options '/framework=4.0.30319' | |
end | |
desc 'runs mspec tests' | |
mspec :mspec do |mspec| | |
mspec.path_to_command = "#{MSPEC_PATH}mspec.exe" | |
mspec.assemblies "#{TEST_WORKING_DIR}#{TEST_ASSEMBLY}" | |
mspec.options '--teamcity' | |
end | |
desc 'copies the relevant config file' | |
task :copy_config do | |
puts 'copying config file' | |
FileUtils.cp "#{CONFIG_DIR}/YourSolution.WindowsService.exe.config.#{PROJECT_CONFIG}", "#{PACKAGE_DIR}/YourSolution.WindowsService.exe.config" | |
end | |
desc 'copys the output (compiled) files' | |
task :package do | |
puts 'packaging files' | |
if(File.directory? "#{PACKAGE_DIR}") then | |
puts 'removing existing package files and folder' | |
FileUtils.rm_r "#{PACKAGE_DIR}" | |
end | |
puts 'creating package folder' | |
Dir.mkdir "#{PACKAGE_DIR}" | |
puts 'copying files to package folder' | |
@files_to_package = FileList["#{PACKAGE_SOURCE_FILES}/*.*"] | |
puts 'listing files to be packaged' | |
puts 'package source folder is ' + "#{PACKAGE_SOURCE_FILES}" | |
@files_to_package.each do |file| | |
puts "will copy" + file | |
end | |
FileUtils.cp_r @files_to_package, "#{PACKAGE_DIR}" | |
end | |
desc 'zips up the output files' | |
zip :zip do |zip| | |
puts 'cleaning output folder' | |
if(File.directory? "#{DEPLOYABLES_DIR}") then | |
FileUtils.rm_r "#{DEPLOYABLES_DIR}" | |
end | |
Dir.mkdir "#{DEPLOYABLES_DIR}" | |
puts 'creating zip' | |
zip.directories_to_zip "#{PACKAGE_DIR}" | |
zip.output_file = "#{ZIPFILE_NAME}" | |
zip.output_path = "#{DEPLOYABLES_DIR}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment