Skip to content

Commit 8e497eb

Browse files
committed
[CI] Reorganize helpers for artifacts task
1 parent 4a39126 commit 8e497eb

File tree

2 files changed

+39
-38
lines changed

2 files changed

+39
-38
lines changed

rake_tasks/elasticsearch_tasks.rake

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,45 @@ namespace :elasticsearch do
5050
end
5151
end
5252

53+
54+
def package_url(filename, build_hash)
55+
begin
56+
artifacts = JSON.parse(File.read(filename))
57+
rescue StandardError => e
58+
STDERR.puts "[!] Couldn't read JSON file #{filename}"
59+
exit 1
60+
end
61+
62+
build_hash_artifact = artifacts['version']['builds'].select do |build|
63+
build.dig('projects', 'elasticsearch', 'commit_hash') == build_hash
64+
end.first
65+
66+
unless build_hash_artifact
67+
STDERR.puts "[!] Could not find artifact with build hash #{build_hash}, using latest instead"
68+
build_hash_artifact = artifacts['version']['builds'].first
69+
end
70+
71+
# Dig into the elasticsearch packages, search for the rest-resources-zip package and return the URL:
72+
build_hash_artifact.dig('projects', 'elasticsearch', 'packages').select { |k,v| k =~ /rest-resources-zip/ }.map { | _, v| v['url'] }.first
73+
end
74+
75+
def download_file!(url, filename)
76+
puts "Downloading #{filename} from #{url}"
77+
File.open(filename, "w") do |downloaded_file|
78+
URI.open(url, "rb") do |artifact_file|
79+
downloaded_file.write(artifact_file.read)
80+
end
81+
end
82+
puts "Successfully downloaded #{filename}"
83+
84+
unless File.exists?(filename)
85+
STDERR.puts "[!] Couldn't download #{filename}"
86+
exit 1
87+
end
88+
rescue StandardError => e
89+
abort e
90+
end
91+
5392
desc 'Download artifacts (tests and REST spec) for currently running cluster'
5493
task :download_artifacts do
5594
json_filename = CURRENT_PATH.join('tmp/artifacts.json')

rake_tasks/test_tasks.rake

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -96,42 +96,4 @@ namespace :test do
9696
STDERR.puts "[!] Test cluster not running?"
9797
abort e
9898
end
99-
100-
def package_url(filename, build_hash)
101-
begin
102-
artifacts = JSON.parse(File.read(filename))
103-
rescue StandardError => e
104-
STDERR.puts "[!] Couldn't read JSON file #{filename}"
105-
exit 1
106-
end
107-
108-
build_hash_artifact = artifacts['version']['builds'].select do |build|
109-
build.dig('projects', 'elasticsearch', 'commit_hash') == build_hash
110-
end.first
111-
112-
unless build_hash_artifact
113-
STDERR.puts "[!] Could not find artifact with build hash #{build_hash}, using latest instead"
114-
build_hash_artifact = artifacts['version']['builds'].first
115-
end
116-
117-
# Dig into the elasticsearch packages, search for the rest-resources-zip package and return the URL:
118-
build_hash_artifact.dig('projects', 'elasticsearch', 'packages').select { |k,v| k =~ /rest-resources-zip/ }.map { | _, v| v['url'] }.first
119-
end
120-
121-
def download_file!(url, filename)
122-
puts "Downloading #{filename} from #{url}"
123-
File.open(filename, "w") do |downloaded_file|
124-
URI.open(url, "rb") do |artifact_file|
125-
downloaded_file.write(artifact_file.read)
126-
end
127-
end
128-
puts "Successfully downloaded #{filename}"
129-
130-
unless File.exists?(filename)
131-
STDERR.puts "[!] Couldn't download #{filename}"
132-
exit 1
133-
end
134-
rescue StandardError => e
135-
abort e
136-
end
13799
end

0 commit comments

Comments
 (0)