Class: ReleaseVersions

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_releases/release_versions.rb

Overview

Wrapper to interact with GitLab release versions. Versions are fetched from two sources:

  1. versions.gitlab.com => Used to interact with previous GitLab versions
  2. releases.yml => Used to interact with upcoming GitLab releases

Constant Summary collapse

RETRY_INTERVAL =

The base interval for retrying operations that failed, in seconds.

5
RELEASES_YAML =

Releases.yml file.

'https://gitlab.com/gitlab-com/www-gitlab-com/-/raw/master/data/releases.yml'

Class Method Summary collapse

Class Method Details

.active_versionObject

Returns the active minor GitLab Version



90
91
92
# File 'lib/gitlab_releases/release_versions.rb', line 90

def self.active_version
  version_for_date(DateTime.now)
end

.available_versionsObject

Returns the available GitLab versions as an Array

Example:

available_versions
=> ['1.2.3', '1.1.1', '1.0.0']


64
65
66
# File 'lib/gitlab_releases/release_versions.rb', line 64

def self.available_versions
  ::VersionSorter.rsort(current_list)
end

.current_listObject

Returns the list of versions from versions.gitlab.com



22
23
24
# File 'lib/gitlab_releases/release_versions.rb', line 22

def self.current_list
  raw_versions.collect(&:version)
end

.current_minor_for_date(date) ⇒ Object

Returns the current major.minor for the given date



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/gitlab_releases/release_versions.rb', line 121

def self.current_minor_for_date(date)
  # Returns the current version associated with the date by calling `releases_yaml`
  # and fetching the version whose release date is less or equal to the given date.
  #
  # For example:
  #
  # | Version | Date           |
  # |:--------|:---------------|
  # | 16.3    | August 22nd    |
  # | 16.4    | September 22nd |
  # | 16.5    | October 22nd   |
  # | 16.6    | November 16th  |
  # | 16.7    | December 21st  |
  #
  # * For August 21st, the release should be 16.2
  # * For August 22nd, the release should be 16.3
  # * For August 23rd, the release should be 16.3
  # * For November 17th, the release should be 16.6
  return nil if releases_yaml.empty?

  row = releases_yaml
    .reverse
    .detect { |release| date.to_date >= release['date'] }

  ReleaseVersion.new(row['version'])
end

.current_versionObject

Returns the current GitLab minor version



69
70
71
# File 'lib/gitlab_releases/release_versions.rb', line 69

def self.current_version
  ReleaseVersion.new(next_versions.first.to_minor)
end

.latest(versions, count = 3) ⇒ Object

Given an Array of version strings, find the count latest by minor number

versions - Array of version strings count - Number of versions to return (default: 3)

Example:

latest(['1.0.0', '1.1.0', '1.1.1', '1.2.3'], 3)
=> ['1.2.3', '1.1.1', '1.0.0']


52
53
54
55
56
# File 'lib/gitlab_releases/release_versions.rb', line 52

def self.latest(versions, count = 3)
  ::VersionSorter.rsort(versions).uniq do |version|
    version.split('.').take(2)
  end.take(count)
end

.latest_patch_for_version(version) ⇒ Object

Returns the latest patch for a given minor version

For example:

  • If the given version is 16.7 and available versions include 16.7.0, 16.7.1, 16.7.2 it will return 16.7.2
  • If the given version is 16.5 and available versions include 16.5.0, 16.5.1 it will return 16.5.1


166
167
168
169
170
# File 'lib/gitlab_releases/release_versions.rb', line 166

def self.latest_patch_for_version(version)
  minor_version = ReleaseVersion.new(version).to_minor

  available_versions.find { |v| v.start_with?("#{minor_version}.") }
end

.next(versions) ⇒ Object

Given an Array of version numbers, return the next patch versions

Example:

next(['1.0.0', '1.1.0', '1.1.1', '1.2.3'])
=> ['1.0.1', '1.1.1', '1.1.2', '1.2.4']


37
38
39
40
41
# File 'lib/gitlab_releases/release_versions.rb', line 37

def self.next(versions)
  versions.map do |version|
    ReleaseVersion.new(version).next_patch
  end
end

.next_versionsObject

Get the next three patch versions



27
28
29
# File 'lib/gitlab_releases/release_versions.rb', line 27

def self.next_versions
  self.next(latest(current_list, 3))
end

.previous_minors(version) ⇒ Object

Returns the previous major.minor versions of the major.minor version based on the releases.yml data

For example:

  • If the current version is 16.7, the previous patch versions are 16.7, 16.6, and 16.5
  • If the current version is 17.1, the previous patch versions are 17.1, 16.11, and 16.10


182
183
184
185
186
187
# File 'lib/gitlab_releases/release_versions.rb', line 182

def self.previous_minors(version)
  versions = releases_yaml.map { |release| release['version'] }
    .reverse

  versions[versions.index(version), 3]
end

.previous_release_dateObject

Returns the release date of the current version



74
75
76
77
78
79
80
# File 'lib/gitlab_releases/release_versions.rb', line 74

def self.previous_release_date
  date = raw_versions
    .find { |version| version.version == "#{current_version}.0" }
    .created_at

  Date.parse(date)
end

.previous_versionObject

Returns the last patch of the previous minor version

For example, if the current version is 16.4, then the previous version would be 16.3 and the last registered patch is 16.3.5

=> previous_version => '16.3.5'



155
156
157
# File 'lib/gitlab_releases/release_versions.rb', line 155

def self.previous_version
  next_versions.second.previous_patch
end

.sort(versions) ⇒ Object



172
173
174
# File 'lib/gitlab_releases/release_versions.rb', line 172

def self.sort(versions)
  ::VersionSorter.sort(versions).uniq
end

.upcoming_release_dateObject

Returns the release date of the upcoming (active) version



83
84
85
86
87
# File 'lib/gitlab_releases/release_versions.rb', line 83

def self.upcoming_release_date
  releases_yaml
    .find { |release| release['version'] == active_version }
    .fetch('date')
end

.version_for_date(date) ⇒ Object

Returns the scheduled major.minor for the given date



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/gitlab_releases/release_versions.rb', line 95

def self.version_for_date(date)
  # Returns the active release associated with the date by calling `releases_yaml` and fetching the
  # release whose date is greater or equal than the given date.
  #
  # For example:
  #
  # | Version | Date           |
  # |:--------|:---------------|
  # | 16.3    | August 22nd    |
  # | 16.4    | September 22nd |
  # | 16.5    | October 22nd   |
  # | 16.6    | November 16th  |
  # | 16.7    | December 21st  |
  #
  # * For August 21st, the release should be 16.3
  # * For August 22nd, the release should be 16.3
  # * For August 23rd, the release should be 16.4
  # * For November 17th, the release should be 16.7
  return nil if releases_yaml.empty?

  row = releases_yaml.find { |release| release['date'] >= date.to_date }

  ReleaseVersion.new(row['version'])
end