-
Notifications
You must be signed in to change notification settings - Fork 0
/
RakeFile
140 lines (123 loc) · 4.8 KB
/
RakeFile
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
require 'yaml'
# path when build tools is installed from https://www.visualstudio.com/thank-you-downloading-visual-studio/?sku=BuildTools&rel=15
MSBUILD1 = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\MSBuild\\Current\\Bin\\"
MSBUILD2 = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\MSBuild\\15.0\\Bin\\"
MSBUILD3 = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\MSBuild\\15.0\\Bin\\" # path when VS is installed
$MSBUILD = MSBUILD1
if !Dir.exist?($MSBUILD)
$MSBUILD = MSBUILD2
if !Dir.exist?($MSBUILD)
$MSBUILD = MSBUILD3
if !Dir.exist?($MSBUILD)
puts "Can't find MsBuild.exe in #{MSBUILD1} or #{MSBUILD2}"
exit 1 # failure
end
end
end
$MSBUILD = $MSBUILD + "msbuild.exe"
PRODUCT_NAME = "FluentBrowserAutomation"
DEFAULT_BUILD_NUMBER = "0.9.0"
COMPANY_NAME = "MVBA, P.C."
COPYRIGHT = "MVBA, P.C. (c) 2010-2020"
ARTIFACTS = File.expand_path("dist")
COMPILE_TARGET = "Debug"
SETTINGS_DIR = "settings"
beginning = Time.now
default_settings = { :artifacts => ARTIFACTS,
:compile_target => COMPILE_TARGET,
}
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, :pack] do
puts "Build Succeeded - time elapsed: #{Time.now - beginning} seconds"
end
desc "Create Directory.Build.props file"
task :assemblyinfo do
build_number = get_build_number
git_hash = get_git_hash
puts "Writing src/Directory.Build.props file..."
File.open('src/Directory.Build.props', 'w') do |file|
file.write "<Project>\n"
file.write " <PropertyGroup>\n"
file.write " <Authors>#{COMPANY_NAME}</Authors>\n"
file.write " <Company>#{COMPANY_NAME}</Company>\n"
file.write " <Description>A fluent domain-specific language (DSL) around Web Driver. (git sha for this version: #{git_hash})</Description>\n"
file.write " <Copyright>#{COPYRIGHT}</Copyright>\n"
file.write " <PackageLicenseFile>License.txt</PackageLicenseFile>\n"
file.write " <NeutralLanguage>en-US</NeutralLanguage>\n"
file.write " <RepositoryUrl>https://github.com/mvbalaw/#{PRODUCT_NAME}</RepositoryUrl>\n"
file.write " <RepositoryType>git</RepositoryType>\n"
file.write " <Version>#{build_number}</Version>\n"
file.write " <FileVersion>#{build_number}</FileVersion>\n"
file.write " <ProductName>#{PRODUCT_NAME}</ProductName>\n"
file.write " </PropertyGroup>\n"
file.write "\n"
file.write " <ItemGroup>\n"
file.write " <Content Include=\"..\\..\\License.txt\" Pack=\"true\" Visible=\"false\" PackagePath=\"\" />"
file.write " </ItemGroup>\n"
file.write "</Project>\n"
end
end
desc "Builds the #{PRODUCT_NAME} solution"
task :build => [:clean, :assemblyinfo] do |msb|
puts
puts "Compiling #{PRODUCT_NAME} in #{settings[:compile_target]} mode..."
puts
sh "\"#{$MSBUILD}\" -t:restore /verbosity:quiet /target:#{:Rebuild} /nologo /p:Configuration=#{settings[:compile_target]} src/#{PRODUCT_NAME}.sln"
end
desc "Prepare the working directory for a new build"
task :clean do
Dir.mkdir settings[:artifacts] unless Dir.exists?(settings[:artifacts])
end
desc "Create nuget package"
task :pack do
puts
puts "Creating nuget package for #{PRODUCT_NAME} in artifact folder (#{settings[:artifacts]})..."
puts
sh "\"#{$MSBUILD}\" /p:PackageOutputPath=\"#{settings[:artifacts]}\" -t:pack /verbosity:quiet /nologo src/#{PRODUCT_NAME}/#{PRODUCT_NAME}.csproj"
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_git_hash
begin
gittag = `git describe --long`.chomp # looks something like v0.1.0-63-g3f10c2e
parts = gittag.split("-")
git_hash = parts[2]
rescue
git_hash = "git unavailable"
end
end