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



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

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']


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

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

.current_listObject

Returns the list of versions from versions.gitlab.com



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

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

.current_minor_for_date(date) ⇒ Object

Returns the current major.minor for the given date



120
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
# File 'lib/gitlab_releases/release_versions.rb', line 120

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



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

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']


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

def self.latest(versions, count = 3)
  ::VersionSorter.rsort(versions).uniq do |version|
    version.split('.').take(2)
  end.take(count)
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']


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

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

.next_versionsObject

Get the next three patch versions



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

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



168
169
170
171
172
173
# File 'lib/gitlab_releases/release_versions.rb', line 168

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



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

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’



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

def self.previous_version
  next_versions.second.previous_patch
end

.sort(versions) ⇒ Object



158
159
160
# File 'lib/gitlab_releases/release_versions.rb', line 158

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

.upcoming_release_dateObject

Returns the release date of the upcoming (active) version



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

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



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

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