Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

172 lines (149 sloc) 5.483 kb
require 'albacore'
PRODUCT_NAME = "StarterTree"
CLR_TOOLS_VERSION = "v4.0"
DEFAULT_BUILD_NUMBER = "0.0.0"
COMPANY_NAME = "MVBA, P.C."
COPYRIGHT = "MVBA, P.C. (c) 2011-2013"
ARTIFACTS = File.expand_path("dist")
COMPILE_TARGET = "Debug"
STAGE = File.expand_path("build")
SETTINGS_DIR = "settings"
nunit_cmd = "tools/NUnit/bin/nunit-console.exe"
beginning = Time.now
default_settings = { :artifacts => ARTIFACTS,
:compile_target => COMPILE_TARGET,
:stage => STAGE
}
def read_config(settings_directory, env)
settings = {}
default_settings_file = "#{settings_directory}/#{env}.default.yaml"
if File.exists?(default_settings_file) then
settings = YAML.load_file(default_settings_file)
end
settings_file = "#{settings_directory}/#{env}.yaml"
if File.exists?(settings_file) then
overrides = YAML.load_file(settings_file)
overrides.each do |k,v|
settings[k] = v
end
end
return settings
end
environment = ENV['environment']
settings = read_config(SETTINGS_DIR, environment)
default_settings.each { |key, val| if settings[key].nil? then settings[key] = default_settings[key] end }
puts "Rakefile settings:"
settings.each { |key, val| puts "#{key} => #{val}" }
puts
desc "** Default **"
task :default => [:build, :copy_artifacts, :test, :archive] do
puts "Build Succeeded - time elapsed: #{Time.now - beginning} seconds"
end
desc "Creates CommonAssemblyInfo.cs file"
assemblyinfo :assemblyinfo do |asm|
build_number = get_build_number
build_number_with_hash = get_build_number_with_hash
asm.product_name = PRODUCT_NAME
asm.version = build_number
asm.file_version = build_number
asm.trademark = build_number_with_hash
asm.company_name = COMPANY_NAME
asm.copyright = COPYRIGHT
asm.output_file = "src/CommonAssemblyInfo.cs"
end
desc "Add Resharper escapes to CommonAssemblyInfo.cs file"
task :resharperAssemblyInfo do
puts
puts "adding Resharper escapes to src/CommonAssemblyInfo.cs"
puts
File.open('src/CommonAssemblyInfo.cs', 'r+') do |f|
contents = f.read
f.rewind
f.puts "// ReSharper disable RedundantUsingDirective"
f.puts contents
f.puts "// ReSharper enable RedundantUsingDirective"
end
end
desc "Builds the #{PRODUCT_NAME} solution"
msbuild :build => [:clean, :assemblyinfo, :resharperAssemblyInfo] do |msb|
puts "Compiling #{PRODUCT_NAME} in #{settings[:compile_target]} mode..."
msb.properties :configuration => settings[:compile_target]
msb.targets :Clean, :Build
msb.solution = "src/#{PRODUCT_NAME}.sln"
msb.verbosity = "quiet"
sleep 1
end
desc "Copy build artifacts to the staging folder"
task :copy_artifacts => [:build] do
puts "Copying files from bin folders to the build folder (#{settings[:stage]})..."
copy_output_files "src/#{PRODUCT_NAME}/bin/#{settings[:compile_target]}", "*.{dll,pdb,exe}", settings[:stage]
copy_output_files "src/#{PRODUCT_NAME}.Tests/bin/#{settings[:compile_target]}", "*.{dll,pdb,exe}", settings[:stage]
FileUtils.cp_r "License.txt", "#{settings[:stage]}/#{PRODUCT_NAME}.License.txt"
end
desc "Prepares the working directory for a new build"
task :clean do
FileUtils.rm_rf settings[:stage]
# work around nasty latency issue where folder still exists for a short while after it is removed
wait_for { !Dir.exists?(settings[:stage]) }
Dir.mkdir settings[:stage]
Dir.mkdir settings[:artifacts] unless Dir.exists?(settings[:artifacts])
end
desc "Runs the unit tests"
nunit :test do |nunit|
puts "Running the unit tests in the build folder (#{settings[:stage]})..."
nunit.command = nunit_cmd
nunit.options "/framework #{CLR_TOOLS_VERSION}"
nunit.assemblies "#{settings[:stage]}/#{PRODUCT_NAME}.Tests.dll"
end
desc "Zips up the build results"
zip :archive do |zip|
puts "Zipping up the build folder and copying to artifact folder (#{settings[:artifacts]})..."
mkdir settings[:artifacts] unless Dir.exists?(settings[:artifacts])
build_number = get_build_number
zip.directories_to_zip = [settings[:stage]]
zip.output_file = "#{PRODUCT_NAME}_#{build_number}.#{settings[:compile_target]}.zip"
zip.output_path = [settings[:artifacts]]
puts "Artifacts are available in the artifact folder: #{settings[:artifacts]}"
end
def copy_output_files(fromDir, filePattern, outDir)
Dir.glob(File.join(fromDir, filePattern)){|file|
copy(file, outDir) if File.file?(file)
}
end
def get_build_number
begin
gittag = `git describe --long`.chomp # looks something like v0.1.0-63-g3f10c2e
puts "gittag: #{gittag}"
parts = gittag.split("-")
base_version = parts[0].gsub("v","")
git_build_revision = parts[1]
git_short_hash = parts[2]
puts "base_version: #{base_version}"
puts "git_build_revision: #{git_build_revision}"
puts "git_short_hash: #{git_short_hash}"
build_number = "#{base_version}.#{git_build_revision}"
rescue
build_number = DEFAULT_BUILD_NUMBER
end
end
def get_build_number_with_hash
begin
gittag = `git describe --long`.chomp # looks something like v0.1.0-63-g3f10c2e
#puts "gittag: #{gittag}"
parts = gittag.split("-")
base_version = parts[0].gsub("v","")
git_build_revision = parts[1]
git_short_hash = parts[2]
build_number_with_hash = "#{base_version}.#{git_build_revision}-#{git_short_hash}"
rescue
build_number_with_hash = DEFAULT_BUILD_NUMBER
end
end
def wait_for(&block)
checks = 0
until block.call || checks >10
sleep 0.5
checks += 1
end
raise 'waitfor timeout expired' if checks > 10
end
Jump to Line
Something went wrong with that request. Please try again.