@@ -6,6 +6,7 @@ const github = require('@actions/github');
6
6
const os = require ( 'os' ) ;
7
7
const path = require ( 'path' ) ;
8
8
const fs = require ( 'fs' ) ;
9
+ const Utils = require ( './utils' ) ;
9
10
const ArtifactsManager = require ( './artifacts' ) ;
10
11
const constants = require ( '../config/constants' ) ;
11
12
@@ -19,6 +20,9 @@ const {
19
20
ALLOWED_INPUT_VALUES : {
20
21
LOCAL_TESTING ,
21
22
} ,
23
+ ENV_VARS : {
24
+ BROWSERSTACK_LOCAL_LOGS_FILE ,
25
+ } ,
22
26
} = constants ;
23
27
24
28
/**
@@ -61,8 +65,9 @@ class BinaryControl {
61
65
* Generates logging file name and its path for Local Binary
62
66
*/
63
67
_generateLogFileMetadata ( ) {
64
- this . logFileName = `${ LOCAL_LOG_FILE_PREFIX } _${ github . context . job } .log` ;
68
+ this . logFileName = process . env [ BROWSERSTACK_LOCAL_LOGS_FILE ] || `${ LOCAL_LOG_FILE_PREFIX } _${ github . context . job } _ ${ new Date ( ) . toISOString ( ) } .log` ;
65
69
this . logFilePath = path . resolve ( this . binaryFolder , this . logFileName ) ;
70
+ core . exportVariable ( BROWSERSTACK_LOCAL_LOGS_FILE , this . logFileName ) ;
66
71
}
67
72
68
73
/**
@@ -131,23 +136,16 @@ class BinaryControl {
131
136
} ;
132
137
}
133
138
134
- _binaryExists ( ) {
135
- const localBinary = tc . findAllVersions ( LOCAL_BINARY_NAME ) ;
136
- return localBinary . length ? true : false ;
137
- }
138
-
139
139
/**
140
140
* Downloads the Local Binary, extracts it and adds it in the PATH variable
141
141
*/
142
142
async downloadBinary ( ) {
143
143
try {
144
- if ( this . _binaryExists ( ) ) {
145
- console . log ( core . getState ( 'jinga' ) ) ;
144
+ if ( Utils . checkToolInCache ( LOCAL_BINARY_NAME ) ) {
146
145
core . info ( 'BrowserStackLocal binary already exists in cache. Using that instead of downloading again...' ) ;
147
146
return ;
148
147
}
149
148
await this . _makeDirectory ( ) ;
150
- core . saveState ( 'jinga' , 'lala' ) ;
151
149
core . info ( 'Downloading BrowserStackLocal binary...' ) ;
152
150
const downloadPath = await tc . downloadTool ( this . binaryLink , path . resolve ( this . binaryFolder , 'binaryZip' ) ) ;
153
151
const extractedPath = await tc . extractZip ( downloadPath , this . binaryFolder ) ;
@@ -218,7 +216,6 @@ class BinaryControl {
218
216
* Uploads BrowserStackLocal generated logs (if the file exists for the job)
219
217
*/
220
218
async uploadLogFilesIfAny ( ) {
221
- core . saveState
222
219
this . _generateLogFileMetadata ( ) ;
223
220
if ( fs . existsSync ( this . logFilePath ) ) {
224
221
await ArtifactsManager . uploadArtifacts (
@@ -228,6 +225,7 @@ class BinaryControl {
228
225
) ;
229
226
await io . rmRF ( this . logFilePath ) ;
230
227
}
228
+ Utils . clearEnvironmentVariable ( BROWSERSTACK_LOCAL_LOGS_FILE ) ;
231
229
}
232
230
}
233
231
0 commit comments