forked from jweber/WcfClientProxyGenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rakefile.rb
168 lines (135 loc) · 5.38 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
require 'albacore'
require 'fileutils'
require 'semver'
CLR_TOOLS_VERSION = 'v4.0.30319'
ARTIFACTS_PATH = "build"
PROJECT_NAME = "WcfClientProxyGenerator"
$config = ENV['config'] || 'Debug'
$nuget_api_key = ENV['nuget_api_key']
task :default => :compile
desc 'Generate the VersionInfo.cs class'
assemblyinfo :version => [:versioning] do |asm|
git_data = commit_data()
revision_hash = git_data[0]
revision_date = git_data[1]
asm.version = FORMAL_VERSION
asm.file_version = FORMAL_VERSION
asm.product_name = PROJECT_NAME
asm.description = "Git commit hash: #{revision_hash} - #{revision_date}"
asm.custom_attributes :AssemblyInformationalVersion => "#{BUILD_VERSION}"
asm.output_file = "source/VersionInfo.cs"
asm.namespaces 'System', 'System.Reflection'
end
desc 'Compile the project'
task :compile => ['nuget:restore'] do
Rake::Task['build:net45'].invoke()
end
namespace :build do
task :all => [:net45] do
end
msbuild :net45 => ["nuget:restore", "version"] do |msb|
msb.properties :configuration => $config, :Framework => 'NET45'
msb.targets [:clean, :build]
msb.solution = "source/#{PROJECT_NAME}.sln"
end
end
desc 'Run tests'
nunit :test => :compile do |nunit|
include FileUtils
mkpath ARTIFACTS_PATH unless Dir.exists? ARTIFACTS_PATH
nunit.command = nunit_path
nunit.assemblies "source/#{PROJECT_NAME}.Tests/bin/#{$config}/#{PROJECT_NAME}.Tests.dll"
#nunit.options '/xml=nunit-console-output.xml'
nunit.options = "/framework=#{CLR_TOOLS_VERSION}", '/noshadow', '/nologo', '/labels', "\"/xml=#{File.join(ARTIFACTS_PATH, "nunit-test-results.xml")}\""
end
desc 'Builds release package'
task :package => 'build:all' do
include FileUtils
assemble_path = File.join(ARTIFACTS_PATH, "assemble")
mkpath ARTIFACTS_PATH unless Dir.exists? ARTIFACTS_PATH
rm_rf Dir.glob(File.join(ARTIFACTS_PATH, "**/*.zip"))
rm_rf assemble_path if Dir.exists? assemble_path
mkpath assemble_path unless Dir.exists? assemble_path
rm_rf Dir.glob(File.join(assemble_path, "**/*"))
cp_r Dir.glob("source/#{PROJECT_NAME}/bin/#{$config}/**"), assemble_path, :verbose => true
rm Dir.glob("#{assemble_path}/log.*")
zip_directory(assemble_path, File.join(ARTIFACTS_PATH, "#{PROJECT_NAME}-#{BUILD_VERSION}.zip"))
rm_rf assemble_path if Dir.exists? assemble_path
end
namespace :nuget do
desc 'Restores nuget packages'
task :restore do
solution_path = "source/#{PROJECT_NAME}.sln"
sh "#{nuget_path} restore #{solution_path} -verbosity normal"
end
desc 'Creates the nuspec file'
nuspec :spec => :version do |nuspec|
mkpath ARTIFACTS_PATH unless Dir.exists? ARTIFACTS_PATH
nuspec.id = PROJECT_NAME
nuspec.version = ENV['NUGET_VERSION']
nuspec.authors = "j.weber"
nuspec.description = "Utility to generate fault tolerant and highly configurable client proxies for WCF services based on WCF ServiceContracts. Supports making async calls using non async-ready ServiceContracts."
nuspec.projectUrl = "https://github.com/jweber/WcfClientProxyGenerator"
nuspec.title = PROJECT_NAME
nuspec.tags = "wcf service client proxy dynamic async"
nuspec.file "..\\source\\#{PROJECT_NAME}\\bin\\#{$config}\\#{PROJECT_NAME}.dll", 'lib\net45'
nuspec.file "..\\source\\#{PROJECT_NAME}\\bin\\#{$config}\\#{PROJECT_NAME}.xml", 'lib\net45'
nuspec.working_directory = 'build'
nuspec.output_file = "#{PROJECT_NAME}.nuspec"
end
desc 'Build nupkg'
nugetpack :pack => ['build:all', :spec] do |nuget|
nuget.command = nuget_path
nuget.nuspec = "build\\#{PROJECT_NAME}.nuspec"
nuget.base_folder = 'build'
nuget.output = 'build'
end
nugetpush :push => [:pack] do |nuget|
raise "No NuGet API key was defined" unless $nuget_api_key
nuget.command = nuget_path
nuget.package = "build\\#{PROJECT_NAME}.#{ENV['NUGET_VERSION']}.nupkg"
nuget.create_only = false
nuget.apikey = $nuget_api_key
nuget.create_only = false
end
end
desc 'Builds version environment variables'
task :versioning do
ver = SemVer.find
#revision = (ENV['BUILD_NUMBER'] || ver.patch).to_i
#ver = SemVer.new(ver.major, ver.minor, revision, ver.special)
if ver.special != ''
ENV['BUILD_VERSION'] = BUILD_VERSION = ver.format("%M.%m.%p.%s") + ".#{commit_data()[0]}"
ENV['NUGET_VERSION'] = NUGET_VERSION = ver.format("%M.%m.%p-%s")
else
ENV['BUILD_VERSION'] = BUILD_VERSION = ver.format("%M.%m.%p") + ".#{commit_data()[0]}"
ENV['NUGET_VERSION'] = NUGET_VERSION = ver.format("%M.%m.%p")
end
ENV['FORMAL_VERSION'] = FORMAL_VERSION = "#{ ver.format("%M.%m.%p")}"
puts "##teamcity[buildNumber '#{BUILD_VERSION}']"
end
def nunit_path()
File.join(Dir.glob(File.join('source', 'packages', "nunit.runners.*")).sort.last, "tools", "nunit-console.exe")
end
def nuget_path()
File.join('lib', 'NuGet.exe')
end
def zip_directory(assemble_path, output_path)
zip = ZipDirectory.new
zip.directories_to_zip assemble_path
zip.output_path = File.dirname(output_path)
zip.output_file = File.basename(output_path)
zip.execute
end
def commit_data
begin
commit = `git rev-parse --short HEAD`.chomp()
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")
commit_date = Time.new.strftime("%Y-%m-%d %H%M%S")
end
[commit, commit_date]
end