Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 81 lines (69 sloc) 2.083 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
require 'yard'
require 'rspec/core/rake_task'

desc "Generate YARD documentation"
YARD::Rake::YardocTask.new do |t|
  files = ['lib/**/*.rb', '-', 'CHANGELOG.md', 'LICENSE']
  t.files = files.reject { |f| f =~ /seed|example/ }
end

desc "Run an IRB session with gocardless pre-loaded"
task :console do
  exec "irb -I lib -r gocardless"
end

desc "Run the specs"
RSpec::Core::RakeTask.new(:spec) do |t|
  t.rspec_opts = %w[--color]
end


def generate_changelog(last_version, new_version)
  commits = `git log v#{last_version}.. --oneline`.split("\n")
  msgs = commits.map { |commit| commit.sub(/^[a-f0-9]+/, '-') }
  date = Time.now.strftime("%B %d, %Y")
  "## #{new_version} - #{date}\n\n#{msgs.join("\n")}\n\n\n"
end

def update_changelog(last_version, new_version)
  contents = File.read('CHANGELOG.md')
  if contents =~ /## #{new_version}/
    puts "CHANGELOG already contains v#{new_version}, skipping"
    return false
  end
  changelog = generate_changelog(last_version, new_version)
  File.open('CHANGELOG.md', 'w') { |f| f.write(changelog + contents) }
end

def update_version_file(new_version)
  path = "lib/#{Dir.glob('*.gemspec').first.split('.').first}/version.rb"
  contents = File.read(path)
  contents.sub!(/VERSION\s+=\s+["'][\d\.]+["']/, "VERSION = '#{new_version}'")
  File.open(path, 'w') { |f| f.write(contents) }
end

def bump_version(part)
  last_version = `git tag -l | tail -1`.strip.sub(/^v/, '')
  major, minor, patch = last_version.scan(/\d+/).map(&:to_i)

  case part
  when :major
    major += 1
    minor = patch = 0
  when :minor
    minor += 1
    patch = 0
  when :patch
    patch += 1
  end
  new_version = "#{major}.#{minor}.#{patch}"

  update_changelog(last_version, new_version)
  puts "Updated CHANGELOG"

  update_version_file(new_version)
  puts "Updated version.rb"
end

desc "Update the version, auto-generating the changelog"
namespace :version do
  namespace :bump do
    task :major do
      bump_version :major
    end
    task :minor do
      bump_version :minor
    end
    task :patch do
      bump_version :patch
    end
  end
end
Something went wrong with that request. Please try again.