generated from mattbrictson/gem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
113 lines (87 loc) · 3.09 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
require "bundler/gem_tasks"
require "rake/testtask"
require "rubocop/rake_task"
require "rspec/core/rake_task"
RuboCop::RakeTask.new
RSpec::Core::RakeTask.new(:test)
task default: %i[test rubocop]
# == "rake release" enhancements ==============================================
Rake::Task["release"].enhance do
puts "Don't forget to publish the release on GitHub!"
system "open https://github.com/uvera/trackstamps-reborn/releases"
end
task :disable_overcommit do
ENV["OVERCOMMIT_DISABLE"] = "1"
end
Rake::Task[:build].enhance [:disable_overcommit]
task :verify_gemspec_files do
git_files = `git ls-files -z`.split("\x0")
gemspec_files = Gem::Specification.load("trackstamps-reborn.gemspec").files.sort
ignored_by_git = gemspec_files - git_files
next if ignored_by_git.empty?
raise <<~ERROR
The `spec.files` specified in trackstamps-reborn.gemspec include the following files
that are being ignored by git. Did you forget to add them to the repo? If
not, you may need to delete these files or modify the gemspec to ensure
that they are not included in the gem by mistake:
#{ignored_by_git.join("\n").gsub(/^/, ' ')}
ERROR
end
Rake::Task[:build].enhance [:verify_gemspec_files]
# == "rake bump" tasks ========================================================
task bump: %w[bump:bundler bump:ruby bump:year]
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 "Gemfile.lock", /^BUNDLED WITH\n\s+(\d\S+)$/ => version
end
task :ruby do
lowest = RubyVersions.lowest
latest = RubyVersions.latest
all_supported = RubyVersions.all_supported
replace_in_file "trackstamps-reborn.gemspec", /ruby_version = .*">= (.*)"/ => lowest
replace_in_file ".rubocop.yml", /TargetRubyVersion: (.*)/ => lowest
replace_in_file ".circleci/config.yml", /default: "([\d.]+)"/ => latest
replace_in_file ".circleci/config.yml", /version: (\[.+\])/ => all_supported.inspect
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 = File.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
File.write(path, contents) if contents != orig_contents
end
module RubyVersions
class << self
def lowest
all_supported.first
end
def latest
all_supported.last
end
def all_supported
patches = versions.values_at(:stable, :security_maintenance, :eol).compact.flatten
patches.map { |p| Gem::Version.new(p[/\d+\.\d+/]) }.sort.map(&:to_s)
end
private
def versions
@_versions ||= begin
yaml = URI.open("https://raw.githubusercontent.com/ruby/www.ruby-lang.org/HEAD/_data/downloads.yml")
YAML.safe_load(yaml, symbolize_names: true)
end
end
end
end