-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
64 lines (54 loc) · 1.73 KB
/
Rakefile
File metadata and controls
64 lines (54 loc) · 1.73 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
require 'rake'
require 'rake/testtask'
desc 'Default: run unit tests'
task default: :test
desc 'Run all tests'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end
desc 'Bump gem version'
task :bump_version, :version do |t, args|
current_version = nil
new_version = args.version
tag_version = "v#{new_version}"
puts "Fetching tags..."
`git fetch --tags`
raise StandardError, "Clean your git status before bumping gem version" unless `git status --porcelain`.empty?
raise StandardError, "Tag '#{tag_version}' already exists" unless `git tag -l #{tag_version}`.empty?
gemspec_path = 'capito.gemspec'
new_gemspec = File.open(gemspec_path) do |f|
content = f.read
current_version = content.match(/version\s*=\s*[\'|\"](.*)[\'|\"]/)[1]
content.sub current_version, new_version
end
IO.write gemspec_path, new_gemspec
changelog_path = 'CHANGELOG.md'
new_changelog = File.open(changelog_path) do |f|
content = f.read
content.match(/(\#{3}\s*\w+(\s+))/)
unreleased = $1
spaces = $2
date = Time.now.strftime('%B %-d, %Y')
released = "### Capito #{new_version} (#{date})"
content.sub unreleased, "#{unreleased}#{released}#{spaces}"
end
IO.write changelog_path, new_changelog
readme_path = 'README.md'
new_readme = File.open(readme_path) do |f|
content = f.read
content.gsub current_version, new_version
end
IO.write readme_path, new_readme
system 'git diff'
puts "Do you wants to commit this changes ? (Y/n)"
if STDIN.gets.chomp =~ /y/i
`git add .`
`git commit -m "Bump version #{tag_version}"`
`git tag #{tag_version} HEAD`
puts "Bump version finished"
else
puts "Bump version cancelled"
end
end