module VersionBump

This file is distributed under New Relic’s license terms. See github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.

Constants

MAJOR
MINOR
TINY
VERSION

Public Class Methods

determine_bump_type() click to toggle source

Determined version based on if changelog has a feature or not for version

# File lib/tasks/helpers/version_bump.rb, line 46
def self.determine_bump_type
  file = read_file('CHANGELOG.md')
  lines = file.split('## ')[1].split('- **')
  return MAJOR if lines.first.include?('Major version')
  return MINOR if lines.any? { |line| line.include?('Feature:') }

  TINY
end
read_file(path) click to toggle source
# File lib/tasks/helpers/version_bump.rb, line 37
def self.read_file(path)
  File.read(File.expand_path(path))
end
update_changelog(version) click to toggle source

Replace dev with version number in changelog

# File lib/tasks/helpers/version_bump.rb, line 56
def self.update_changelog(version)
  file = read_file('CHANGELOG.md')
  file.gsub!('## dev', "## v#{version}")
  file.gsub!('Version <dev>', "Version #{version}")
  write_file('CHANGELOG.md', file)
end
update_version() click to toggle source

Updates version.rb with new version number

# File lib/tasks/helpers/version_bump.rb, line 12
def self.update_version
  bump_type = determine_bump_type
  file = read_file('lib/new_relic/version.rb')
  new_version = {}

  VERSION.each do |key, current|
    file.gsub!(/(#{key.to_s.upcase} = )(\d+)/) do
      match = Regexp.last_match

      new_version[key] = if bump_type == current # bump type, increase by 1
        match[2].to_i + 1
      elsif bump_type < current # right of bump type, goes to 0
        0
      else # left of bump type, stays the same
        match[2].to_i
      end

      match[1] + new_version[key].to_s
    end
  end

  write_file('lib/new_relic/version.rb', file)
  new_version.values.join('.')
end
write_file(path, file) click to toggle source
# File lib/tasks/helpers/version_bump.rb, line 41
def self.write_file(path, file)
  File.write(File.expand_path(path), file)
end