-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Rakefile
66 lines (50 loc) · 2.5 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
CONFIG = ENV['CONFIG'] || 'Debug'
COVERAGE_DIR = 'Coverage'
ASSEMBLY_INFO = 'src/StateMechanic/Properties/AssemblyInfo.cs'
NUSPEC = 'NuGet/StateMechanic.nuspec'
CSPROJ = 'src/StateMechanic/StateMechanic.csproj'
MSBUILD = %q{C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe}
GITLINK_REMOTE = 'https://github.com/canton7/StateMechanic'
directory COVERAGE_DIR
desc "Create NuGet package"
task :package do
local_hash = `git rev-parse HEAD`.chomp
sh "NuGet/GitLink.exe . -s #{local_hash} -u #{GITLINK_REMOTE} -f src/StateMechanic.sln -ignore StateMechanicUnitTests"
Dir.chdir(File.dirname(NUSPEC)) do
sh "nuget.exe pack #{File.basename(NUSPEC)}"
end
end
desc "Bump version number"
task :version, [:version] do |t, args|
parts = args[:version].split('.')
parts << '0' if parts.length == 3
version = parts.join('.')
content = IO.read(ASSEMBLY_INFO)
content[/^\[assembly: AssemblyVersion\(\"(.+?)\"\)\]/, 1] = version
content[/^\[assembly: AssemblyFileVersion\(\"(.+?)\"\)\]/, 1] = version
File.open(ASSEMBLY_INFO, 'w'){ |f| f.write(content) }
content = IO.read(NUSPEC)
content[/<version>(.+?)<\/version>/, 1] = args[:version]
File.open(NUSPEC, 'w'){ |f| f.write(content) }
end
desc "Build the project for release"
task :build do
sh MSBUILD, CSPROJ, "/t:Clean;Rebuild", "/p:Configuration=Release", "/verbosity:normal"
end
task :test_environment do
NUNIT_TOOLS = 'src/packages/NUnit.ConsoleRunner.*/tools'
NUNIT_CONSOLE = Dir[File.join(NUNIT_TOOLS, 'nunit3-console.exe')].first
OPENCOVER_CONSOLE = Dir['src/packages/OpenCover.*/tools/OpenCover.Console.exe'].first
REPORT_GENERATOR = Dir['src/packages/ReportGenerator.*/tools/ReportGenerator.exe'].first
UNIT_TESTS_DLL = "bin/#{CONFIG}/StateMechanicUnitTests.dll"
raise "NUnit.ConsoleRunner not found. Restore NuGet packages" unless NUNIT_CONSOLE
raise "OpenCover not found. Restore NuGet packages" unless OPENCOVER_CONSOLE
raise "ReportGenerator not found. Restore NuGet packages" unless REPORT_GENERATOR
end
desc "Generate unit test code coverage reports for CONFIG (or Debug)"
task :cover => [:test_environment, COVERAGE_DIR] do
coverage_file = File.join(COVERAGE_DIR, File.basename(UNIT_TESTS_DLL).ext('xml'))
sh %Q{#{OPENCOVER_CONSOLE} -register:user -target:"#{NUNIT_CONSOLE}" -targetargs:"#{UNIT_TESTS_DLL}" -filter:"+[StateMechanic]*" -excludebyattribute:*.ExcludeFromCoverageAttribute -output:"#{coverage_file}"}
rm('TestResult.xml', :force => true)
sh %Q{#{REPORT_GENERATOR} -reports:"#{coverage_file}" -targetdir:#{COVERAGE_DIR}}
end