generated from mattbrictson/tomo-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
95 lines (77 loc) · 2.58 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
require "bundler/gem_tasks"
require "rake/testtask"
require "rubocop/rake_task"
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
end
RuboCop::RakeTask.new
task default: %i[test rubocop]
task bump: %w[bump:bundler bump:ruby bump:year]
Rake::Task["release"].enhance do
puts "Don't forget to publish the release on GitHub!"
system "open https://github.com/mattbrictson/tomo-plugin-sidekiq/releases"
end
namespace :bump do
task :bundler do
version = Gem.latest_version_for("bundler").to_s
replace_in_file ".circleci/config.yml", /bundler -v (\S+)/ => version
replace_in_file ".travis.yml", /bundler -v (\S+)/ => version
replace_in_file "Gemfile.lock", /^BUNDLED WITH\n\s+([\d.]+)$/ => version
end
task :ruby do
lowest = RubyVersions.lowest_supported
lowest_minor = RubyVersions.lowest_supported_minor
latest = RubyVersions.latest
replace_in_file "tomo-plugin-sidekiq.gemspec", /ruby_version = .*">= (.*)"/ => lowest
replace_in_file ".rubocop.yml", /TargetRubyVersion: (.*)/ => lowest_minor
replace_in_file ".circleci/config.yml", %r{cimg/ruby:([\d.]+)} => latest
replace_in_file ".circleci/config.yml", /bundle-.*ruby([\d.]+)-/ => latest
travis = YAML.safe_load(open(".travis.yml"))
travis["rvm"] = RubyVersions.latest_supported_patches + ["ruby-head"]
IO.write(".travis.yml", YAML.dump(travis))
end
task :year do
replace_in_file "LICENSE.txt", /\(c\) (\d+)/ => Date.today.year.to_s
end
end
require "date"
require "open-uri"
require "yaml"
def replace_in_file(path, replacements)
contents = IO.read(path)
orig_contents = contents.dup
replacements.each do |regexp, text|
raise "Can't find #{regexp} in #{path}" unless regexp.match?(contents)
contents.gsub!(regexp) do |match|
match[regexp, 1] = text
match
end
end
IO.write(path, contents) if contents != orig_contents
end
module RubyVersions
class << self
def lowest_supported
"#{lowest_supported_minor}.0"
end
def lowest_supported_minor
latest_supported_patches.first[/\d+\.\d+/]
end
def latest
latest_supported_patches.last
end
def latest_supported_patches
patches = [versions[:stable], versions[:security_maintenance]].flatten
patches.map(&Gem::Version.method(:new)).sort.map(&:to_s)
end
private
def versions
@_versions ||= begin
yaml = URI.open("https://raw.githubusercontent.com/ruby/www.ruby-lang.org/master/_data/downloads.yml")
YAML.safe_load(yaml, symbolize_names: true)
end
end
end
end