Skip to content

Commit 40496ea

Browse files
committed
add: timestamp suffix to binary log files to differentiate between steps
1 parent 9fe509d commit 40496ea

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

setup-local/config/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports = {
1515
ENV_VARS: {
1616
BROWSERSTACK_ACCESS_KEY: 'BROWSERSTACK_ACCESS_KEY',
1717
BROWSERSTACK_LOCAL_IDENTIFIER: 'BROWSERSTACK_LOCAL_IDENTIFIER',
18+
BROWSERSTACK_LOCAL_LOGS_FILE: 'BROWSERSTACK_LOCAL_LOGS_FILE',
1819
},
1920

2021
BINARY_LINKS: {

setup-local/src/binaryControl.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const github = require('@actions/github');
66
const os = require('os');
77
const path = require('path');
88
const fs = require('fs');
9+
const Utils = require('./utils');
910
const ArtifactsManager = require('./artifacts');
1011
const constants = require('../config/constants');
1112

@@ -19,6 +20,9 @@ const {
1920
ALLOWED_INPUT_VALUES: {
2021
LOCAL_TESTING,
2122
},
23+
ENV_VARS: {
24+
BROWSERSTACK_LOCAL_LOGS_FILE,
25+
},
2226
} = constants;
2327

2428
/**
@@ -61,8 +65,9 @@ class BinaryControl {
6165
* Generates logging file name and its path for Local Binary
6266
*/
6367
_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`;
6569
this.logFilePath = path.resolve(this.binaryFolder, this.logFileName);
70+
core.exportVariable(BROWSERSTACK_LOCAL_LOGS_FILE, this.logFileName);
6671
}
6772

6873
/**
@@ -131,23 +136,16 @@ class BinaryControl {
131136
};
132137
}
133138

134-
_binaryExists() {
135-
const localBinary = tc.findAllVersions(LOCAL_BINARY_NAME);
136-
return localBinary.length ? true : false;
137-
}
138-
139139
/**
140140
* Downloads the Local Binary, extracts it and adds it in the PATH variable
141141
*/
142142
async downloadBinary() {
143143
try {
144-
if (this._binaryExists()) {
145-
console.log(core.getState('jinga'));
144+
if (Utils.checkToolInCache(LOCAL_BINARY_NAME)) {
146145
core.info('BrowserStackLocal binary already exists in cache. Using that instead of downloading again...');
147146
return;
148147
}
149148
await this._makeDirectory();
150-
core.saveState('jinga', 'lala');
151149
core.info('Downloading BrowserStackLocal binary...');
152150
const downloadPath = await tc.downloadTool(this.binaryLink, path.resolve(this.binaryFolder, 'binaryZip'));
153151
const extractedPath = await tc.extractZip(downloadPath, this.binaryFolder);
@@ -218,7 +216,6 @@ class BinaryControl {
218216
* Uploads BrowserStackLocal generated logs (if the file exists for the job)
219217
*/
220218
async uploadLogFilesIfAny() {
221-
core.saveState
222219
this._generateLogFileMetadata();
223220
if (fs.existsSync(this.logFilePath)) {
224221
await ArtifactsManager.uploadArtifacts(
@@ -228,6 +225,7 @@ class BinaryControl {
228225
);
229226
await io.rmRF(this.logFilePath);
230227
}
228+
Utils.clearEnvironmentVariable(BROWSERSTACK_LOCAL_LOGS_FILE);
231229
}
232230
}
233231

setup-local/src/utils/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const tc = require('@actions/tool-cache');
2+
3+
class Utils {
4+
static clearEnvironmentVariable(environmentVariable) {
5+
delete process.env[environmentVariable];
6+
}
7+
8+
static checkToolInCache(toolName) {
9+
const toolCache = tc.findAllVersions(toolName);
10+
return toolCache.length !== 0;
11+
}
12+
}
13+
14+
module.exports = Utils;

0 commit comments

Comments
 (0)