Commit 9f1f9efe authored by DJ Mountney's avatar DJ Mountney

Start building a script for bumping the chart and app versions

Updated our changelog script so that is can be run from root, and
includse the upstream release-tools version option as a foundation.

[ci skip]
parent 92d4567a
Pipeline #23166754 skipped
config.yaml
ci/terraform/.terraform
charts/*.tgz
Gemfile.lock
......@@ -16,9 +16,8 @@ access to the `master` branch.
```sh
git checkout master
git pull master
cd scripts
bundle install
scripts/changelog_manager.rb ../
scripts/changelog_manager.rb .
git push
```
......
require_relative '../version'
require_relative '../changelog_version'
module Changelog
# Updates a Markdown changelog String by inserting new Markdown for a
......@@ -38,7 +38,7 @@ module Changelog
def insert(markdown)
contents.each_with_index do |line, index|
if line =~ /\A## (\d{4}-\d{2}-\d{2})/
header = Version.new($1)
header = ChangelogVersion.new($1)
if version == header
entries = markdown.lines
......
require_relative 'version'
class ChangelogVersion < Version
VERSION_REGEX = %r{
\A(?<year>\d{4})
-(?<month>\d{2})
-(?<day>\d{2})\z
}x
def year
@year ||= extract_from_version(:year).to_i
end
alias_method :major, :year
def month
@month ||= extract_from_version(:month).to_i
end
alias_method :minor, :month
def day
@day ||= extract_from_version(:day).to_i
end
alias_method :minor, :patch
def to_s
"%04d-%02d-%02d" % [year, month, day]
end
end
class Version < String
VERSION_REGEX = %r{
\A(?<year>\d{4})
-(?<month>\d{2})
-(?<day>\d{2})\z
\A(?<major>\d+)
\.(?<minor>\d+)
(\.(?<patch>\d+))?
(-(?<rc>rc(?<rc_number>\d*)))?
(-ee)?\z
}x
def initialize(version_string)
super(version_string)
if valid? && extract_from_version(:patch, fallback: nil).nil?
rc? ? super(to_rc(rc)) : super(to_patch)
end
end
def ==(other)
if other.respond_to?(:to_ce)
to_ce.eql?(other.to_ce)
else
super
end
end
def <=>(other)
return nil unless other.is_a?(Version)
return 0 if self == other
if year > other.year ||
(year >= other.year && month > other.month) ||
(year >= other.year && month >= other.month && day > other.day)
1
if major > other.major ||
(major >= other.major && minor > other.minor) ||
(major >= other.major && minor >= other.minor && patch > other.patch) ||
(major >= other.major && minor >= other.minor && patch >= other.patch && other.rc?)
rc? ? (rc - other.rc) : 1
else
-1
end
end
def year
@year ||= extract_from_version(:year).to_i
def ee?
end_with?('-ee')
end
def milestone_name
to_minor
end
def monthly?
patch.zero? && !rc?
end
def patch?
patch.positive?
end
def month
@month ||= extract_from_version(:month).to_i
def major
@major ||= extract_from_version(:major).to_i
end
def day
@day ||= extract_from_version(:day).to_i
def minor
@minor ||= extract_from_version(:minor).to_i
end
def patch
@patch ||= extract_from_version(:patch).to_i
end
def rc
return unless rc?
@rc ||= extract_from_version(:rc_number).to_i
end
def rc?
return @is_rc if defined?(@is_rc)
@is_rc = extract_from_version(:rc, fallback: false)
end
def version?
self =~ self.class::VERSION_REGEX
end
def valid?
self =~ self.class::VERSION_REGEX
def release?
valid? && !rc? && !ee?
end
def next_minor
"#{major}.#{minor + 1}.0"
end
def previous_patch
return unless patch?
new_patch = self.class.new("#{major}.#{minor}.#{patch - 1}")
ee? ? new_patch.to_ee : new_patch
end
def next_patch
new_patch = self.class.new("#{major}.#{minor}.#{patch + 1}")
ee? ? new_patch.to_ee : new_patch
end
def stable_branch(ee: false)
to_minor.tr('.', '-').tap do |prefix|
if ee || ee?
prefix << '-stable-ee'
else
prefix << '-stable'
end
end
end
def to_s
"%04d-%02d-%02d" % [year, month, day]
def tag(ee: false)
tag_for(self, ee: ee)
end
def previous_tag(ee: false)
return unless patch?
return if rc?
tag_for(previous_patch, ee: ee)
end
# Convert the current version to CE if it isn't already
def to_ce
return self unless ee?
self.class.new(to_s.gsub(/-ee$/, ''))
end
# Convert the current version to EE if it isn't already
def to_ee
return self if ee?
self.class.new("#{self}-ee")
end
def to_minor
"#{major}.#{minor}"
end
def to_omnibus(ee: false)
str = "#{to_patch}+"
str << "rc#{rc}." if rc?
str << (ee ? 'ee' : 'ce')
str << '.0'
end
def to_docker(ee: false)
to_omnibus(ee: ee).tr('+', '-')
end
def to_patch
"#{major}.#{minor}.#{patch}"
end
def to_rc(number = 1)
"#{to_patch}-rc#{number}".tap do |version|
version << '-ee' if ee?
end
end
def valid?
self =~ self.class::VERSION_REGEX
end
private
def tag_for(version, ee: false)
version = version.to_ee if ee
"v#{version}"
end
def extract_from_version(part, fallback: 0)
match_data = self.class::VERSION_REGEX.match(self)
if match_data && match_data.names.include?(part.to_s) && match_data[part]
......
#!/usr/bin/env ruby
require 'optparse'
require 'yaml'
require_relative 'lib/version'
# Grab current versions
class ChartFile
attr_reader :metadata
def initialize(filepath)
unless filepath && File.exist?(filepath)
$stderr.puts "Chart file must exist"
exit 1
end
@filepath = filepath
@metadata = YAML.load(File.read(filepath))
end
def version
Version.new(@metadata['version'])
end
def appVersion
Version.new(@metadata['appVersion'])
end
end
# Set versions
# Accept chart version or gitlab app version
options = {
working_dir: Dir.pwd
}
OptionParser.new do |opts|
opts.banner = "Usage: #{__FILE__} [options] \n\n"
opts.on("--app-version [string]", String, "GitLab Application Version") do |value|
options[:app_version] = Version.new(value)
end
opts.on("--chart-version [string]", String, "Chart Package Version") do |value|
options[:chart_version] = Version.new(value)
end
opts.on("-d", "--directory [string]", String, "Working directory for the script") do |value|
options[:working_dir] = value
end
opts.on('-h', '--help', 'Print help message') do
$stdout.puts opts
exit
end
end.parse!
unless (options[:app_version] && options[:app_version].valid?) && (options[:chart_version] && options[:chart_version].valid?)
$stderr.puts "Must specify a valid --app-version or --chart-version in the syntax 'x.x.x' eg: 11.0.0"
exit 1
end
unless Dir.exist?(options[:working_dir])
$stderr.puts "Must provide a valid working directory"
exit 1
end
chart = ChartFile.new(File.join(options[:working_dir], 'Chart.yaml'))
# If we were not passed the new chart version, use the gitlab version to bump it
unless options[:chart_version]
# No Op if app version has not changed
if options[:app_version] == chart.appVersion
$stdout.puts "Version already updated"
exit
end
end
$stdout.puts "#{chart.version} + #{chart.appVersion}"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment