-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile.rb
217 lines (196 loc) · 6.7 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
169
170
171
172
173
174
175
176
177
178
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
206
207
208
209
210
211
212
213
214
215
# Creative Commons BY-SA : Regis d'Aubarede <regis.aubarede@gmail.com>
# LGPL
#################################################################
# Rakefile : git commit/add ; git push, test/spec & gem push
#################################################################
#
# Usage:
# > rake commit # commit in local directory and push to repository
# > rake gem # make gem,and test it, and push it to gemcutter
# > rake travis # travis CI run commands
#
#################################################################
# Requirements :
# version : X.Y.Z
# X : to be hand-modified
# Y : incremented at each 'rake gem'
# Z : increment on each file 'rake commit'
# auto commit all changed file, sking comment for each
# log all commment in CHANGELOG?Txt file
# increment VERSION content with version numbering rule
# so CHANGELOG.txt is updated with each comment/version change
# so VERSION is updated in each commit (Z part) and each gem build (Y part)
#
# commit:
# Use 'git status' output for each new/modified file,
# with asking some comment
# (no add/commit of comment is empty)
#
# gem:
# execute rspec if specs exists,
# make a gem, install it, execute samples/test.rb in it, if exist
# ask to operator if execution is ok and :
# increment version
# update change log/version
# do a 'gem push' and a 'gem yanked'
# make a coffe
#
#################################################################
FIGNORES=%w{VERSION CHANGELOG.txt .gitignore}
NAME= Dir.pwd.gsub(File.dirname(Dir.pwd)+'/',"")
Rake.application.options.trace = false
def push_changelog(line)
b=File.read('CHANGELOG.txt').split(/\r?\n/)
b.unshift(line)
File.open('CHANGELOG.txt','w') {|f| f.write(b[0..500].join("\n")) }
end
def changelog_push_currrent_versions()
version=File.read('VERSION').strip
b=File.read('CHANGELOG.txt').split(/\r?\n/)
b.unshift(version)
File.open('CHANGELOG.txt','w') {|f| f.write(b.join("\n")) }
yield rescue p $!.to_s
b.shift
File.open('CHANGELOG.txt','w') {|f| f.write(b.join("\n")) }
end
def change_version()
a=File.read('VERSION').strip.split('.')[0..2]
yield(a)
version=a.join('.')
File.open('VERSION','w') {|f| f.write(version) }
version
end
def verification_file(fn)
return unless File.extname(fn)==".rb"
content=File.read(fn)[0..600]
unless content =~ /LGPL/
puts "\nFile #{fn} seem not contain licenses data LGPL\n"
exit(0)
end
end
#############################################################
# Comment each file add/modified ##
#############################################################
desc "commit file changed and created"
task :commit_status do
`git status -s`.split(/\r?\n/).each do |line|
words=line.split(/\s+/)
case line
when /^ M /
filename=words[2]
next if FIGNORES.include?(filename)
system("git","diff",filename)
print("Comment for change in #{filename} : ")
comment=$stdin.gets
if comment && comment.chomp.size>0
comment.chomp!
(puts "Abort!";exit!) if comment=~/^a(b(o(r(t)?)?)?)?$/
verification_file(filename)
sh "git commit #{filename} -m \"#{comment.strip}\"" rescue 1
push_changelog(" #{File.basename(filename)} : #{comment}")
$changed=true
end
when /^\?\?/
filename=words[1]
print("Comment for new file in #{filename} : ")
comment=$stdin.gets.chomp
(puts "Abort!";exit!) if comment=~/^a(b(o(r(t)?)?)?)?$/
if comment =~ /^y|o/i
verification_file(filename)
sh "git add #{filename}"
sh "git commit #{filename} -m \"creation\"" rescue 1
$changed=true
end
end
end
end
#############################################################
# before commit
#############################################################
desc "job before commit"
task :pre_commit do
sh "cls" if RUBY_PLATFORM =~ /(win32)|(mingw)/i
puts <<EEND2
--------------------------------------------------------------------
Commmit and push #{NAME}
--------------------------------------------------------------------
EEND2
#sh "giti"
$changed=false
end
#############################################################
# after commit
#############################################################
desc "job after local commit done: push to git repo"
task :post_commit do
if $changed
$version=change_version { |a| a[-1]=(a.last.to_i+1) }
sh "git commit VERSION -m update"
changelog_push_currrent_versions {
sh "git commit CHANGELOG.txt -m update"
sh "git push"
puts "\n\nNew version is #{$version}\n"
}
else
puts "no change!"
end
end
#############################################################
# commit
#############################################################
desc "commit local and then distant repo"
task :commit => [:pre_commit,"commit_status",:post_commit]
#############################################################
# gem build & push
#############################################################
desc "make a gem and push it to gemcutter"
task :gem do
$version=change_version { |a|
a[-2]=(a[-2].to_i+1)
a[-1]=0
}
puts "New version ==>> #{$version}"
l=FileList['*.gem']
l.each { |fn| rm fn }
gem_name="#{NAME}-#{$version}.gem"
push_changelog "#{$version} : #{Time.now}"
sh "gem build #{NAME}.gemspec"
Rake::Task["test"].execute if File.exists?("samples/test.rb")
sh "gem push #{gem_name}"
l.each { |fn|
ov=fn.split('-')[1].gsub('.gem',"")
sh "gem yank -v #{ov} #{NAME}"
}
end
#############################################################
# execute tests
#############################################################
desc "test the current version of the framework by installing the gem and run a test programme"
task :test do
if File.exists?("spec/test_all.rb")
system("rspec spec/test_all.rb")
end
if File.exists?("samples/test.rb")
cd ".."
mkdir "#{NAME}Test" unless File.exists?("#{NAME}Test")
nname="#{NAME}Test/test.rb"
content=File.read("#{NAME}/samples/test.rb").gsub(/require_relative/," require").gsub('../lib/','')
File.open(nname,"w") { |f| f.write(content) }
sh "gem install #{FileList["#{NAME}/#{NAME}*.gem"][-1]}"
ruby nname rescue nil
cd NAME
print "\n\nOk for diffusion ? "
rep=$stdin.gets
raise("aborted!") unless rep && rep =~ /^y|o|d/
end
end
#############################################################
# travis command
#############################################################
task :travis do
puts "Starting travis test..."
cmd="bundle exec rspec spec/test_all.rb"
system("export DISPLAY=:99.0 && #{cmd}")
#system(cmd)
raise "rspec failed!" unless $?.exitstatus == 0
end