@@ -26,7 +26,7 @@ const fetch = require('node-fetch')
26
26
const crossZip = require ( 'cross-zip' )
27
27
const ora = require ( 'ora' )
28
28
29
- const { mkdir } = promises
29
+ const { mkdir, cp } = promises
30
30
const pipeline = promisify ( stream . pipeline )
31
31
const unzip = promisify ( crossZip . unzip )
32
32
@@ -35,7 +35,7 @@ const zipFile = join(__dirname, '..', 'serverless-clients-tests.zip')
35
35
36
36
const specFolder = join ( __dirname , '..' , 'rest-api-spec' )
37
37
38
- async function downloadArtifacts ( ) {
38
+ async function downloadArtifacts ( localTests ) {
39
39
const log = ora ( 'Checking out spec and test' ) . start ( )
40
40
41
41
const { GITHUB_TOKEN } = process . env
@@ -46,31 +46,36 @@ async function downloadArtifacts () {
46
46
47
47
log . text = 'Fetching test YAML files'
48
48
49
- if ( ! GITHUB_TOKEN ) {
50
- log . fail ( "Missing required environment variable 'GITHUB_TOKEN'" )
51
- process . exit ( 1 )
52
- }
53
-
54
- let response = await fetch ( 'https://api.github.com/repos/elastic/serverless-clients-tests/zipball/main' , {
55
- headers : {
56
- Authorization : `Bearer ${ GITHUB_TOKEN } ` ,
57
- Accept : "application/vnd.github+json" ,
49
+ if ( localTests ) {
50
+ log . text = `Copying local tests from ${ localTests } `
51
+ await cp ( localTests , testYamlFolder , { recursive : true } )
52
+ } else {
53
+ if ( ! GITHUB_TOKEN ) {
54
+ log . fail ( "Missing required environment variable 'GITHUB_TOKEN'" )
55
+ process . exit ( 1 )
58
56
}
59
- } )
60
57
61
- if ( ! response . ok ) {
62
- log . fail ( `unexpected response ${ response . statusText } ` )
63
- process . exit ( 1 )
64
- }
58
+ let response = await fetch ( 'https://api.github.com/repos/elastic/serverless-clients-tests/zipball/main' , {
59
+ headers : {
60
+ Authorization : `Bearer ${ GITHUB_TOKEN } ` ,
61
+ Accept : "application/vnd.github+json" ,
62
+ }
63
+ } )
65
64
66
- log . text = 'Downloading tests zipball'
67
- await pipeline ( response . body , createWriteStream ( zipFile ) )
65
+ if ( ! response . ok ) {
66
+ log . fail ( `unexpected response ${ response . statusText } ` )
67
+ process . exit ( 1 )
68
+ }
68
69
69
- log . text = 'Unzipping tests'
70
- await unzip ( zipFile , testYamlFolder )
70
+ log . text = 'Downloading tests zipball '
71
+ await pipeline ( response . body , createWriteStream ( zipFile ) )
71
72
72
- log . text = 'Cleanup'
73
- await rimraf ( zipFile )
73
+ log . text = 'Unzipping tests'
74
+ await unzip ( zipFile , testYamlFolder )
75
+
76
+ log . text = 'Cleanup'
77
+ await rimraf ( zipFile )
78
+ }
74
79
75
80
log . text = 'Fetching Elasticsearch spec info'
76
81
await rimraf ( specFolder )
0 commit comments