Skip to content

Commit cc44fb1

Browse files
committed
[CI] Updates bump stack version automation for more explicit behaviour
1 parent 60e28b0 commit cc44fb1

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

rake_tasks/automation.rake

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -105,39 +105,48 @@ namespace :automation do
105105
DESC
106106
task :bumpmatrix, :version do |_, args|
107107
abort('[!] Required argument [version] missing') unless (version = args[:version])
108-
gh_actions = Dir.glob(File.expand_path('../.github/workflows/*.yml', __dir__))
108+
gh_actions = [
109+
File.expand_path('../.github/workflows/main.yml', __dir__),
110+
File.expand_path('../.github/workflows/otel.yml', __dir__),
111+
]
109112

110113
files = gh_actions + ['.buildkite/pipeline.yml']
111-
regexp = Regexp.new(/([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}?+(-SNAPSHOT)?)/)
112114
files.each do |file|
113115
content = File.read(file)
114116
if file == '.buildkite/pipeline.yml'
115-
require 'yaml'
116-
yaml = YAML.safe_load(content)
117-
yaml_tests_branch = yaml['steps'][0]['env']['ES_YAML_TESTS_BRANCH']
118-
119-
if yaml_tests_branch == 'main'
120-
old = content.match(/STACK_VERSION: (.*)/)[1]
121-
new = "STACK_VERSION: #{version}"
122-
content.gsub!(new, old)
123-
else
124-
branch = version.match(/([0-9]+\.[0-9]+)\.[0-9]+.*/)[1]
125-
content.gsub!(yaml_tests_branch, branch)
126-
end
127-
puts "[#{yaml_tests_branch}] -> [#{branch}] in #{file.gsub('./', '')}"
117+
pipeline(content, args[:version])
118+
elsif file.include?('.github/workflows/')
119+
workflows(content, args[:version])
128120
end
129-
match = content.match(regexp)
130-
next if match.nil?
131-
132-
old_version = match[1]
133-
next if old_version == args[:version]
134-
135-
content.gsub!(old_version, args[:version])
136-
puts "[#{old_version}] -> [#{version}] in #{file.gsub('./', '')}"
137121
File.open(file, 'w') { |f| f.puts content }
122+
puts "[#{version}] in #{file.to_s.gsub('./','')}"
138123
end
139124
end
140125

126+
def pipeline(content, version)
127+
yaml = YAML.safe_load(content)
128+
yaml_tests_branch = yaml['steps'][0]['env']['ES_YAML_TESTS_BRANCH']
129+
130+
if yaml_tests_branch == 'main'
131+
branch = yaml_tests_branch
132+
old = content.match(/STACK_VERSION: (.*)/)[0]
133+
new = "STACK_VERSION: #{version}"
134+
content.gsub!(old, new)
135+
else
136+
branch = version.match(/([0-9]+\.[0-9]+)\.[0-9]+.*/)[1]
137+
content.gsub!(yaml_tests_branch, branch)
138+
end
139+
end
140+
141+
def workflows(content, version)
142+
yaml = YAML.safe_load(content)
143+
tests = yaml['name'] == 'opentelemetry' ? 'otel' : 'main'
144+
old_version = yaml['jobs']["test-#{tests}"]['steps'][2]['with']['stack-version']
145+
return if old_version == version
146+
147+
content.gsub!(old_version, version)
148+
end
149+
141150
desc 'Show current client version'
142151
task :version do
143152
puts Elasticsearch::VERSION

0 commit comments

Comments
 (0)