blob: be79af499ea0d5833f84a11f9047155f295bc658 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
require 'yaml'
PRODUCTS = %W[ee omnibus runner charts].freeze
VERSION_FORMAT = /^(?<major>\d{1,2})\.(?<minor>\d{1,2})$/
def config
# Parse the config file and create a hash.
@config ||= YAML.load_file('./nanoc.yaml')
end
def products
return @products if defined?(@products)
# Pull products data from the config.
@products = PRODUCTS.each_with_object({}) do |key, result|
result[key] = config['products'][key]
end
end
def retrieve_branch(slug)
# If CI_COMMIT_REF_NAME is not defined, set it to master.
if ENV["CI_COMMIT_REF_NAME"].nil?
'master'
# If we're on a gitlab-docs stable branch according to the regex, catch the
# version and assign the product stable branches correctly.
elsif version = ENV["CI_COMMIT_REF_NAME"].match(VERSION_FORMAT)
case slug
# EE has different branch name scheme
when 'ee'
"#{version[:major]}-#{version[:minor]}-stable-ee"
when 'omnibus', 'runner'
"#{version[:major]}-#{version[:minor]}-stable"
# Charts don't use the same version scheme as GitLab, we need to
# deduct their version from the GitLab equivalent one.
when 'charts'
chart = chart_version(ENV["CI_COMMIT_REF_NAME"]).match(VERSION_FORMAT)
"#{chart[:major]}-#{chart[:minor]}-stable"
# For all other products use master
else
'master'
end
# If we're NOT on a gitlab-docs stable branch, fetch the BRANCH_* environment
# variable, and if not assigned, set to master.
else
ENV.fetch("BRANCH_#{slug.upcase}", 'master')
end
end
def git_workdir_dirty?
status = `git status --porcelain`
!status.empty?
end
def local_branch_exist?(branch)
status = `git branch --list #{branch}`
!status.empty?
end
def chart_version_added?(gitlab_version)
config = YAML.load_file('./content/_data/chart_versions.yaml')
config.key?(gitlab_version)
end
def chart_version(gitlab_version)
config = YAML.load_file('./content/_data/chart_versions.yaml')
config.fetch(gitlab_version)
end
|