Skip to content

Commit

Permalink
Added rakelib
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Mar 5, 2021
1 parent ebb9245 commit e7a0999
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
*.bundle
*.dll
*.so
ChangeLog
logs/
4 changes: 3 additions & 1 deletion io-wait.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
_VERSION = "0.1.0"

Gem::Specification.new do |spec|
spec.name = "io-wait"
spec.version = "0.1.0"
spec.version = _VERSION
spec.authors = ["Nobu Nakada"]
spec.email = ["nobu@ruby-lang.org"]

Expand Down
34 changes: 34 additions & 0 deletions rakelib/changelogs.rake
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 5 additions & 0 deletions rakelib/epoch.rake
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions rakelib/version.rake
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e7a0999

Please sign in to comment.