@@ -40,23 +40,21 @@ const downloadedSpec = join(esFolder, 'rest-api-spec', 'api')
40
40
const specFolder = join ( __dirname , '..' , '..' , 'specification' , '_json_spec' )
41
41
42
42
async function downloadArtifacts ( opts ) {
43
- if ( typeof opts . version !== 'string' && typeof opts . branch !== 'string' ) {
44
- throw new Error ( 'Missing version or branch' )
43
+ if ( typeof opts . branch !== 'string' ) {
44
+ throw new Error ( 'Missing branch' )
45
45
}
46
46
47
- core . info ( 'Checking out spec and test ' )
47
+ core . info ( 'Resolving artifact URL ' )
48
48
49
- core . info ( 'Resolving version' )
50
49
let resolved
51
50
try {
52
- resolved = await resolve ( opts . version || fromBranch ( opts . branch ) , opts . hash )
51
+ resolved = await resolve ( opts . branch )
53
52
} catch ( err ) {
54
53
core . error ( err . message )
55
54
process . exit ( 1 )
56
55
}
57
56
58
- opts . version = resolved . version
59
- core . info ( `Resolved version ${ opts . version } ` )
57
+ core . info ( `Resolved artifact URL for ${ resolved . commit_url } ` )
60
58
61
59
core . info ( 'Cleanup' )
62
60
await rm ( esFolder )
@@ -96,74 +94,26 @@ async function downloadArtifacts (opts) {
96
94
core . info ( 'Done' )
97
95
}
98
96
99
- async function resolve ( version , hash ) {
100
- if ( version === 'latest' ) {
101
- const response = await fetch ( 'https://artifacts-api.elastic.co/v1/versions' )
102
- if ( ! response . ok ) {
103
- throw new Error ( `unexpected response ${ response . statusText } ` )
104
- }
105
- const { versions } = await response . json ( )
106
- version = versions . pop ( )
107
- }
108
-
109
- core . info ( `Resolving version ${ version } ` )
110
- const response = await fetch ( `https://artifacts-api.elastic.co/v1/versions/${ version } ` )
97
+ async function resolve ( branch ) {
98
+ const url = `https://artifacts-snapshot.elastic.co/elasticsearch/latest/${ branch } .json`
99
+ const response = await fetch ( url )
111
100
if ( ! response . ok ) {
112
- throw new Error ( `unexpected response ${ response . statusText } ` )
101
+ throw new Error ( `Unexpected response. Invalid version? ${ url } : ${ response . statusText } ` )
113
102
}
114
-
115
103
const data = await response . json ( )
116
- const esBuilds = data . version . builds
117
- . filter ( build => build . projects . elasticsearch != null )
118
- . map ( build => {
119
- return {
120
- projects : build . projects . elasticsearch ,
121
- buildId : build . build_id ,
122
- date : build . start_time ,
123
- version : build . version
124
- }
125
- } )
126
- . sort ( ( a , b ) => {
127
- const dA = new Date ( a . date )
128
- const dB = new Date ( b . date )
129
- if ( dA > dB ) return - 1
130
- if ( dA < dB ) return 1
131
- return 0
132
- } )
133
-
134
- if ( hash != null ) {
135
- const build = esBuilds . find ( build => build . projects . commit_hash === hash )
136
- if ( ! build ) {
137
- throw new Error ( `Can't find any build with hash '${ hash } '` )
138
- }
139
- const zipKey = Object . keys ( build . projects . packages ) . find ( key => key . startsWith ( 'rest-resources-zip-' ) && key . endsWith ( '.zip' ) )
140
- return {
141
- url : build . projects . packages [ zipKey ] . url ,
142
- id : build . buildId ,
143
- hash : build . projects . commit_hash ,
144
- version : build . version
145
- }
146
- }
147
104
148
- const lastBuild = esBuilds [ 0 ]
149
- const zipKey = Object . keys ( lastBuild . projects . packages ) . find ( key => key . startsWith ( 'rest-resources-zip-' ) && key . endsWith ( '.zip' ) )
150
- return {
151
- url : lastBuild . projects . packages [ zipKey ] . url ,
152
- id : lastBuild . buildId ,
153
- hash : lastBuild . projects . commit_hash ,
154
- version : lastBuild . version
105
+ let manifest_url = data . manifest_url
106
+ const manifestResponse = await fetch ( manifest_url )
107
+ if ( ! manifestResponse . ok ) {
108
+ throw new Error ( `Unexpected manifestResponse. ${ manifest_url } : ${ manifestResponse . statusText } ` )
155
109
}
156
- }
110
+ const manifestData = await manifestResponse . json ( )
111
+ const elasticsearch = manifestData . projects . elasticsearch
112
+ const restResourceName = `rest-resources-zip-${ manifestData . version } .zip`
157
113
158
- function fromBranch ( branch ) {
159
- if ( branch === 'main' ) {
160
- return 'latest'
161
- } else if ( branch === '7.x' ) {
162
- return '7.x-SNAPSHOT'
163
- } else if ( ( branch . startsWith ( '7.' ) || branch . startsWith ( '8.' ) ) && ! isNaN ( Number ( branch . split ( '.' ) [ 1 ] ) ) ) {
164
- return `${ branch } -SNAPSHOT`
165
- } else {
166
- throw new Error ( `Cannot derive version from branch '${ branch } '` )
114
+ return {
115
+ url : elasticsearch . packages [ restResourceName ] . url ,
116
+ commit_url : elasticsearch . commit_url ,
167
117
}
168
118
}
169
119
@@ -172,7 +122,7 @@ async function main (options) {
172
122
}
173
123
174
124
const options = minimist ( process . argv . slice ( 2 ) , {
175
- string : [ 'id' , 'version' , 'hash' , ' branch']
125
+ string : [ 'branch' ]
176
126
} )
177
127
main ( options ) . catch ( t => {
178
128
core . error ( t )
0 commit comments