@@ -43,7 +43,7 @@ namespace :elasticsearch do
43
43
end
44
44
end
45
45
46
- def package_url ( filename , build_hash )
46
+ def package_url ( filename )
47
47
begin
48
48
artifacts = JSON . parse ( File . read ( filename ) )
49
49
rescue StandardError => e
@@ -52,16 +52,18 @@ namespace :elasticsearch do
52
52
end
53
53
54
54
build_hash_artifact = artifacts [ 'version' ] [ 'builds' ] . select do |build |
55
- build . dig ( 'projects' , 'elasticsearch' , 'commit_hash' ) == build_hash
55
+ build . dig ( 'projects' , 'elasticsearch' , 'commit_hash' ) == @ build_hash
56
56
end . first
57
57
58
58
unless build_hash_artifact
59
- STDERR . puts "[!] Could not find artifact with build hash #{ build_hash } , using latest instead"
59
+ STDERR . puts "[!] Could not find artifact with build hash #{ @build_hash } , using latest instead"
60
+
60
61
build_hash_artifact = artifacts [ 'version' ] [ 'builds' ] . first
62
+ @build_hash = artifacts [ 'version' ] [ 'builds' ] . first [ 'projects' ] [ 'elasticsearch' ] [ 'commit_hash' ]
61
63
end
62
64
63
65
# Dig into the elasticsearch packages, search for the rest-resources-zip package and return the URL:
64
- build_hash_artifact . dig ( 'projects' , 'elasticsearch' , 'packages' ) . select { |k , v | k =~ /rest-resources-zip/ } . map { | _ , v | v [ 'url' ] } . first
66
+ build_hash_artifact . dig ( 'projects' , 'elasticsearch' , 'packages' ) . select { |k , _ | k =~ /rest-resources-zip/ } . map { |_ , v | v [ 'url' ] } . first
65
67
end
66
68
67
69
def download_file! ( url , filename )
@@ -73,8 +75,8 @@ namespace :elasticsearch do
73
75
end
74
76
puts "Successfully downloaded #{ filename } "
75
77
76
- unless File . exists ?( filename )
77
- STDERR . puts "[!] Couldn't download #{ filename } "
78
+ unless File . exist ?( filename )
79
+ warn "[!] Couldn't download #{ filename } "
78
80
exit 1
79
81
end
80
82
rescue StandardError => e
@@ -88,8 +90,8 @@ namespace :elasticsearch do
88
90
unless ( version_number = args [ :version ] || ENV [ 'STACK_VERSION' ] )
89
91
# Get version number and build hash of running cluster:
90
92
version_number = cluster_info [ 'number' ]
91
- build_hash = cluster_info [ 'build_hash' ]
92
- puts "Build hash: #{ build_hash } "
93
+ @ build_hash = cluster_info [ 'build_hash' ]
94
+ puts "Build hash: #{ @ build_hash} "
93
95
end
94
96
95
97
# Create ./tmp if it doesn't exist
@@ -100,7 +102,7 @@ namespace :elasticsearch do
100
102
download_file! ( json_url , json_filename )
101
103
102
104
# Get the package url from the json file given the build hash
103
- zip_url = package_url ( json_filename , build_hash )
105
+ zip_url = package_url ( json_filename )
104
106
105
107
# Download the zip file
106
108
filename = CURRENT_PATH . join ( "tmp/#{ zip_url . split ( '/' ) . last } " )
@@ -112,6 +114,7 @@ namespace :elasticsearch do
112
114
puts "Unzipping file #{ filename } "
113
115
`unzip -o #{ filename } -d tmp/`
114
116
`rm #{ filename } `
115
- puts 'Artifacts downloaded in ./tmp'
117
+ puts "Artifacts downloaded in ./tmp, build hash #{ @build_hash } "
118
+ File . write ( CURRENT_PATH . join ( 'tmp/rest-api-spec/build_hash' ) , @build_hash )
116
119
end
117
120
end
0 commit comments