forked from backup/backup
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Rakefile
82 lines (67 loc) · 1.84 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
require "rubocop/rake_task"
RuboCop::RakeTask.new
desc "Open a pry console in the Backup context"
task :console do
require "pry"
require "backup"
ARGV.clear
Pry.start || exit
end
def version_file
File.join(File.expand_path("lib/backup/version.rb"))
end
def current_version
Backup.send(:remove_const, :VERSION)
load version_file
Backup::VERSION
end
# Validates version numbers
#
# Valid version number format:
# - 10.0.0
# - 10.0.1.alpha
# - 10.0.1.alpha.1
# - 10.0.1.beta
# - 10.0.1.beta.1
# - 10.0.1.rc
# - 10.0.1.rc.1
def valid_version?(version)
version =~ /\d+\.\d+\.\d+(\.(alpha|beta|rc)(\.\d+)?)?/
end
def current_branch
`git rev-parse --abbrev-ref HEAD`.chomp
end
desc "Release new Backup gem version. Use this to release a new version."
task :release do
puts "Current version: #{current_version}"
print "Enter new version: "
new_version = $stdin.gets.chomp
unless valid_version?(new_version)
abort "ERROR: Invalid version number: #{new_version.inspect}"
end
puts "Creating new version: #{new_version}"
lines = File.readlines(version_file)
File.open(version_file, "w+") do |file|
lines.each do |line|
if line =~ /VERSION =/
file.puts %( VERSION = "#{new_version}")
else
file.write line
end
end
end
# Check if file saved correctly
unless current_version == new_version
abort "ERROR: Versions don't match!\n"\
"Current version:#{current_version}\n"\
"New version: #{new_version}"
end
puts `gem build backup.gemspec`
puts "Pushing to repository.."
puts `git commit -m "Release v#{new_version} [ci skip]" #{version_file}`
puts `git tag #{new_version}`
puts `git push origin #{new_version} #{current_branch}`
puts "Publishing Backup version #{new_version}"
puts `gem push backup-#{new_version}.gem`
puts "Backup version #{new_version} released!"
end