forked from git-tfs/git-tfs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
168 lines (147 loc) · 4.22 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
require 'rubygems'
require 'bundler/setup'
require 'albacore'
require 'rexml/document'
require 'jeweler/version_helper'
require 'git'
task :default => %W(
build
runtests
)
def build task_name, *targets
build_properties = { :configuration => 'Debug', :platform => 'x86' }
build_properties.merge!(targets.pop) if Hash === targets.last
msbuild task_name do |msb|
msb.properties build_properties
msb.targets targets
msb.solution = 'GitTfs.sln'
end
end
task :build => 'build:debug'
namespace :build do
desc "Build in debug mode"
build :debug, 'Build'
task :debug
desc "Build in release mode"
build :release, 'Build', :configuration => 'Release'
task :release
end
desc 'Run the tests'
task :runtests do
rm 'results.trx' if File.exist? 'results.trx'
mstest_cmd =%W(mstest
/testcontainer:GitTfsTest\\bin\\Debug\\GitTfsTest.dll
/resultsfile:results.trx)
sh(*mstest_cmd) do |ok, status|
analyze_tests('results.trx')
end
end
def analyze_tests(results_file)
fail_count = 0
File.open(results_file) do |file|
xml =REXML::Document.new(file)
xml.elements.each '//UnitTestResult[@outcome="Failed"]' do |e|
puts ''
puts '**********************************'
puts e.attributes['testName']
puts e.elements['Output/ErrorInfo/Message'].get_text.value
puts e.elements['Output/ErrorInfo/StackTrace'].get_text.value
%W(StdOut StdErr).each do |s|
show_stream e, s
end
puts ''
fail_count = fail_count.succ
end
end
fail "#{fail_count} tests failed" if fail_count > 0
end
def show_stream(e, s)
data = e.elements["Output/#{s}"]
if data
puts "#{s}:", data.get_text.value
end
end
desc "Package a release zip"
task :release => ['checks:clean_workdir', 'build:release', 'zip:release', 'tag']
namespace :checks do
task :clean_workdir do
unless clean_working_dir?
system 'git status'
raise "Unclean working directory! Be sure to commit or .gitignore everything first!"
end
end
end
namespace :zip do
zip :release do |zip|
zip.directories_to_zip 'GitTfs/bin/Release'
zip.output_file = "GitTfs-#{version_helper.to_s}.zip"
zip.output_path = File.expand_path('../pkg', __FILE__)
end
task :release => :pkg
end
directory 'pkg'
def version_helper
@version_helper ||= Jeweler::VersionHelper.new(File.dirname(__FILE__))
end
def repo
@repo ||= Git.open(File.dirname(__FILE__))
end
def commit opts
repo.add opts[:files]
repo.commit opts[:message]
end
def clean_working_dir?
`git ls-files --deleted --modified --others --exclude-standard` == ''
end
desc 'Show the current version'
task :version do
$stdout.puts "Current version: #{version_helper.to_s}"
end
namespace :version do
task :cs do
File.open('Version.cs', 'w') do |f|
f.puts(
'partial class GitTfsProperties',
'{',
" public const string Version = \"#{version_helper.to_s}\";",
'}'
)
end
$stdout.puts 'Wrote Version.cs'
Rake::Task['version:cs'].reenable
end
namespace :bump do
desc "Bump to next major version"
task :major => :version do
version_helper.bump_major
version_helper.write
$stdout.puts "Updated version to #{version_helper.to_s}"
Rake::Task['version:cs'].invoke
commit(:files => ['VERSION', 'Version.cs'], :message => "Bumped to version #{version_helper.to_s}")
end
desc "Bump to next minor version"
task :minor => :version do
version_helper.bump_minor
version_helper.write
$stdout.puts "Updated version to #{version_helper.to_s}"
Rake::Task['version:cs'].invoke
commit(:files => ['VERSION', 'Version.cs'], :message => "Bumped to version #{version_helper.to_s}")
end
desc "Bump to next patch version"
task :patch => :version do
version_helper.bump_patch
version_helper.write
$stdout.puts "Updated version to #{version_helper.to_s}"
Rake::Task['version:cs'].invoke
commit(:files => ['VERSION', 'Version.cs'], :message => "Bumped to version #{version_helper.to_s}")
end
end
end
task :tag do
release_tag = "v#{version_helper.to_s}"
tag = repo.tag(release_tag) rescue nil
unless tag
$stdout.puts "Tagging #{release_tag}"
repo.add_tag(release_tag)
end
end