This repository has been archived by the owner on Aug 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
79 lines (62 loc) · 2.36 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
# frozen_string_literal: true
task :console do
exec "irb -r gwitch -I ./lib"
end
require "rake/testtask"
task default: :test
Rake::TestTask.new do |t|
t.libs = %w[lib test]
t.test_files = FileList["test/**/*_test.rb"]
t.warning = true
t.verbose = true
end
namespace :gwitch do
GEM_VERSION_FILE = File.expand_path('../lib/gwitch/version.rb', __FILE__)
GIT_TAG_URL = 'https://github.com/dounx/gwitch/releases/tag/'
def last_commit_date
`git log -1 --date=short --format=%cd`.chomp
end
def latest_tag
`git describe --tags --abbrev=0`.chomp
end
def changelog(git_start = latest_tag(), git_end = 'HEAD', format = '%s')
`git log --no-decorate --no-merges --pretty=format:#{format} #{git_start}..#{git_end}`
end
desc 'Write latest changes to CHANGELOG.md'
task :changelog, [:version] do |t, args|
# Filters-out commits containing some keywords and adds header
exceptions_regexp = Regexp.union(['README'])
title = "## [%s](%s%s) (%s)\n\n" % [args[:version], GIT_TAG_URL, args[:version], last_commit_date]
changes = changelog.each_line
.map { |line| (exceptions_regexp === line) ? nil : "* #{line.capitalize}" }
.unshift(title)
.append("\n\n")
.join
puts changes
puts "\n\e[31mDo you want to update the CHANGELOG.md with the text above? [y/N]\e[0m"
exit if STDIN.gets.chomp.downcase != 'y'
# Rewrite CHANGELOG.md
old_changes = File.readlines('CHANGELOG.md', 'r').join
File.open('CHANGELOG.md', 'w') { |file| file.write(changes, old_changes) }
puts 'CHANGELOG.md successfully updated'
end
desc 'Bump gem version'
task :semver, [:version] do |t, args|
File.open(GEM_VERSION_FILE, 'w') do |file|
file.write <<~SEMVER
module Gwitch
VERSION = "#{args[:version]}"
end
SEMVER
end
# This force to reload the file with the newest version.
# Hence, `gemspec.version` invoked by Bundler later on will be correct.
load GEM_VERSION_FILE
puts "Bumped gem version from #{latest_tag} to #{args[:version]}"
end
desc 'Release a new version of this gem'
task :release, [:version] => [:changelog, :semver] do |t, args|
`git add #{File.expand_path('../lib/gwitch/version.rb', __FILE__)} CHANGELOG.md`
`git commit -m "Bump to version #{args[:version]}"`
end
end