forked from nspec/NSpec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakeFile
169 lines (129 loc) · 4.96 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
169
require 'nokogiri'
require 'cgi'
require 'zip/zipfilesystem'
desc 'build'
task :build do
sh 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe NSpec.sln'
end
desc 'run specs'
task :spec => :build do
sh '"C:\program files (x86)\nunit 2.5.9\bin\net-2.0\nunit-console-x86.exe" NSpecSpecs/bin/Debug/NSpecSpecs.dll'
end
task :pull do
result = `git pull`
raise 'Merge Required' if result.include? 'Aborting'
end
task :commit => :pull do
`git add -A .`
`git commit -m "#{ENV['m']}`
`git push`
`git tag -a v#{get_version_node.text} -m "#{get_version_node.text}" HEAD`
`git push --tags`
end
desc 'supply commit message as parameter - rake all m="commit message" - version bump, nuget, zip and everything shall be done for you'
task :all => [:pull,:version,:nuget,:commit,:website,:zip,:upload]
task :zip do
fileName = create_zip_filename
File.delete(fileName) if File.exists? fileName
Zip::ZipFile.open(fileName, Zip::ZipFile::CREATE) {
|zipfile|
zipfile.add 'NSpecRunner.exe', 'NSpecRunner\bin\Debug\NSpecRunner.exe'
zipfile.add 'NSpec.dll', 'NSpecRunner\bin\Debug\NSpec.dll'
zipfile.add 'nunit.framework.dll', 'NSpecRunner\bin\Debug\nunit.framework.dll'
}
end
task :version => :bump_version do
lines = ["[assembly: AssemblyVersion(\"#{get_version_node.text}\")]",
"[assembly: AssemblyFileVersion(\"#{get_version_node.text}\")]"]
Dir['NSpec*/**/AssemblyInfo.cs'].each {|f| update_version f,lines}
end
def update_version file, version_lines
newlines = (File.read file).split("\n")[0..-3] + version_lines
File.open(file, 'w') {|f| f.write(newlines.join("\n"))}
end
def create_zip_filename
"NSpec-#{get_version_node.text}.zip"
end
task :upload do
sh "upload.bat #{create_zip_filename}"
end
desc 'Increments version number.'
task :bump_version do
node = get_version_node
nextVer = "0.9." + (node.text.split('.').last.to_i + 1).to_s
xml = Nokogiri::XML(File.read 'nspec.nuspec')
xml.root.default_namespace = "http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"
node = xml.root.xpath('//xmlns:version')[0]
node.inner_html = nextVer
File.open("nspec.nuspec", 'w') {|f| f.write(xml.to_xml) }
end
desc 'create and upload a nuget package. requires deploy.bat with secure hash to be in your path. autoincrements version number.'
task :nuget => :spec do
Dir['nspec*{nupkg}'].each {|f| File.delete(f)}
sh 'nuget.exe pack nspec.nuspec'
sh "deployNuget.bat #{Dir['*{nupkg}'][0]}"
end
def get_version_node
xml = Nokogiri::XML(File.read 'nspec.nuspec')
xml.root.default_namespace = "http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"
xml.root.xpath('//xmlns:version')[0]
end
desc 'run SampleSpecs with NSpecRunner. you can supply a single spec like so -> rake samples[spec_name]'
task :samples, :spec do |t,args|
spec = args[:spec] || ''
sh "NSpecRunner/bin/debug/NSpecRunner.exe SampleSpecs/bin/debug/SampleSpecs.dll #{spec}"
end
desc 'supply the current tutorial markup in source.html and generate new.html containing current source code and output'
task :website => :spec do
if File.exists? 'source.html'
@doc = Nokogiri::HTML.fragment(File.read 'source.html')
Dir['SampleSpecs/WebSite/**/*.*'].each {|f| run f}
t = Time.now
time = t.strftime("on %m/%d/%Y") + t.strftime(" at %I:%M%p")
timestamp = "Sample code and output automatically executed against nspec version #{get_version_node.text} #{time}"
@doc.at('#timestamp').inner_html = timestamp
File.open('new.html', 'w') {|f| f.write(@doc) }
else
puts 'you must download the current markup into source.html'
end
end
def run file
node = @doc.at("\##{class_for(file)}_code")
if node.nil?
puts "can't find pre with id = #{class_for(file)}_code"
else
node.add_next_sibling code_markup file
node.remove
puts "pre with id = #{class_for(file)}_code replaced successfully"
end
node = nil
node = @doc.at("\##{class_for(file)}_output")
if node.nil?
puts "can't find pre with id = #{class_for(file)}_output"
else
node.add_next_sibling output_markup file
node.remove
puts "pre with id = #{class_for(file)}_outputreplaced successfully"
end
end
def class_for file
file.split('/').last.split('.').first
end
def code_markup file
out = "<pre id=\"#{class_for(file)}_code\" data-timestamp=\"#{Time.new.inspect}\" class=\"brush: csharp;\">"
out += CGI::escapeHTML(File.read file).gsub('', "")
out += '</pre>'
end
def output_markup file
out = "<pre id=\"#{class_for(file)}_output\" data-timestamp=\"#{Time.new.inspect}\" style=\"font-size: 1.1em !important; color: #5ce632; background-color: #1b2426; padding: 10px;\">"
output = `nspecrunner/bin/debug/nspecrunner.exe samplespecs/bin/debug/samplespecs.dll #{class_for(file)}`.strip#.gsub("\ï\»\¿","")
output.each_line do |line|
cleanLine = line.rstrip
if cleanLine.length <= 94
out += CGI::escapeHTML(line.rstrip) + "\n"
else
out += CGI::escapeHTML(line.rstrip[0..94-line.length] + "...\n")
end
end
out += '</pre>'
end