This repository has been archived by the owner on Jun 16, 2020. It is now read-only.
forked from bruce/bitmask-attribute
-
Notifications
You must be signed in to change notification settings - Fork 71
/
Rakefile
157 lines (132 loc) · 3.83 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
# encoding: UTF-8
begin
require 'bundler/setup'
require 'appraisal'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
Bundler::GemHelper.install_tasks
require 'rake/testtask'
desc 'Default: run unit tests.'
task :default => :test
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end
#############################################################################
#
# Helper functions
#
#############################################################################
def name
@name ||= Dir['*.gemspec'].first.split('.').first
end
def version
line = File.read("lib/#{name}/version.rb")[/^\s*VERSION\s*=\s*.*/]
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
end
def gem_file
"#{name}-#{version}.gem"
end
require 'rdoc/task'
require 'sdoc'
Rake::RDocTask.new do |rdoc|
rdoc.rdoc_dir = 'doc'
rdoc.title = "#{name} #{version}"
rdoc.options << '-f' << 'sdoc'
rdoc.options << '-a'
rdoc.options << '--markup' << 'tomdoc'
rdoc.options << '-m' << 'README.rdoc'
rdoc.rdoc_files.include('CHANGELOG*')
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
#############################################################################
#
# Changeling
#
#############################################################################
namespace :changeling do
# desc "Bumps the version by a minor or patch version, depending on what was passed in."
task :bump, :part do |t, args|
unless `git branch` =~ /^\* master$/
puts "You must be on the master branch to bump the version!"
exit!
end
# Thanks, Jeweler!
if BitmaskAttributes::VERSION =~ /^(\d+)\.(\d+)\.(\d+)(?:\.(.*?))?$/
major = $1.to_i
minor = $2.to_i
patch = $3.to_i
if $4 =~ /([a-z]+)(\d+)?/i
pre_name = $1
pre_version = ($2 || 0).to_i
end
else
abort
end
case args[:part]
when /minor/
minor += 1
patch = 0
when /patch/
patch += 1
when /pre/
pre_version += 1
pre = "#{pre_name}#{pre_version}"
else
abort
end
version = [major, minor, patch, pre].compact.join('.')
File.open(File.join("lib", name, "version.rb"), "w") do |f|
f.write <<EOF
module BitmaskAttributes
VERSION = "#{version}".freeze
end
EOF
end
end
# desc "Writes out the new CHANGELOG and prepares the release"
task :change do
unless `git branch` =~ /^\* master$/
puts "You must be on the master branch to update changelog!"
exit!
end
load "lib/#{name}/version.rb"
file = "CHANGELOG.rdoc"
old = File.read(file)
message = "Bumping to version #{version}"
File.open(file, "w") do |f|
f.write <<EOF
=== Version #{version} - #{Time.now}
#{`git log $(git tag | tail -1)..HEAD | git shortlog`.gsub /\s{6}/, "\n*"}
#{old}
EOF
end
Rake::Task['build'].invoke
exec ["#{ENV["EDITOR"]} #{file}",
"git commit -aqm '#{message}'",
"git tag -a -m '#{message}' v#{version}",
"git push origin master",
"git push origin $(git tag | tail -1)",
"gem push pkg/#{name}-#{version}.gem",
"echo '\n\033[32mReleased v#{version} /' `git show-ref -s refs/heads/master` '.\033[0m\n'"].join(' && ')
end
desc "Bump by a minor version (1.2.3 => 1.3.0)"
task :minor do |t|
Rake::Task['changeling:bump'].invoke(t.name)
Rake::Task['changeling:change'].invoke
end
desc "Bump by a patch version, (1.2.3 => 1.2.4)"
task :patch do |t|
Rake::Task['changeling:bump'].invoke(t.name)
Rake::Task['changeling:change'].invoke
end
desc "Bump by a pre-release version, (1.0.0.pre1 => 1.0.0.pre2)"
task :pre do |t|
Rake::Task['changeling:bump'].invoke(t.name)
Rake::Task['changeling:change'].invoke
end
end