forked from storyteller/Storyteller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rakefile.rb
149 lines (119 loc) · 4.15 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
COMPILE_TARGET = ENV['config'].nil? ? "debug" : ENV['config']
RESULTS_DIR = "results"
BUILD_VERSION = '3.0.0'
NUGET_KEY = ENV['api_key']
include FileUtils
include FileTest
tc_build_number = ENV["BUILD_NUMBER"]
build_revision = tc_build_number || Time.new.strftime('5%H%M')
build_number = "#{BUILD_VERSION}.#{build_revision}"
BUILD_NUMBER = build_number
task :ci => [:default, :integration_test, :publish]
task :default => [:test, :mocha]
desc "Prepares the working directory for a new build"
task :clean do
#TODO: do any other tasks required to clean/prepare the working directory
FileUtils.rm_rf RESULTS_DIR
FileUtils.rm_rf 'artifacts'
Dir.mkdir 'artifacts'
Dir.mkdir RESULTS_DIR
end
desc "Update the version information for the build"
task :version do
asm_version = build_number
begin
commit = `git log -1 --pretty=format:%H`
rescue
commit = "git unavailable"
end
puts "##teamcity[buildNumber '#{build_number}']" unless tc_build_number.nil?
puts "Version: #{build_number}" if tc_build_number.nil?
options = {
:description => 'Storyteller -- Executable Specifications and Living Documents for .Net',
:product_name => 'Storyteller',
:copyright => 'Copyright 2008-2015 Jeremy D. Miller, Steve Matney, Ron Lloyd, et al. All rights reserved.',
:trademark => commit,
:version => asm_version,
:file_version => build_number,
:informational_version => asm_version
}
puts "Writing src/CommonAssemblyInfo.cs..."
File.open('src/CommonAssemblyInfo.cs', 'w') do |file|
file.write "using System.Reflection;\n"
file.write "using System.Runtime.InteropServices;\n"
file.write "[assembly: AssemblyProduct(\"#{options[:product_name]}\")]\n"
file.write "[assembly: AssemblyCopyright(\"#{options[:copyright]}\")]\n"
file.write "[assembly: AssemblyTrademark(\"#{options[:trademark]}\")]\n"
file.write "[assembly: AssemblyVersion(\"#{options[:version]}\")]\n"
file.write "[assembly: AssemblyFileVersion(\"#{options[:file_version]}\")]\n"
file.write "[assembly: AssemblyInformationalVersion(\"#{options[:informational_version]}\")]\n"
end
end
desc 'Compile the code'
task :compile => [:npm, :clean, :version] do
sh "paket.exe restore"
msbuild = '"C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.exe"'
sh "#{msbuild} src/Storyteller.sln /property:Configuration=#{COMPILE_TARGET} /v:m /t:rebuild /nr:False /maxcpucount:2"
end
desc 'Run the unit tests'
task :test => [:compile] do
sh "packages/Fixie/lib/net45/Fixie.Console.exe src/Storyteller.Testing/bin/#{COMPILE_TARGET}/Storyteller.Testing.dll --NUnitXml results/TestResult.xml"
end
desc 'Build Nuspec packages'
task :pack => [:compile] do
sh "nuget.exe pack packaging/nuget/storyteller.nuspec -VERSION #{build_number}-alpha -OutputDirectory artifacts"
end
task :publish => [:pack] do
sh "nuget.exe push artifacts/Storyteller.#{build_number}-alpha.nupkg #{NUGET_KEY} "
end
desc "Delegates to npm install and builds the javascript for diagnostics"
task :npm do
sh 'npm install'
sh 'npm run build-client'
end
desc "Runs all the client side tests"
task :mocha => [:npm] do
sh 'npm run test'
end
desc "Run the storyteller specifications"
task :storyteller => [:compile] do
sh "packages/Storyteller/tools/st.exe run src/FubuMVC.IntegrationTesting --retries 3 --results-path artifacts/stresults.htm --build #{COMPILE_TARGET}"
end
desc "Run the storyteller specifications"
task :samples do
sh "src/st/bin/debug/st.exe open src/Samples"
end
desc "Run the storyteller specifications"
task :specifications do
sh "src/st/bin/debug/st.exe open src/Specifications"
end
desc "Launches VS to the Storyteller solution file"
task :sln do
sh "start src/Storyteller.sln"
end
def copyOutputFiles(fromDir, filePattern, outDir)
Dir.glob(File.join(fromDir, filePattern)){|file|
copy(file, outDir) if File.file?(file)
}
end
def waitfor(&block)
checks = 0
until block.call || checks >10
sleep 0.5
checks += 1
end
raise 'waitfor timeout expired' if checks > 10
end
def cleanDirectory(dir)
if exists?(dir)
puts 'Cleaning directory ' + dir
FileUtils.rm_rf dir;
waitfor { !exists?(dir) }
end
if dir == 'artifacts'
Dir.mkdir 'artifacts'
end
end
def cleanFile(file)
File.delete file unless !File.exist?(file)
end