Skip to content

Commit bd1a155

Browse files
authored
Merge pull request #170 from LambdaTest/MLE-10664
support for setup of sys env on machine
2 parents d7ceacc + 55cdf8f commit bd1a155

File tree

5 files changed

+52
-1
lines changed

5 files changed

+52
-1
lines changed

commands/utils/batch/batch_runner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ async function run(lt_config, batches, env, i = 0) {
182182
});
183183
})
184184
.catch(function (err) {
185-
console.log("No able to archive the project");
185+
console.log("Unable to archive the project");
186186
console.log(err);
187187
reject(err);
188188
});

commands/utils/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = {
99
DEFAULT_TEST_PATH: ".",
1010
LAMBDA_CONFIG: "./lambdatest-config.json",
1111
SUPPORTED_CYPRESS_VERSIONS: ["5", "6"],
12+
WHITELISTED_ENV_VARS: ["CI_BUILD_ID"],
1213
BUILD_END_STATES:
1314
"&status=running,queued,created,initiated,pqueued,error,lambda error,failed",
1415
BUILD_ERROR_STATES: "&status=error,lambda error,failed",

commands/utils/set_args.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const constants = require("./constants.js");
22
const fs = require("fs");
33
const path = require("path");
44
const process = require("process");
5+
const { type } = require("os");
56

67
function write_file(file_path, content) {
78
fs.writeFileSync(file_path, content, function (err) {
@@ -322,6 +323,33 @@ function sync_args_from_cmd(args) {
322323
} else {
323324
lt_config["run_settings"]["reject_unauthorized"] = false;
324325
}
326+
327+
//Set the env variables
328+
let sys_env_vars = undefined;
329+
let envs = {};
330+
if ("sys-envs" in args) {
331+
sys_env_vars = args["sys-envs"];
332+
} else if (lt_config["run_settings"]["sys_envs"]) {
333+
sys_env_vars = lt_config["run_settings"]["sys_envs"];
334+
}
335+
336+
if (sys_env_vars){
337+
sys_env_vars = sys_env_vars.trim();
338+
sys_env_vars = sys_env_vars.split(";");
339+
340+
for (index in sys_env_vars) {
341+
envItem = sys_env_vars[index];
342+
if (envItem){
343+
envKeyValue = envItem.split("=");
344+
envKey = envKeyValue[0];
345+
envValue = envKeyValue[1];
346+
envs[envKey] = envValue;
347+
}
348+
}
349+
}
350+
lt_config["run_settings"]["sys_envs"] = envs;
351+
352+
325353
//get specs from current directory if specs are not passed in config or cli
326354
if (
327355
(lt_config["run_settings"]["specs"] == undefined ||

commands/utils/validate.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const fs = require("fs");
22
const constants = require("./constants.js");
33
module.exports = validate_config = function (lt_config, validation_configs) {
4+
console.log("validating config");
45
return new Promise(function (resolve, reject) {
56
//validate auth keys are present
67
if (
@@ -319,6 +320,22 @@ module.exports = validate_config = function (lt_config, validation_configs) {
319320
reject("Error!! boolean value is expected in reject_unauthorized key");
320321
}
321322
}
323+
324+
// validate system env variables to be set up
325+
if ("sys_envs" in lt_config["run_settings"]) {
326+
let sys_envs = lt_config["run_settings"]["sys_envs"];
327+
let envValue;
328+
Object.keys(sys_envs).forEach(function(envKey) {
329+
envValue = sys_envs[envKey];
330+
if (envKey && ! constants.WHITELISTED_ENV_VARS.includes(envKey)){
331+
reject(`Usage of unwanted environment variable detected. Allowed variables are - ${constants.WHITELISTED_ENV_VARS}`);
332+
}
333+
if (envValue == undefined || envValue === ""){
334+
reject("Value of environment variable cannot be left blank");
335+
}
336+
})
337+
338+
}
322339
resolve("Validated the Config");
323340
});
324341
};

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ const argv = require("yargs")
127127
alias: "build-tags",
128128
describe: "build tags",
129129
type: "string",
130+
})
131+
.option("sys-envs", {
132+
alias: "sys-env-variables",
133+
describe: "system environment variables",
134+
type: "string",
130135
});
131136
},
132137
function (argv) {

0 commit comments

Comments
 (0)