-
Notifications
You must be signed in to change notification settings - Fork 92
/
Rakefile
90 lines (75 loc) · 2.15 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
require "rspec/core/rake_task"
desc "Prepare MongoDB connection"
task :mongo_prepare do
# Wait for mongod to start on Travis.
# From the Mongo Ruby Driver gem.
if ENV["TRAVIS"]
require "mongo"
client = Mongo::Client.new(["127.0.0.1:27017"])
begin
puts "Waiting for MongoDB..."
client.command("ismaster" => 1)
rescue Mongo::Error::NoServerAvailable
sleep 2
# 1 Retry
puts "Waiting for MongoDB..."
client.cluster.scan!
client.command(Mongo::Error::NoServerAvailable)
end
end
end
desc "Run the mongo_session_store gem test suite."
RSpec::Core::RakeTask.new :test => :mongo_prepare
desc "Release a new version of the mongo_session_store gem"
task :release do
GEMSPEC_NAME = "mongo_session_store"
GEM_NAME = "mongo_session_store"
VERSION_FILE = "lib/mongo_session_store/version.rb"
def reload_version
if defined?(MongoSessionStore::VERSION)
MongoSessionStore.send(:remove_const, :VERSION)
end
load File.expand_path(VERSION_FILE)
end
raise "$EDITOR should be set" unless ENV["EDITOR"]
def build_and_push_gem
puts "# Building gem"
system "gem build #{GEMSPEC_NAME}.gemspec"
puts "# Publishing Gem"
system "gem push #{GEM_NAME}-#{gem_version}.gem"
end
def update_repo
puts `git commit -am "Bump to #{version} [ci skip]"`
begin
puts `git tag #{version}`
puts `git push origin #{version}`
puts `git push origin master`
rescue
raise %(Tag: "#{version}" already exists)
end
end
def changes
git_status_to_array(`git status -s -u`)
end
def gem_version
MongoSessionStore::VERSION
end
def version
@version ||= "v" << gem_version
end
def git_status_to_array(changes)
changes.split("\n").map { |change| change.gsub(/^.. /, "") }
end
raise "Branch should hold no uncommitted file change)" unless changes.empty?
reload_version
system("$EDITOR #{VERSION_FILE}")
if changes.include?(VERSION_FILE)
reload_version
build_and_push_gem
update_repo
else
raise "Actually change the version in: #{VERSION_FILE}"
end
end
desc "Default task for Rake. Runs test suite."
task :default => :test