Top Level Namespace
Defined Under Namespace
Classes: Dependency, SemverVersioning, Transform, Update
Constant Summary
collapse
- VERSIONING =
'versioning'
Instance Method Summary
collapse
-
#add_files(stage, what_dlls, nuspec, folder = 'lib') ⇒ Object
-
#auto_add_dependencies(project, nuspec) ⇒ Object
-
#auto_update_local_semver ⇒ Object
-
#auto_update_semver(project_name, semver_location, semver_file, semver_dimension) ⇒ Object
-
#check_devkit ⇒ Object
-
#check_gems ⇒ Object
check and install required gems.
-
#check_package_version_dependency(package_uri, package, version = 'IsLatestVersion') ⇒ Object
-
#check_ruby ⇒ Object
-
#clean_build(msb, solution) ⇒ Object
-
#cleantask(props) ⇒ Object
-
#commit_data ⇒ Object
-
#copy_full_directory(fromDir, outDir) ⇒ Object
-
#copy_output_files(fromDir, filePattern, outDir) ⇒ Object
-
#copy_runtime_artifacts(package) ⇒ Object
-
#download_file(sourcePath, filePath, localFileLocation) ⇒ Object
-
#each_package(packages_config) ⇒ Object
-
#each_package_dependency(project) ⇒ Object
-
#gem_exists(name, version) ⇒ Object
-
#get_commit_hash_and_date ⇒ Object
-
#install_file(cmd, versionedExeFile) ⇒ Object
-
#is_team_city_run ⇒ Object
-
#package(rake_files_path, task_list) ⇒ Object
Gathers all rake files and runs the task list.
-
#project_outputs(props) ⇒ Object
-
#restore_nuget(nuget_exe) ⇒ Object
-
#restore_project_pkgs(proj) ⇒ Object
-
#set_framework_version(asm) ⇒ Object
-
#set_solution_version(asm) ⇒ Object
-
#set_version(asm, version, file_version, assembly_version, output_file, output_file_src = 'src') ⇒ Object
-
#teamcity_build_number ⇒ Object
Tell teamcity our decision to set the build.number environment variable.
-
#versioning(project = nil, file = nil) ⇒ Object
-
#waitfor(&block) ⇒ Object
Instance Method Details
#add_files(stage, what_dlls, nuspec, folder = 'lib') ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/build.rb', line 34
def add_files stage, what_dlls, nuspec, folder='lib'
[['net35', 'net-3.5'], ['net40', 'net-4.0'], ['net45', 'net-4.5']].each{|fw|
takeFrom = File.join(stage, fw[1], what_dlls)
Dir.glob(takeFrom).each do |f|
nuspec.file(f.gsub("/", "\\"), "#{folder}\\#{fw[0]}")
end
}
end
|
#auto_add_dependencies(project, nuspec) ⇒ Object
1
2
3
4
5
6
7
8
9
10
11
|
# File 'lib/dependency.rb', line 1
def auto_add_dependencies(project, nuspec)
@Dependencies = Array.new
each_package_dependency(project) do |package|
@Dependencies << package
end
@Dependencies.each do |dep|
nuspec.dependency dep.Name, dep.Version
end
end
|
#auto_update_local_semver ⇒ Object
#auto_update_semver(project_name, semver_location, semver_file, semver_dimension) ⇒ Object
269
270
271
272
|
# File 'lib/semantic_versioning.rb', line 269
def auto_update_semver project_name, semver_location, semver_file, semver_dimension
versioning = SemverVersioning.new
versioning.auto_update_semver project_name, semver_location, semver_file, semver_dimension
end
|
#check_devkit ⇒ Object
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
|
# File 'lib/install.rb', line 94
def check_devkit
puts 'Checking devkit version...'
rubyPath = `where.exe ruby.exe`
rubyPath['bin\ruby.exe'] = 'devkit'
rubyPath = rubyPath.sub("\n", '') if (!File.directory?(rubyPath))
puts 'devkit not found'
puts 'Downloading devkit...'
sourcePath = 'cdn.rubyinstaller.org'
versionedExeFile = $selected_version[:devkit]
filePath = "/archives/devkits/#{versionedExeFile}?direct"
return false if !download_file(sourcePath, filePath, versionedExeFile)
puts 'Devkit installation in progress...'
cmd = "#{versionedExeFile} -y -o\"#{rubyPath}\"" puts cmd
return false if !install_file(cmd, versionedExeFile)
puts 'Setting up devkit...'
Dir.chdir "#{rubyPath}"
cmd = 'ruby dk.rb init'
cmdoutput = `#{cmd}`
puts cmdoutput
if !cmdoutput.to_s.include?('Initialization complete!')
puts 'Error: could not initialize devkit.'
return false
end
cmd = 'ruby dk.rb review'
cmdoutput = `#{cmd}`
puts cmdoutput
if !cmdoutput.to_s.include?('DevKit functionality will be injected')
puts 'Error: devkit review failed'
return false
end
cmd = 'ruby dk.rb install'
cmdoutput = `#{cmd}`
puts cmdoutput
puts 'Restart console since environment variables are now updated'
return false
end
puts 'devkit ok'
return true
end
|
#check_gems ⇒ Object
check and install required gems
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/install.rb', line 146
def check_gems
puts 'Checking required gems...'
$selected_version[:gems].each {|key, value|
if !gem_exists(key, "=#{value}")
begin
puts "Installing missing gem: #{key}"
cmd = "gem install --user-install #{key} -v #{value}"
cmdoutput = `#{cmd}`
puts cmdoutput
rescue
puts 'gem install failed'
puts $!
return false end
end
}
return true
end
|
#check_package_version_dependency(package_uri, package, version = 'IsLatestVersion') ⇒ Object
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
# File 'lib/build.rb', line 179
def check_package_version_dependency package_uri, package, version='IsLatestVersion'
response = Net::HTTP.get_response(URI.parse(package_uri.sub('pkg', package))) package_info = response.body
xml = Nokogiri::XML package_info
xml.xpath("//m:properties/d:#{version}").each { |e|
if e.text.to_s == 'true'
version = e.parent.xpath('d:Version').text
end
}
config_files = Dir.glob '**/packages.config'
config_files.each{ |file|
doc = Nokogiri::XML(File.read file)
node = doc.at_xpath("//*[@id=\"#{package}\"]")
if !node.nil?
config_version = node.attr('version')
puts "Package: #{package} Latest Version: #{version} File: #{file} File package version: #{config_version}"
return false unless config_version.to_s == version
end
}
return true
end
|
#check_ruby ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/install.rb', line 75
def check_ruby
puts 'Checking ruby version...'
rubyVersion = "#{RUBY_VERSION}"
localVersion = "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
expectedVersion1 = '1.9.3-p551'
expectedVersion2 = '2.0.0-p481'
if (!rubyVersion.nil? && (localVersion != expectedVersion1 && localVersion != expectedVersion2))
puts "Uninstall incompatible version of ruby: #{localVersion} and install version: #{expectedVersion1} or #{expectedVersion2}. Then Restart rake. Goto http://rubyinstaller.org/downloads/"
return false
end
$selected_version = $version_map[localVersion]
puts 'Ruby ok'
return true
end
|
#clean_build(msb, solution) ⇒ Object
100
101
102
103
104
105
106
|
# File 'lib/build.rb', line 100
def clean_build msb, solution
msb.properties :Configuration => 'Release',
:Platform => 'Any CPU',
:VisualStudioVersion => '12.0'
msb.use :net4
msb.solution = solution
end
|
#cleantask(props) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/build.rb', line 67
def cleantask props
if props.has_key?(:output) && File.directory?(props[:output])
FileUtils.rm_rf props[:output]
waitfor { !exists?(props[:output]) }
end
if props.has_key?(:artifacts) && File.directory?(props[:artifacts])
FileUtils.rm_rf props[:artifacts]
waitfor { !exists?(props[:artifacts]) }
end
if props.has_key?(:output)
Dir.mkdir props[:output]
end
if props.has_key?(:artifacts)
Dir.mkdir props[:artifacts]
end
end
|
#commit_data ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/build.rb', line 43
def commit_data
begin
commit = `git rev-parse --short HEAD`.chomp()[0,6]
git_date = `git log -1 --date=iso --pretty=format:%ad`
commit_date = DateTime.parse( git_date ).strftime("%Y-%m-%d %H%M%S")
rescue Exception => e
puts e.inspect
commit = (ENV['BUILD_VCS_NUMBER'] || "000000")[0,6]
commit_date = Time.new.strftime("%Y-%m-%d %H%M%S")
end
[commit, commit_date]
end
|
#copy_full_directory(fromDir, outDir) ⇒ Object
11
12
13
|
# File 'lib/build.rb', line 11
def copy_full_directory fromDir, outDir
FileUtils.cp_r(File.join(fromDir, "."), outDir)
end
|
#copy_output_files(fromDir, filePattern, outDir) ⇒ Object
4
5
6
7
8
9
|
# File 'lib/build.rb', line 4
def copy_output_files fromDir, filePattern, outDir
FileUtils.mkdir_p outDir unless exists?(outDir)
Dir.glob(File.join(fromDir, filePattern)){|file|
copy(file, outDir) if File.file?(file)
}
end
|
#copy_runtime_artifacts(package) ⇒ Object
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
# File 'lib/build.rb', line 207
def copy_runtime_artifacts package
config_files = Dir.glob '**/packages.config'
config_version = ''
config_files.each{ |file|
doc = Nokogiri::XML(File.read file)
node = doc.at_xpath("//*[@id=\"#{package}\"]")
if !node.nil?
config_version = node.attr('version').to_s
break
end
}
puts config_version
source = "#{ENV['RuntimePath']}/#{config_version}"
dest = File.join(File.expand_path('.'), 'RuntimeService')
puts source
puts dest
copy_full_directory source, dest
end
|
#download_file(sourcePath, filePath, localFileLocation) ⇒ Object
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/install.rb', line 2
def download_file(sourcePath, filePath, localFileLocation)
Net::HTTP.start(sourcePath) do |http|
resp = http.get(filePath)
f = open(localFileLocation, 'wb')
begin
requestPath = "http://#{sourcePath}#{filePath}"
puts "Downloading #{requestPath}..."
http.request_get(requestPath) do |resp|
resp.read_body do |segment|
f.write(segment)
end
end
rescue
puts $!
return false
ensure
f.close()
end
end
return true
end
|
#each_package(packages_config) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/dependency.rb', line 24
def each_package(packages_config)
xml = File.read packages_config
doc = REXML::Document.new xml
doc.elements.each 'packages/package' do |package|
if block_given?
yield package.attributes['id'], package.attributes['version']
else
"no package block"
end
end
end
|
#each_package_dependency(project) ⇒ Object
14
15
16
17
18
19
20
21
|
# File 'lib/dependency.rb', line 14
def each_package_dependency(project)
packages_config = File.join File.dirname(project), 'packages.config'
return [] unless File.exists? packages_config
each_package packages_config do |id, version|
yield Dependency.new id, version
end
end
|
#gem_exists(name, version) ⇒ Object
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/install.rb', line 40
def gem_exists(name, version)
begin
gem name, version
rescue Gem::LoadError
puts "failed to load gem #{name} -v #{version}"
Gem.clear_paths
return false
end
return true
end
|
#get_commit_hash_and_date ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/build.rb', line 22
def get_commit_hash_and_date
begin
commit = `git log -1 --pretty=format:%H`
git_date = `git log -1 --date=iso --pretty=format:%ad`
commit_date = DateTime.parse( git_date ).strftime("%Y-%m-%d %H%M%S")
rescue
commit = "git unavailable"
end
[commit, commit_date]
end
|
#install_file(cmd, versionedExeFile) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/install.rb', line 24
def install_file(cmd, versionedExeFile)
begin
installerOutput = `#{cmd}`
puts installerOutput
rescue
puts $!
return false
ensure
puts 'Cleaning up...'
cmd = "#{versionedExeFile}"
installerOutput = `del #{cmd}`
puts installerOutput
end
return true
end
|
#is_team_city_run ⇒ Object
279
280
281
|
# File 'lib/semantic_versioning.rb', line 279
def is_team_city_run
ENV['BUILD_VCS_NUMBER'] != nil
end
|
#package(rake_files_path, task_list) ⇒ Object
Gathers all rake files and runs the task list
233
234
235
236
237
238
239
240
241
242
243
244
|
# File 'lib/build.rb', line 233
def package rake_files_path, task_list
if task_list.nil?
puts "No task to execute"
else
Dir.glob("#{rake_files_path}/*.rb").each {
|r| load r
}
task_list.each { |eachtask|
Rake::Task["#{eachtask}"].invoke
}
end
end
|
#project_outputs(props) ⇒ Object
16
17
18
19
20
|
# File 'lib/build.rb', line 16
def project_outputs props
props[:projects].map{ |p| "src/#{p}/bin/#{BUILD_CONFIG}/#{p}.dll" }.
concat( props[:projects].map{ |p| "src/#{p}/bin/#{BUILD_CONFIG}/#{p}.exe" } ).
find_all{ |path| exists?(path) }
end
|
#restore_nuget(nuget_exe) ⇒ Object
87
88
89
90
|
# File 'lib/build.rb', line 87
def restore_nuget nuget_exe
sh 'powershell', '-Command', "& { Invoke-RestMethod https://www.nuget.org/nuget.exe -OutFile '#{Dir.pwd}/#{nuget_exe}' }"
sh "#{Dir.pwd}/#{nuget_exe}", 'restore', "src/#{PRODUCT}.sln"
end
|
#restore_project_pkgs(proj) ⇒ Object
92
93
94
95
96
97
98
|
# File 'lib/build.rb', line 92
def restore_project_pkgs proj
msbuild :nuget_restore do |msb|
msb.use :net4
msb.targets :RestorePackages
msb.solution = proj
end
end
|
#set_framework_version(asm) ⇒ Object
156
157
158
|
# File 'lib/build.rb', line 156
def set_framework_version asm
set_version asm, $versionMap[:formal_version], $versionMap[:formal_version], $versionMap[:build_version], 'Framework'
end
|
#set_solution_version(asm) ⇒ Object
160
161
162
|
# File 'lib/build.rb', line 160
def set_solution_version asm
set_version asm, $versionMap[:platform_version], $versionMap[:platform_version], $versionMap[:platform_build_version], 'Solution'
end
|
#set_version(asm, version, file_version, assembly_version, output_file, output_file_src = 'src') ⇒ Object
164
165
166
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/build.rb', line 164
def set_version asm, version, file_version, assembly_version, output_file, output_file_src='src'
asm.product_name = PRODUCT
asm.description = PRODUCT_DESCRIPTION
asm.version = version
asm.file_version = file_version
asm.custom_attributes :AssemblyInformationalVersion => assembly_version,
:ComVisibleAttribute => false,
:CLSCompliantAttribute => true
asm.copyright = COPYRIGHT
asm.output_file = "#{output_file_src}/#{output_file}.Version.cs"
asm.namespaces 'System', 'System.Reflection', 'System.Runtime.InteropServices'
end
|
#teamcity_build_number ⇒ Object
Tell teamcity our decision to set the build.number environment variable
151
152
153
154
|
# File 'lib/build.rb', line 151
def teamcity_build_number
platform_version = Time.new.strftime('%y.%-m.%-d') + ".#{(ENV['BUILD_NUMBER'] || '0')}"
puts "##teamcity[buildNumber '#{platform_version}']"
end
|
#versioning(project = nil, file = nil) ⇒ Object
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
|
# File 'lib/build.rb', line 108
def versioning project=nil, file=nil
if !project.nil? && !file.nil?
v = SemVer.new
path = File.join VERSIONING, file
v.load path
ver = v
commitData = commit_data()
ENV["#{project}_NUGET_VERSION"] = ver.format('%M.%m.%p%s')
ENV["#{project}_BUILD_VERSION"] = ver.format('%M.%m.%p%s') + ".#{commitData[0]}"
sem = SemVer.new(ver.major, ver.minor, ver.patch).format '%M.%m.%p'
build_counter = (ENV['BUILD_COUNTER'] || '0').to_i
ENV["#{project}_FORMAL_VERSION"] = "#{sem}.#{build_counter}"
else
ver = SemVer.find
commitData = commit_data()
build_counter = (ENV['BUILD_COUNTER'] || '0').to_i
ENV['BUILD_VERSION'] = $versionMap[:build_version] = ver.format('%M.%m.%p%s') + ".#{commitData[0]}"
ENV['NUGET_VERSION'] = $versionMap[:nuget_version] = ver.format('%M.%m.%p%s')
ENV['PLATFORM_VERSION'] = $versionMap[:platform_version] = Time.new.strftime('%y.%-m.%-d') + ".#{build_counter}"
ENV['PLATFORM_BUILD_VERSION'] = $versionMap[:platform_build_version] = Time.new.strftime('%y.%-m.%-d') + ".#{commitData[0]}"
sem = SemVer.new(ver.major, ver.minor, ver.patch).format '%M.%m.%p'
ENV['FORMAL_VERSION'] = $versionMap[:formal_version] = "#{sem}.#{build_counter}"
teamcity_build_number
end
end
|
#waitfor(&block) ⇒ Object
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/build.rb', line 56
def waitfor &block
checks = 0
until block.call || checks >10
sleep 0.5
checks += 1
end
raise 'Waitfor timeout expired. Make sure that you aren\'t running something from the build output folders, or that you have browsed to it through Explorer.' if checks > 10
end
|