diff --git a/Rakefile b/Rakefile index f32f2a8..caacbf2 100644 --- a/Rakefile +++ b/Rakefile @@ -1,48 +1,12 @@ require "bundler/gem_tasks" require "rake/testtask" -helper = Bundler::GemHelper.instance - Rake::TestTask.new(:test) do |t| t.test_files = FileList["test/**/test_*.rb"] end task :default => :test -task "build" => "date_epoch" -task "build" => "changelogs" - -task "date_epoch" do - ENV["SOURCE_DATE_EPOCH"] = IO.popen(%W[git -C #{__dir__} log -1 --format=%ct], &:read).chomp -end - -def helper.update_gemspec - path = "#{__dir__}/#{gemspec.name}.gemspec" - File.open(path, "r+b") do |f| - if (d = f.read).sub!(/^(version\s*=\s*)".*"/) {$1 + gemspec.version.to_s.dump} - f.rewind - f.truncate(0) - f.print(d) - end - end -end - -def helper.commit_bump - sh(%W[git -C #{__dir__} commit -m bump\ up\ to\ #{gemspec.version} - #{gemspec.name}.gemspec]) -end - -def helper.version=(v) - gemspec.version = v - update_gemspec - commit_bump -end -major, minor, teeny = helper.gemspec.version.segments - -task "bump:teeny" do - helper.version = Gem::Version.new("#{major}.#{minor}.#{teeny+1}") -end - task "bump:minor" do raise "can't bump up minor" end @@ -50,41 +14,3 @@ end task "bump:major" do raise "can't bump up major" end - -task "bump" => "bump:teeny" - -task "tag" do - helper.__send__(:tag_version) -end - -def changelog(output, ver = nil, prev = nil) - ver &&= Gem::Version.new(ver) - range = [[prev], [ver, "HEAD"]].map {|ver, branch| ver ? "v#{ver.to_s}" : branch}.compact.join("..") - IO.popen(%W[git log --format=fuller --topo-order --no-merges #{range}]) do |log| - line = log.gets - FileUtils.mkpath(File.dirname(output)) - File.open(output, "wb") do |f| - f.print "-*- coding: utf-8 -*-\n\n", line - log.each_line do |line| - line.sub!(/^(?!:)(?:Author|Commit)?(?:Date)?: /, ' \&') - line.sub!(/ +$/, '') - f.print(line) - end - end - end -end - -tags = IO.popen(%w[git tag -l v0.*]).grep(/v(.*)/) {$1} -tags.sort_by! {|tag| tag.scan(/\d+/).map(&:to_i)} -tags.inject(nil) do |prev, tag| - task("logs/ChangeLog-#{tag}") {|t| changelog(t.name, tag, prev)} - tag -end - -desc "Make ChangeLog" -task "ChangeLog", [:ver, :prev] do |t, ver: nil, prev: tags.last| - changelog(t.name, ver, prev) -end -changelogs = ["ChangeLog", *tags.map {|tag| "logs/ChangeLog-#{tag}"}] -task "changelogs" => changelogs -CLOBBER.concat(changelogs) << "logs" diff --git a/rakelib/changelogs.rake b/rakelib/changelogs.rake new file mode 100644 index 0000000..df72f9d --- /dev/null +++ b/rakelib/changelogs.rake @@ -0,0 +1,34 @@ +task "build" => "changelogs" + +changelog = proc do |output, ver = nil, prev = nil| + ver &&= Gem::Version.new(ver) + range = [[prev], [ver, "HEAD"]].map {|ver, branch| ver ? "v#{ver.to_s}" : branch}.compact.join("..") + IO.popen(%W[git log --format=fuller --topo-order --no-merges #{range}]) do |log| + line = log.gets + FileUtils.mkpath(File.dirname(output)) + File.open(output, "wb") do |f| + f.print "-*- coding: utf-8 -*-\n\n", line + log.each_line do |line| + line.sub!(/^(?!:)(?:Author|Commit)?(?:Date)?: /, ' \&') + line.sub!(/ +$/, '') + f.print(line) + end + end + end +end + +tags = IO.popen(%w[git tag -l v[0-9]*]).grep(/v(.*)/) {$1} +tags.sort_by! {|tag| tag.scan(/\d+/).map(&:to_i)} +tags.inject(nil) do |prev, tag| + task("logs/ChangeLog-#{tag}") {|t| changelog[t.name, tag, prev]} + tag +end + +desc "Make ChangeLog" +task "ChangeLog", [:ver, :prev] do |t, ver: nil, prev: tags.last| + changelog[t.name, ver, prev] +end + +changelogs = ["ChangeLog", *tags.map {|tag| "logs/ChangeLog-#{tag}"}] +task "changelogs" => changelogs +CLOBBER.concat(changelogs) << "logs" diff --git a/rakelib/epoch.rake b/rakelib/epoch.rake new file mode 100644 index 0000000..80f27c9 --- /dev/null +++ b/rakelib/epoch.rake @@ -0,0 +1,5 @@ +task "build" => "date_epoch" + +task "date_epoch" do + ENV["SOURCE_DATE_EPOCH"] = IO.popen(%W[git -C #{__dir__} log -1 --format=%ct], &:read).chomp +end diff --git a/rakelib/version.rake b/rakelib/version.rake new file mode 100644 index 0000000..c56ea56 --- /dev/null +++ b/rakelib/version.rake @@ -0,0 +1,44 @@ +class << (helper = Bundler::GemHelper.instance) + def update_gemspec + path = gemspec.loaded_from + File.open(path, "r+b") do |f| + d = f.read + if d.sub!(/^(_VERSION\s*=\s*)".*"/) {$1 + gemspec.version.to_s.dump} + f.rewind + f.truncate(0) + f.print(d) + end + end + end + + def commit_bump + sh(%W[git -C #{__dir__} commit -m bump\ up\ to\ #{gemspec.version} + #{gemspec.loaded_from}]) + end + + def version=(v) + gemspec.version = v + update_gemspec + commit_bump + end +end + +major, minor, teeny = helper.gemspec.version.segments + +task "bump:teeny" do + helper.version = Gem::Version.new("#{major}.#{minor}.#{teeny+1}") +end + +task "bump:minor" do + helper.version = Gem::Version.new("#{major}.#{minor+1}.0") +end + +task "bump:major" do + helper.version = Gem::Version.new("#{major+1}.0.0") +end + +task "bump" => "bump:teeny" + +task "tag" do + helper.__send__(:tag_version) +end diff --git a/ruby2_keywords.gemspec b/ruby2_keywords.gemspec index cfe7811..e2cd397 100644 --- a/ruby2_keywords.gemspec +++ b/ruby2_keywords.gemspec @@ -1,9 +1,9 @@ -version = "0.0.5" -abort "Version must not reach 1" if version[/\d+/].to_i >= 1 +_VERSION = "0.0.5" +abort "Version must not reach 1" if _VERSION[/\d+/].to_i >= 1 Gem::Specification.new do |s| s.name = "ruby2_keywords" - s.version = version + s.version = _VERSION s.summary = "Shim library for Module#ruby2_keywords" s.homepage = "https://github.com/ruby/ruby2_keywords" s.licenses = ["Ruby", "BSD-2-Clause"]