Skip to content

Commit b7b1ef7

Browse files
committed
Adds task to automatically update to the latest STACK_VERSION
1 parent ce8efd7 commit b7b1ef7

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

Rakefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def admin_client
3838
}
3939
)
4040

41-
url = "https://#{user}:#{password}@#{uri.host}:#{uri.port}"
41+
url = "https://#{user}:#{password}@#{uri.host}:#{uri.port}"
4242
else
43-
url = "http://#{user}:#{password}@#{uri.host}:#{uri.port}"
43+
url = "http://#{user}:#{password}@#{uri.host}:#{uri.port}"
4444
end
4545
puts "Elasticsearch Client url: #{url}"
4646
Elasticsearch::Client.new(host: url, transport_options: transport_options)

rake_tasks/automation.rake

+7-11
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ require_relative '../elasticsearch/lib/elasticsearch/version'
2020

2121
namespace :automation do
2222
desc 'Build gem releases and snapshots'
23-
task :build_gems do |_, args|
24-
output_dir = File.expand_path(__dir__ + '/../build')
25-
require 'byebug'; byebug
26-
27-
23+
task :build_gems do
24+
output_dir = File.expand_path("#{__dir__}/../build")
2825
dir = CURRENT_PATH.join(output_dir).to_s
2926
FileUtils.mkdir_p(dir) unless File.exist?(dir)
3027
version = Elasticsearch::VERSION
@@ -40,7 +37,7 @@ namespace :automation do
4037

4138
desc 'Generate API code'
4239
task :codegen do
43-
version = YAML.load_file(File.expand_path(__dir__ + '/../.buildkite/pipeline.yml'))['steps'].first['env']['STACK_VERSION']
40+
version = YAML.load_file(File.expand_path("#{__dir__}/../.buildkite/pipeline.yml"))['steps'].first['env']['STACK_VERSION']
4441

4542
Rake::Task['elasticsearch:download_artifacts'].invoke(version)
4643
sh "cd #{CURRENT_PATH.join('elasticsearch-api/utils')} \
@@ -100,16 +97,15 @@ namespace :automation do
10097
DESC
10198
task :bumpmatrix, :version do |_, args|
10299
abort('[!] Required argument [version] missing') unless (version = args[:version])
100+
gh_actions = Dir.glob(File.expand_path('../.github/workflows/*.yml', __dir__))
103101

104-
files = [
105-
'.github/workflows/main.yml',
106-
'.github/workflows/otel.yml',
107-
'.buildkite/pipeline.yml'
108-
]
102+
files = gh_actions + ['.buildkite/pipeline.yml']
109103
regexp = Regexp.new(/([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}?+(-SNAPSHOT)?)/)
110104
files.each do |file|
111105
content = File.read(file)
112106
match = content.match(regexp)
107+
next if match.nil?
108+
113109
old_version = match[1]
114110
content.gsub!(old_version, args[:version])
115111
puts "[#{old_version}] -> [#{version}] in #{file.gsub('./', '')}"

rake_tasks/elasticsearch_tasks.rake

+13
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ namespace :elasticsearch do
4141
end
4242
end
4343

44+
desc 'Automatically update to latest version'
45+
task :autoupdate_version do
46+
require 'tempfile'
47+
48+
branch = `git branch --show-current`.strip
49+
url = "https://snapshots.elastic.co/latest/#{branch}.json"
50+
file = Tempfile.new('version')
51+
download_file!(url, file)
52+
version = JSON.parse(file.read)['version']
53+
puts "Latest version is #{version}"
54+
Rake::Task['automation:bumpmatrix'].invoke(version)
55+
end
56+
4457
def download_file!(url, filename)
4558
puts "Downloading #{filename} from #{url}"
4659
File.open(filename, 'w') do |downloaded_file|

0 commit comments

Comments
 (0)