@@ -50,6 +50,45 @@ namespace :elasticsearch do
50
50
end
51
51
end
52
52
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
+
53
92
desc 'Download artifacts (tests and REST spec) for currently running cluster'
54
93
task :download_artifacts do
55
94
json_filename = CURRENT_PATH . join ( 'tmp/artifacts.json' )
0 commit comments