Skip to content

Commit

Permalink
Merge pull request #272 from LambdaTest/dev
Browse files Browse the repository at this point in the history
Release 14 nov
  • Loading branch information
HRanjan-11 authored Nov 14, 2023
2 parents 529a723 + e1b3c08 commit 5f4f3b8
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 26 deletions.
2 changes: 2 additions & 0 deletions commands/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ module.exports = {
"&status=running,queued,created,initiated,pqueued,error,lambda error,failed,completed,queue_timeout,idle_timeout,stopped,cancelled,passed,timeout,inactive",
BUILD_ERROR_STATES: "&status=error,lambda error,failed",
CYPRESS_ENV_FILE_PATH: "cypress.env.json",
LT_USERNAME_ENV: "LT_USERNAME",
LT_ACCESS_KEY_ENV: "LT_ACCESS_KEY",
ENVS: ["stage", "beta", "prod", "preprod", "stage_new"],
prod: {
INTEGRATION_BASE_URL: "https://api.lambdatest.com/liis",
Expand Down
97 changes: 75 additions & 22 deletions commands/utils/set_args.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,58 @@ function write_file(file_path, content) {
function sync_args_from_cmd(args) {
return new Promise(function (resolve, reject) {
let rawdata = fs.readFileSync(args["lambdatest-config-file"]);
let lt_config = JSON.parse(rawdata);
let lt_config;
try {
lt_config = JSON.parse(rawdata);
} catch (err) {
reject("error in parsing lambdatest-config-file",err);
}
let usernameFromEnvFile = undefined;
let accessKeyFromEnvFile = undefined;
let envFile,parsedEnv;
let dot_env_vars = undefined;
let dot_env_keys_list = undefined;
let envFilePath = path.join(".", `.env`);
if ("sys-env-keys" in args) {
dot_env_vars = args["sys-env-keys"];
} else if (lt_config["run_settings"] && lt_config["run_settings"]["sys_env_keys"]) {
dot_env_vars = lt_config["run_settings"]["sys_env_keys"];
}
if (dot_env_vars) {
dot_env_vars = dot_env_vars.trim();
dot_env_keys_list = dot_env_vars.split(",");
if ("envfl" in args) {
envFilePath = args["envfl"];
} else if (lt_config["run_settings"] && lt_config["run_settings"]["env_file"]) {
envFilePath = lt_config["run_settings"]["env_file"];
}

try {
envFile = fs.readFileSync(envFilePath, {encoding: 'utf8'})
parsedEnv = dotenv.parse(envFile)
for (index in dot_env_keys_list) {
let envKey = dot_env_keys_list[index]
if (envKey==constants.LT_USERNAME_ENV){
let envValue = parsedEnv[envKey]
if (envValue){
usernameFromEnvFile = envValue
} else {
console.error(`value of username is not set in .env file.`)
}

} else if (envKey==constants.LT_ACCESS_KEY_ENV){
let envValue = parsedEnv[envKey]
if (envValue){
accessKeyFromEnvFile = envValue
} else {
console.error(`value of access key is not set in .env file.`)
}
}
}
} catch (err) {
console.error("error in fetching environment variables from .env file",err);
}
}

if (
"lambdatest_auth" in lt_config &&
Expand All @@ -31,6 +82,17 @@ function sync_args_from_cmd(args) {
);
lt_config["lambdatest_auth"]["username"] = process.env.LT_USERNAME;
}
} else if ( usernameFromEnvFile &&
(!("lambdatest_auth" in lt_config) ||
!("username" in lt_config["lambdatest_auth"]))) {
console.log(
"Setting user name from .env file",
usernameFromEnvFile
);
if (!lt_config["lambdatest_auth"]) {
lt_config["lambdatest_auth"] = {};
}
lt_config["lambdatest_auth"]["username"] = usernameFromEnvFile;
} else if (
process.env.LT_USERNAME &&
(!("lambdatest_auth" in lt_config) ||
Expand Down Expand Up @@ -58,6 +120,14 @@ function sync_args_from_cmd(args) {
console.log("setting access key from environment");
lt_config["lambdatest_auth"]["access_key"] = process.env.LT_ACCESS_KEY;
}
} else if (accessKeyFromEnvFile &&
(!("lambdatest_auth" in lt_config) ||
!("access_key" in lt_config["lambdatest_auth"]))) {
if (!lt_config["lambdatest_auth"]) {
lt_config["lambdatest_auth"] = {};
}
console.log("Setting access key from .env file");
lt_config["lambdatest_auth"]["access_key"] = accessKeyFromEnvFile;
} else if (
process.env.LT_ACCESS_KEY &&
(!("lambdatest_auth" in lt_config) ||
Expand Down Expand Up @@ -386,28 +456,11 @@ function sync_args_from_cmd(args) {
}
}
}
let dot_env_vars = undefined;
if ("sys-env-keys" in args) {
dot_env_vars = args["sys-env-keys"];
} else if (lt_config["run_settings"] && lt_config["run_settings"]["sys_env_keys"]) {
dot_env_vars = lt_config["run_settings"]["sys_env_keys"];
}
let parsedEnv,envFile;
let envFilePath = path.join(".", `.env`)
if (dot_env_vars) {
dot_env_vars = dot_env_vars.trim();
dot_env_vars = dot_env_vars.split(",");
if ("envfl" in args) {
envFilePath = args["envfl"];
} else if (lt_config["run_settings"]["env_file"]) {
envFilePath = lt_config["run_settings"]["env_file"];
}


if (dot_env_keys_list) {
try {
envFile = fs.readFileSync(envFilePath, {encoding: 'utf8'})
parsedEnv = dotenv.parse(envFile)
for (index in dot_env_vars) {
let envKey = dot_env_vars[index]
for (index in dot_env_keys_list) {
let envKey = dot_env_keys_list[index]
let envValue = parsedEnv[envKey]
envs[envKey] = envValue
}
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const argv = require("yargs")
type: "string",
})
.option("envfl", {
alias: "env_file",
alias: "env-file",
describe: "path of .env file",
type: "string",
})
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lambdatest-cypress-cli",
"version": "3.0.19",
"version": "3.0.20",
"description": "The lambdatest-cypress-cli is LambdaTest's command-line interface (CLI) aimed to help you run your Cypress tests on LambdaTest platform.",
"homepage": "https://github.com/LambdaTest/lambdatest-cypress-cli",
"author": "LambdaTest <[email protected]>",
Expand Down

0 comments on commit 5f4f3b8

Please sign in to comment.