public
Rubygem
Description: Apache Buildr
Homepage: http://incubator.apache.org/buildr
Clone URL: git://github.com/vic/buildr.git
assaf (author)
Thu May 01 15:00:53 -0700 2008
commit  5f79ec47a19cadd0254c5008e4cbf3bbb44d114d
tree    27d7ef16bc23f1391b569280a27b1accedc31ebb
parent  6c9f386b4d0d0e5d8d3c01874fc1ecd287b4651e
buildr / rakelib / changelog.rake
100644 58 lines (50 sloc) 2.355 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
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with this
# work for additional information regarding copyright ownership. The ASF
# licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
 
 
# Handling of CHANGELOG.
namespace 'changelog' do
 
  task 'check'=>'CHANGELOG' do
    print 'Checking that CHANGELOG indicates most recent version and today\'s date ... '
    expecting = "#{spec.version} (#{Time.now.strftime('%Y-%m-%d')})"
    header = File.readlines('CHANGELOG').first.chomp
    fail "Expecting CHANGELOG to start with #{expecting}, but found #{header} instead" unless expecting == header
    puts 'OK'
  end
 
  file 'staged/CHANGES'=>'CHANGELOG' do |task|
    # Read the changes for this release.
    print 'Looking for changes between this release and previous one ... '
    pattern = /(^(\d+\.\d+(?:\.\d+)?)\s+\(\d{4}-\d{2}-\d{2}\)\s*((:?^[^\n]+\n)*))/
    changes = File.read('CHANGELOG').scan(pattern).inject({}) { |hash, set| hash[set[1]] = set[2] ; hash }
    current = changes[spec.version.to_s]
    fail "No changeset found for version #{spec.version}" unless current
    File.open task.name, 'w' do |file|
      file.write "#{spec.version} (#{Time.now.strftime('%Y-%m-%d')})\n"
      file.write current
    end
    puts 'OK'
  end
 
  task 'wrapup'=>'CHANGELOG' do
    next_version = spec.version.to_s.split('.').map { |v| v.to_i }.
      zip([0, 0, 1]).map { |a| a.inject(0) { |t,i| t + i } }.join('.')
    print 'Adding new entry to CHANGELOG ... '
    modified = "#{next_version} (Pending)\n\n" + File.read('CHANGELOG')
    File.open 'CHANGELOG', 'w' do |file|
      file.write modified
    end
    puts 'Done'
  end
 
end
 
task 'stage:check'=>'changelog:check'
task 'stage:prepare'=>'staged/CHANGES'
task 'release:wrapup'=>'changelog:wrapup'