Class: Shoes::Changelog
- Inherits:
-
Object
- Object
- Shoes::Changelog
- Defined in:
- lacci/lib/shoes/changelog.rb
Instance Method Summary collapse
- #get_latest_release_info ⇒ Object
-
#initialize ⇒ Changelog
constructor
include Shoes::Log.
Constructor Details
#initialize ⇒ Changelog
include Shoes::Log
10 11 12 13 14 15 |
# File 'lacci/lib/shoes/changelog.rb', line 10 def initialize #TODO : refer to https://github.com/scarpe-team/scarpe/pull/400 # and figure out how to use scarpe logger here without getting duplicate or nil error # Shoes::Log.instance = Scarpe::Components::ModularLogImpl.new # log_init("Changelog") end |
Instance Method Details
#get_latest_release_info ⇒ Object
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 |
# File 'lacci/lib/shoes/changelog.rb', line 17 def get_latest_release_info root_dir = File.dirname(__FILE__, 4) # this duplicates constants.rb, but how to share? git_dir = "#{root_dir}/.git" revision = nil if File.exist?(git_dir) revision = `git rev-parse HEAD`.chomp end changelog_file = "#{root_dir}/CHANGELOG.md" if File.exist?(changelog_file) changelog_content = File.read(changelog_file) release_name_pattern = /^## \[(\d+\.\d+\.\d+)\] - (\d{4}-\d{2}-\d{2}) - (\w+)$/m release_matches = changelog_content.scan(release_name_pattern) latest_release = release_matches.max_by { |version, _date, _name| Gem::Version.new(version) } if latest_release #puts "Found release #{latest_release[0]} in CHANGELOG.md" # @log.debug("Found release #{latest_release[0]} in CHANGELOG.md") # Logger isn't initialized yet version_parts = latest_release[0].split(".").map(&:to_i) rel_id = ("%02d%02d%02d" % version_parts).to_i return({ RELEASE_NAME: latest_release[2], RELEASE_BUILD_DATE: latest_release[1], RELEASE_ID: rel_id, REVISION: revision, }) end end puts "No release found in CHANGELOG.md" { RELEASE_NAME: nil, RELEASE_BUILD_DATE: nil, RELEASE_ID: nil, REVISION: revision } end |