Skip to content

Commit b297a79

Browse files
committed
[CI] Reorganize helpers for artifacts task
1 parent 0670f4c commit b297a79

File tree

2 files changed

+39
-38
lines changed

2 files changed

+39
-38
lines changed

rake_tasks/elasticsearch_tasks.rake

+39
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

-38
Original file line numberDiff line numberDiff line change
@@ -74,42 +74,4 @@ namespace :test do
7474
STDERR.puts "[!] Test cluster not running?"
7575
abort e
7676
end
77-
78-
def package_url(filename, build_hash)
79-
begin
80-
artifacts = JSON.parse(File.read(filename))
81-
rescue StandardError => e
82-
STDERR.puts "[!] Couldn't read JSON file #{filename}"
83-
exit 1
84-
end
85-
86-
build_hash_artifact = artifacts['version']['builds'].select do |build|
87-
build.dig('projects', 'elasticsearch', 'commit_hash') == build_hash
88-
end.first
89-
90-
unless build_hash_artifact
91-
STDERR.puts "[!] Could not find artifact with build hash #{build_hash}, using latest instead"
92-
build_hash_artifact = artifacts['version']['builds'].first
93-
end
94-
95-
# Dig into the elasticsearch packages, search for the rest-resources-zip package and return the URL:
96-
build_hash_artifact.dig('projects', 'elasticsearch', 'packages').select { |k,v| k =~ /rest-resources-zip/ }.map { | _, v| v['url'] }.first
97-
end
98-
99-
def download_file!(url, filename)
100-
puts "Downloading #{filename} from #{url}"
101-
File.open(filename, "w") do |downloaded_file|
102-
URI.open(url, "rb") do |artifact_file|
103-
downloaded_file.write(artifact_file.read)
104-
end
105-
end
106-
puts "Successfully downloaded #{filename}"
107-
108-
unless File.exists?(filename)
109-
STDERR.puts "[!] Couldn't download #{filename}"
110-
exit 1
111-
end
112-
rescue StandardError => e
113-
abort e
114-
end
11577
end

0 commit comments

Comments
 (0)