@@ -54,21 +54,13 @@ namespace :elasticsearch do
5454 begin
5555 artifacts = JSON . parse ( File . read ( filename ) )
5656 rescue StandardError => e
57- STDERR . puts "[!] Couldn't read JSON file #{ filename } "
57+ warn "[!] Couldn't read JSON file #{ json_filename } \n #{ e . message } "
5858 exit 1
5959 end
60-
61- build_hash_artifact = artifacts [ 'version' ] [ 'builds' ] . select do |build |
62- build . dig ( 'projects' , 'elasticsearch' , 'commit_hash' ) == build_hash
63- end . first
64-
65- unless build_hash_artifact
66- STDERR . puts "[!] Could not find artifact with build hash #{ build_hash } , using latest instead"
67- build_hash_artifact = artifacts [ 'version' ] [ 'builds' ] . first
68- end
69-
70- # Dig into the elasticsearch packages, search for the rest-resources-zip package and return the URL:
71- build_hash_artifact . dig ( 'projects' , 'elasticsearch' , 'packages' ) . select { |k , v | k =~ /rest-resources-zip/ } . map { | _ , v | v [ 'url' ] } . first
60+ # Search the JSON for the rest-resources-zip file and get the URL
61+ packages = artifacts . dig ( 'projects' , 'elasticsearch' , 'packages' )
62+ rest_resources = packages . select { |k , v | k =~ /rest-resources/ }
63+ zip_url = rest_resources . map { |_ , v | v [ 'url' ] } . first
7264 end
7365
7466 def download_file! ( url , filename )
@@ -90,6 +82,7 @@ namespace :elasticsearch do
9082
9183 desc 'Download artifacts (tests and REST spec) for currently running cluster'
9284 task :download_artifacts do
85+ require 'net/http'
9386 json_filename = CURRENT_PATH . join ( 'tmp/artifacts.json' )
9487
9588 unless ( version_number = ENV [ 'STACK_VERSION' ] )
@@ -102,9 +95,16 @@ namespace :elasticsearch do
10295 # Create ./tmp if it doesn't exist
10396 Dir . mkdir ( CURRENT_PATH . join ( 'tmp' ) , 0700 ) unless File . directory? ( CURRENT_PATH . join ( 'tmp' ) )
10497
105- # Download json file with package information for version:
106- json_url = "https://artifacts-api.elastic.co/v1/versions/#{ version_number } "
107- download_file! ( json_url , json_filename )
98+ # Get the latest minor from version number, and get latest snapshot
99+ major_minor = if version_number == 'main'
100+ 'master'
101+ else
102+ version_number . split ( '.' ) [ 0 ..1 ] . join ( '.' )
103+ end
104+ url = URI ( "https://artifacts-snapshot.elastic.co/elasticsearch/latest/#{ major_minor } .json" )
105+
106+ manifest_url = JSON . parse ( Net ::HTTP . get ( url ) ) [ 'manifest_url' ]
107+ download_file! ( manifest_url , json_filename )
108108
109109 # Get the package url from the json file given the build hash
110110 zip_url = package_url ( json_filename , build_hash )
0 commit comments