-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
154 lines (130 loc) · 3.65 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
#
# Copyright 2013-17 the original author or authors
#
# Licensed 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.
#
require 'bundler/setup'
require 'date'
require 'rake/testtask'
require 'rubygems'
require 'rubygems/package_task'
require File.dirname(__FILE__) + '/lib/debut'
#############################################################################
#
# Helper functions
#
#############################################################################
def name
@name ||= Dir['*.gemspec'].first.split('.').first
end
def version
LiveTribe::Debut::VERSION
end
def date
Date.today.to_s
end
def rubyforge_project
name
end
def gemspec_file
"#{name}.gemspec"
end
def gem_file
"#{name}-#{version}.gem"
end
def replace_header(head, header_name)
head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
end
#############################################################################
#
# Standard tasks
#
#############################################################################
GEM_NAME = "#{name}"
task :default => :test
Rake::TestTask.new do |t|
t.libs.push "lib"
t.test_files = FileList['tests/*_tests.rb']
t.verbose = true
end
#############################################################################
#
# Packaging tasks
#
#############################################################################
task :release => %w(release:prepare release:publish)
namespace :release do
task :preflight do
unless `git branch` =~ /^\* master$/
puts 'You must be on the master branch to release!'
exit!
end
if `git tag` =~ /^\* #{version}$/
puts "Tag #{version} already exists!"
exit!
end
end
task :prepare => :preflight do
Rake::Task[:build].invoke
sh "gem install pkg/#{name}-#{version}.gem"
Rake::Task[:git_mark_release].invoke
end
task :publish do
Rake::Task[:git_push_release].invoke
Rake::Task[:gem_push].invoke
end
end
task :git_mark_release do
sh "git commit --allow-empty -a -m 'Release #{version}'"
sh "git tag #{version}"
end
task :git_push_release do
sh 'git push origin master'
sh "git push origin #{version}"
end
task :gem_push do
sh "gem push pkg/#{name}-#{version}.gem"
end
desc "Build debut-#{version}.gem"
task :build => :gemspec do
sh 'mkdir -p pkg'
sh "gem build #{gemspec_file}"
sh "mv #{gem_file} pkg"
end
task :gem => :build
desc "Updates the gemspec and runs 'validate'"
task :gemspec => :validate do
# read spec file and split out manifest section
spec = File.read(gemspec_file)
# replace name version and date
replace_header(spec, :name)
replace_header(spec, :version)
replace_header(spec, :date)
#comment this out if your rubyforge_project has a different name
replace_header(spec, :rubyforge_project)
File.open(gemspec_file, 'w') { |io| io.write(spec) }
puts "Updated #{gemspec_file}"
end
desc 'Run before pushing out the code'
task :validate do
libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
unless libfiles.empty?
puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
exit!
end
unless Dir['VERSION*'].empty?
puts 'A `VERSION` file at root level violates Gem best practices.'
exit!
end
end