@@ -33,6 +33,8 @@ const unzip = promisify(crossZip.unzip)
33
33
const testYamlFolder = join ( __dirname , '..' , 'yaml-rest-tests' )
34
34
const zipFile = join ( __dirname , '..' , 'serverless-clients-tests.zip' )
35
35
36
+ const specFolder = join ( __dirname , '..' , 'rest-api-spec' )
37
+
36
38
async function downloadArtifacts ( ) {
37
39
const log = ora ( 'Checking out spec and test' ) . start ( )
38
40
@@ -49,7 +51,7 @@ async function downloadArtifacts () {
49
51
process . exit ( 1 )
50
52
}
51
53
52
- const response = await fetch ( 'https://api.github.com/repos/elastic/serverless-clients-tests/zipball/main' , {
54
+ let response = await fetch ( 'https://api.github.com/repos/elastic/serverless-clients-tests/zipball/main' , {
53
55
headers : {
54
56
Authorization : `Bearer ${ GITHUB_TOKEN } ` ,
55
57
Accept : "application/vnd.github+json" ,
@@ -70,6 +72,36 @@ async function downloadArtifacts () {
70
72
log . text = 'Cleanup'
71
73
await rimraf ( zipFile )
72
74
75
+ log . text = 'Fetching Elasticsearch spec info'
76
+ await rimraf ( specFolder )
77
+ await mkdir ( specFolder , { recursive : true } )
78
+
79
+ response = await fetch ( 'https://artifacts-api.elastic.co/v1/versions' )
80
+ let data = await response . json ( )
81
+ const latest = data . versions [ data . versions . length - 1 ]
82
+ response = await fetch ( `https://artifacts-api.elastic.co/v1/versions/${ latest } ` )
83
+ data = await response . json ( )
84
+ const latestBuild = data . version . builds
85
+ . filter ( build => build . projects . elasticsearch !== null )
86
+ . sort ( ( a , b ) => new Date ( b . start_time ) - new Date ( a . start_time ) ) [ 0 ]
87
+
88
+ const buildZip = Object . keys ( latestBuild . projects . elasticsearch . packages )
89
+ . find ( key => key . startsWith ( 'rest-resources-zip-' ) && key . endsWith ( '.zip' ) )
90
+ const zipUrl = latestBuild . projects . elasticsearch . packages [ buildZip ] . url
91
+
92
+ log . test = 'Fetching Elasticsearch spec zip'
93
+ response = await fetch ( zipUrl )
94
+
95
+ log . text = 'Downloading spec zip'
96
+ const specZipFile = join ( specFolder , 'rest-api-spec.zip' )
97
+ await pipeline ( response . body , createWriteStream ( specZipFile ) )
98
+
99
+ log . text = 'Unzipping spec'
100
+ await unzip ( specZipFile , specFolder )
101
+
102
+ log . text = 'Cleanup'
103
+ await rimraf ( specZipFile )
104
+
73
105
log . succeed ( 'Done' )
74
106
}
75
107
@@ -90,4 +122,4 @@ if (require.main === module) {
90
122
}
91
123
92
124
module . exports = downloadArtifacts
93
- module . exports . locations = { testYamlFolder, zipFile }
125
+ module . exports . locations = { testYamlFolder, zipFile, specFolder }
0 commit comments