Merge pull request #556 from Retrospring/winver.exe

add rake task for easier version bumping
This commit is contained in:
Georg Gadinger 2022-07-23 13:11:17 +02:00 committed by GitHub
commit 737ba177ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 24 deletions

49
lib/tasks/version.rake Normal file
View File

@ -0,0 +1,49 @@
# frozen_string_literal: true
namespace :version do
desc "Bump the version"
task bump: :environment do
puts "Current version: #{Retrospring::Version}"
current_ymd = %i[year month day].map { Retrospring::Version.public_send(_1) }
now = Time.now.utc
today_ymd = %i[year month day].map { now.public_send(_1) }
version_path = Rails.root.join("lib/version.rb")
version_contents = File.read(version_path)
patch_contents = lambda do |key, val|
version_contents.sub!(/def #{key} = .+/) { "def #{key} = #{val}" }
end
if current_ymd == today_ymd
# bump the patch version
patch_contents[:patch, Retrospring::Version.patch + 1]
else
# set year/month/day to today, and reset patch to 0
%i[year month day].each { patch_contents[_1, now.public_send(_1)] }
patch_contents[:patch, 0]
end
# write the file
File.write(version_path, version_contents)
# reload the version file
load version_path
puts "New version: #{Retrospring::Version}"
end
desc "Commit and tag a new release"
task commit: :environment do
version_path = Rails.root.join("lib/version.rb")
puts "Committing version"
sh %(git commit -m 'Bump version to #{Retrospring::Version}' -- #{version_path.to_s.inspect})
puts "Tagging new release"
sh %(git tag -a -m 'Bump version to #{Retrospring::Version}' #{Retrospring::Version})
end
desc "Update the version (bump + commit)"
task update: %i[bump commit]
end

View File

@ -13,36 +13,20 @@ module Retrospring
module Version module Version
module_function module_function
def year def year = 2022
2022
end
def month def month = 7
7
end
def day def day = 23
23
end
def patch def patch = 0
0
end
def suffix def suffix = ""
""
end
def minor def minor = [month.to_s.rjust(2, "0"), day.to_s.rjust(2, "0")].join
[month.to_s.rjust(2, "0"), day.to_s.rjust(2, "0")].join
end
def to_a def to_a = [year.to_s, minor, patch.to_s]
[year.to_s, minor, patch.to_s]
end
def to_s def to_s = [to_a.join("."), suffix].join
[to_a.join("."), suffix].join
end
end end
end end