release.rake
9.24 KB
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
namespace :noosfero do
def pendencies_on_authors
sh "git status | grep 'AUTHORS' > /dev/null" do |ok, res|
return {:ok => !ok, :res => res}
end
end
def pendencies_on_repo
sh "git status | grep 'nothing.*commit' > /dev/null" do |ok, res|
return {:ok => ok, :res => res}
end
end
def pendencies_on_public_errors
sh "git status | grep -e '500.html' -e '503.html' > /dev/null" do |ok, res|
return {:ok => !ok, :res => res}
end
end
def commit_changes(files, commit_message)
files = files.join(' ')
puts "\nThere are changes in the following files:"
sh "git diff #{files}"
if confirm('Do you want to commit these changes')
sh "git add #{files}"
sh "git commit -m '#{commit_message}'"
else
sh "git checkout #{files}"
abort 'There are changes to be commited. Reverting changes and exiting...'
end
end
desc 'checks if there are uncommitted changes in the repo'
task :check_repo do
if !pendencies_on_repo[:ok]
raise "******** There are uncommited changes in the repository, cannot continue"
end
end
def version
require_dependency 'noosfero'
Noosfero::VERSION
end
desc 'checks if there is already a tag for the current version'
task :check_tag do
sh "git tag | grep '^#{version}$' >/dev/null" do |ok, res|
if ok
raise "******** There is already a tag for version #{version}, cannot continue"
end
end
puts "Not found tag for version #{version}, we can go on."
end
desc 'checks the version of the Debian package'
task :check_debian_package do
debian_version = `dpkg-parsechangelog | grep Version: | cut -d ' ' -f 2`.strip
unless debian_version =~ /^#{version}/
puts "Version mismatch: Debian version = #{debian_version}, Noosfero upstream version = #{version}"
puts "Run `dch -v #{version}` to add a new changelog entry that upgrades the Debian version"
raise "Version mismatch between noosfero version and debian package version"
end
end
AUTHORS_HEADER = <<EOF
If you are not listed here, but should be, please write to the noosfero mailing
list: http://listas.softwarelivre.org/cgi-bin/mailman/listinfo/noosfero-dev
(this list requires subscription to post, but since you are an author of
noosfero, that's not a problem).
Developers
==========
EOF
AUTHORS_FOOTER = <<EOF
Ideas, specifications and incentive
===================================
Daniel Tygel <dtygel@fbes.org.br>
Guilherme Rocha <guilherme@gf7.com.br>
Raphael Rousseau <raph@r4f.org>
Théo Bondolfi <move@cooperation.net>
Vicente Aguiar <vicenteaguiar@colivre.coop.br>
Arts
===================================
Nara Oliveira <narananet@gmail.com>
EOF
desc 'updates the AUTHORS file'
task :authors do
begin
File.open("AUTHORS", 'w') do |output|
output.puts AUTHORS_HEADER
output.puts `git log --pretty=format:'%aN <%aE>' | sort | uniq`
output.puts AUTHORS_FOOTER
end
commit_changes(['AUTHORS'], 'Updating AUTHORS file') if !pendencies_on_authors[:ok]
rescue Exception => e
rm_f 'AUTHORS'
raise e
end
end
def ask(message, default = nil, default_message = nil, symbol = ':')
default_choice = default ? " [#{default_message || default}]#{symbol} " : "#{symbol} "
print message + default_choice
answer = STDIN.gets.chomp
answer.blank? && default.present? ? default : answer
end
def confirm(message, default=true)
default_message = default ? 'Y/n' : 'y/N'
default_value = default ? 'y' : 'n'
choice = nil
while choice.nil?
answer = ask(message, default_value, default_message, '?')
if answer.blank?
choice = default
elsif ['y', 'yes'].include?(answer.downcase)
choice = true
elsif ['n', 'no'].include?(answer.downcase)
choice = false
end
end
choice
end
desc 'sets the new version on apropriate files'
task :set_version, :release_kind do |t, args|
next if File.exist?("tmp/pending-release")
release_kind = args[:release_kind] || 'stable'
if release_kind == 'test'
version_question = "Release candidate of which version"
distribution = 'squeeze-test'
else
version_question = "Version that is being released"
distribution = 'unstable'
end
version_name = new_version = ask(version_question)
if release_kind == 'test'
rc_version = ask('RC version', Time.now.strftime('%Y%m%d%H%M%S'))
version_name += "~rc#{rc_version}"
end
release_message = ask("Release message")
sh 'git checkout debian/changelog lib/noosfero.rb'
sh "sed -i \"s/VERSION = '[^']*'/VERSION = '#{version_name}'/\" lib/noosfero.rb"
sh "dch --newversion #{version_name} --distribution #{distribution} --force-distribution '#{release_message}'"
sh 'git diff debian/changelog lib/noosfero.rb'
if confirm("Commit version bump to #{version_name} on #{distribution} distribution")
sh 'git add debian/changelog lib/noosfero.rb'
sh "git commit -m 'Bumping version #{version_name}'"
sh "touch tmp/pending-release"
else
sh 'git checkout debian/changelog lib/noosfero.rb'
abort 'Version update not confirmed. Reverting changes and exiting...'
end
end
desc "uploads the packages to the repository"
task :upload_packages, :release_kind do |t, args|
release_kind = args[:release_kind] || 'stable'
sh "dput --unchecked #{release_kind} #{Dir['pkg/*.changes'].first}"
end
desc 'sets the new version on apropriate files'
task :set_version, :release_kind do |t, args|
next if File.exist?("tmp/pending-release")
release_kind = args[:release_kind] || 'stable'
if release_kind == 'test'
version_question = "Release candidate of which version: "
distribution = 'squeeze-test'
else
version_question = "Version that is being released: "
distribution = 'unstable'
end
version_name = new_version = ask(version_question)
if release_kind == 'test'
timestamp = Time.now.strftime('%Y%m%d%H%M%S')
version_name += "~rc#{timestamp}"
end
release_message = ask("Release message")
sh 'git checkout debian/changelog lib/noosfero.rb'
sh "sed -i \"s/VERSION = '[^']*'/VERSION = '#{version_name}'/\" lib/noosfero.rb"
sh "dch --newversion #{version_name} --distribution #{distribution} --force-distribution '#{release_message}'"
sh 'git diff debian/changelog lib/noosfero.rb'
if confirm("Commit version bump to #{version_name} on #{distribution} distribution")
sh 'git add debian/changelog lib/noosfero.rb'
sh "git commit -m 'Bumping version #{version_name}'"
sh "touch tmp/pending-release"
else
sh 'git checkout debian/changelog lib/noosfero.rb'
abort 'Version update not confirmed. Reverting changes and exiting...'
end
end
desc "uploads the packages to the repository"
task :upload_packages, :release_kind do |t, args|
release_kind = args[:release_kind] || 'stable'
sh "dput --unchecked #{release_kind} #{Dir['pkg/*.changes'].first}"
end
desc 'prepares a release tarball'
task :release, :release_kind do |t, args|
release_kind = args[:release_kind] || 'stable'
puts "==> Updating authors..."
Rake::Task['noosfero:authors'].invoke
Rake::Task['noosfero:set_version'].invoke(release_kind)
puts "==> Checking tags..."
Rake::Task['noosfero:check_tag'].invoke
puts "==> Checking debian package version..."
Rake::Task['noosfero:check_debian_package'].invoke
puts "==> Checking translations..."
Rake::Task['noosfero:error-pages:translate'].invoke
if !pendencies_on_public_errors[:ok]
commit_changes(['public/500.html', 'public/503.html'], 'Updating public error pages')
end
puts "==> Checking repository..."
Rake::Task['noosfero:check_repo'].invoke
puts "==> Preparing debian packages..."
Rake::Task['noosfero:debian_packages'].invoke
if confirm('Do you want to upload the packages')
puts "==> Uploading debian packages..."
Rake::Task['noosfero:upload_packages'].invoke(release_kind)
end
sh "git tag #{version.gsub('~','-')}"
push_tags = confirm('Push new version tag')
if push_tags
repository = ask('Repository name', 'origin')
puts "==> Uploading tags..."
sh "git push #{repository} #{version.gsub('~','-')}"
end
sh "rm tmp/pending-release" if Dir["tmp/pending-release"].first.present?
puts "I: please upload the tarball and Debian packages to the website!"
puts "I: please push the tag for version #{version} that was just created!" if !push_tags
puts "I: notify the community about this sparkling new version!"
end
desc 'Build Debian packages'
task :debian_packages => :package do
target = "pkg/noosfero-#{Noosfero::VERSION}"
# base pre-config
mkdir "#{target}/tmp"
ln_s '../../../vendor/rails', "#{target}/vendor/rails"
cp "#{target}/config/database.yml.sqlite3", "#{target}/config/database.yml"
sh "cd #{target} && dpkg-buildpackage -us -uc -b"
end
desc "Build Debian packages (shorcut)"
task :deb => :debian_packages
desc 'Test Debian package'
task 'debian:test' => :debian_packages do
Dir.chdir 'pkg' do
rm_rf "noosfero-#{Noosfero::VERSION}"
sh 'apt-ftparchive packages . > Packages'
sh 'apt-ftparchive release . > Release'
end
end
end