class Gitlab::QA::Support::GitlabVersionInfo
def current_major
-
(Integer)
-
def current_major @current_major ||= current_version.match(COMPONENT_PATTERN)[:major].to_i end
def current_minor
-
(Integer)
-
def current_minor @current_minor ||= current_version.match(COMPONENT_PATTERN)[:minor].to_i end
def current_patch
-
(Integer)
-
def current_patch @current_patch ||= current_version.match(COMPONENT_PATTERN)[:patch].to_i end
def fallback_major
-
(String)
-
def fallback_major previous_fallback_version(current_major - 1) end
def fallback_minor
-
(String)
-
def fallback_minor return previous_fallback_version(current_major, current_minor - 1) unless current_minor.zero? previous_major end
def fallback_patch
-
(String)
-
def fallback_patch return previous_fallback_version(current_major, current_minor, current_patch - 1) unless current_patch.zero? previous_minor end
def fetch_tags(page:, per_page: TAGS_PER_PAGE)
def fetch_tags(page:, per_page: TAGS_PER_PAGE) logger.info("Fetching Docker tags page #{page} from 'gitlab/gitlab-#{edition}' registry") response = HttpRequest.make_http_request( url: "https://registry.hub.docker.com/v2/namespaces/gitlab/repositories/gitlab-#{edition}/tags?page=#{page}&page_size=#{per_page}", fail_on_error: false ) unless response.code == 200 logger.error(" failed to fetch docker tags - code: #{response.code}, response: '#{response.body}'") return nil end response = JSON.parse(response.body, symbolize_names: true) matching_tags = response .fetch(:results) .map { |tag| tag[:name] } .grep(VERSION_PATTERN) more_data = response.fetch(:next) [matching_tags, more_data] end
def initialize(current_version, edition)
-
edition
(String
) -- GitLab edition - ee or ce -
current_version
(String
) --
def initialize(current_version, edition) @current_version = current_version @edition = edition @logger = Runtime::Logger.logger end
def latest_patch(version)
-
(String)
-
Parameters:
-
version
(Gem::Version
) --
def latest_patch(version) # check if version is already a patch version return version if version.to_s.split('.').size == 3 versions.find { |ver| ver.to_s.match?(/^#{version}\./) }.tap do |ver| raise_version_not_found("Latest patch version for version #{version}") unless ver end end
def previous_fallback_version(major_component, minor_component = 0, patch_component = 0)
-
(Gem::Version)
-
Parameters:
-
patch_component
(Integer
) -- -
minor_component
(Integer
) -- -
major_component
(Integer
) --
def previous_fallback_version(major_component, minor_component = 0, patch_component = 0) Gem::Version.new("#{major_component}.#{minor_component}.#{patch_component}") end
def previous_major
-
(String)
-
def previous_major return fallback_major unless tags versions.find { |version| version.to_s.start_with?((current_major - 1).to_s) } end
def previous_minor
-
(String)
-
def previous_minor return fallback_minor unless tags return previous_major if current_minor.zero? versions.find { |version| version.to_s.match?(/^#{current_major}\.#{current_minor - 1}/) }.tap do |ver| raise_version_not_found("Previous minor version for current version #{current_version}") unless ver end end
def previous_patch
-
(String)
-
def previous_patch return fallback_patch unless tags return previous_minor if current_patch.zero? versions.find { |version| version.to_s.match?(/^#{current_major}\.#{current_minor}\.#{current_patch - 1}/) } end
def previous_version(semver_component)
-
(Gem::Version)
-
Parameters:
-
semver_component
(String
) -- version number component for previous version detection - major|minor|patch
def previous_version(semver_component) case semver_component when "major" previous_major when "minor" previous_minor when "patch" previous_patch else raise("Unsupported semver component, must be major|minor|patch") end end
def raise_version_not_found(error_prefix)
def raise_version_not_found(error_prefix) raise(VersionNotFoundError, "#{error_prefix} not available on Dockerhub (yet)") end
def tags
-
(Array
-)
def tags return @tags if defined?(@tags) MAX_TAGS_HTTP_REQUESTS.times do |index| tag_list, more_data = fetch_tags(page: index + 1) if tag_list @tags = Array(@tags) @tags += tag_list end break if tag_list.nil? || more_data.nil? end @tags end
def version(tag)
-
(String)
-
Parameters:
-
tag
(String
) --
def version(tag) tag.match(VERSION_PATTERN)[:version] end
def versions
-
(Array
-)
def versions @versions = tags .map { |tag| Gem::Version.new(tag.match(VERSION_PATTERN)[:version]) } .sort .reverse # reverse array so first match by .find always returns latest version end