Skip to content

Commit

Permalink
Sync run_in_in_ci.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sfodagain committed Jun 5, 2024
1 parent bc27500 commit 0506505
Showing 1 changed file with 95 additions and 86 deletions.
181 changes: 95 additions & 86 deletions utils/run_in_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def setup_json_arguments_list(file, input_uuid=None):

for argument in config_json['arguments']:
# Add the name of the argument
config_json_arguments_list.append(argument['name'])
if( 'name' in argument):
config_json_arguments_list.append(argument['name'])

# Based on the data present, we need to process and add the data differently
try:
Expand Down Expand Up @@ -227,7 +228,8 @@ def cleanup_runnable():
global config_json_arguments_list

for argument in config_json['arguments']:
config_json_arguments_list.append(argument['name'])
if( 'name' in argument):
config_json_arguments_list.append(argument['name'])

# Based on the data present, we need to process and add the data differently
try:
Expand Down Expand Up @@ -270,96 +272,103 @@ def launch_runnable(runnable_dir):

exit_code = 0

runnable_timeout = None
if ('timeout' in config_json):
runnable_timeout = config_json['timeout']

print("Launching runnable...")

# Java
if (config_json['language'] == "Java"):
# Flatten arguments down into a single string
arguments_as_string = ""
for i in range(0, len(config_json_arguments_list)):
arguments_as_string += str(config_json_arguments_list[i])
if (i+1 < len(config_json_arguments_list)):
arguments_as_string += " "

arguments = ["mvn", "compile", "exec:java"]
arguments.append("-pl")
arguments.append(config_json['runnable_file'])
arguments.append("-Dexec.mainClass=" + config_json['runnable_main_class'])
arguments.append("-Daws.crt.ci=True")

# We have to do this as a string, unfortunately, due to how -Dexec.args= works...
argument_string = subprocess.list2cmdline(arguments) + " -Dexec.args=\"" + arguments_as_string + "\""
print(f"Running cmd: {argument_string}")
runnable_return = subprocess.run(argument_string, input=subprocess_stdin, shell=True)
exit_code = runnable_return.returncode

elif (config_json['language'] == "Java JAR"):
# Flatten arguments down into a single string
arguments_as_string = ""
for i in range(0, len(config_json_arguments_list)):
arguments_as_string += str(config_json_arguments_list[i])
if (i+1 < len(config_json_arguments_list)):
arguments_as_string += " "

runnable_file = os.path.join(runnable_dir, config_json['runnable_file'])

arguments = ["java"]
arguments.append("-Daws.crt.ci=True")
arguments.append("-jar")
arguments.append(runnable_file)

argument_string = subprocess.list2cmdline(arguments) + " " + arguments_as_string
print(f"Running cmd: {argument_string}")
runnable_return = subprocess.run(argument_string, input=subprocess_stdin, shell=True)
exit_code = runnable_return.returncode

# C++
elif (config_json['language'] == "CPP"):
runnable_file = os.path.join(runnable_dir, config_json['runnable_file'])
runnable_return = subprocess.run(args=config_json_arguments_list, input=subprocess_stdin, executable=runnable_file)
exit_code = runnable_return.returncode

elif (config_json['language'] == "Python"):
config_json_arguments_list.append("--is_ci")
config_json_arguments_list.append("True")

runnable_return = subprocess.run(
args=[sys.executable, config_json['runnable_file']] + config_json_arguments_list, input=subprocess_stdin)
exit_code = runnable_return.returncode

elif (config_json['language'] == "Javascript"):
os.chdir(config_json['runnable_file'])

config_json_arguments_list.append("--is_ci")
config_json_arguments_list.append("true")

runnable_return_one = None
if sys.platform == "win32" or sys.platform == "cygwin":
runnable_return_one = subprocess.run(args=["npm", "install"], shell=True)
else:
runnable_return_one = subprocess.run(args=["npm", "install"])
try:
# Java
if (config_json['language'] == "Java"):
# Flatten arguments down into a single string
arguments_as_string = ""
for i in range(0, len(config_json_arguments_list)):
arguments_as_string += str(config_json_arguments_list[i])
if (i+1 < len(config_json_arguments_list)):
arguments_as_string += " "

arguments = ["mvn", "compile", "exec:java"]
arguments.append("-pl")
arguments.append(config_json['runnable_file'])
arguments.append("-Dexec.mainClass=" + config_json['runnable_main_class'])
arguments.append("-Daws.crt.ci=True")

# We have to do this as a string, unfortunately, due to how -Dexec.args= works...
argument_string = subprocess.list2cmdline(arguments) + " -Dexec.args=\"" + arguments_as_string + "\""
print(f"Running cmd: {argument_string}")
runnable_return = subprocess.run(argument_string, input=subprocess_stdin, timeout=runnable_timeout, shell=True)
exit_code = runnable_return.returncode

elif (config_json['language'] == "Java JAR"):
# Flatten arguments down into a single string
arguments_as_string = ""
for i in range(0, len(config_json_arguments_list)):
arguments_as_string += str(config_json_arguments_list[i])
if (i+1 < len(config_json_arguments_list)):
arguments_as_string += " "

runnable_file = os.path.join(runnable_dir, config_json['runnable_file'])

arguments = ["java"]
arguments.append("-Daws.crt.ci=True")
arguments.append("-jar")
arguments.append(runnable_file)

argument_string = subprocess.list2cmdline(arguments) + " " + arguments_as_string
print(f"Running cmd: {argument_string}")
runnable_return = subprocess.run(argument_string, input=subprocess_stdin, timeout=runnable_timeout, shell=True)
exit_code = runnable_return.returncode

# C++
elif (config_json['language'] == "CPP"):
runnable_file = os.path.join(runnable_dir, config_json['runnable_file'])
runnable_return = subprocess.run(args=config_json_arguments_list, input=subprocess_stdin, timeout=runnable_timeout, executable=runnable_file)
exit_code = runnable_return.returncode

elif (config_json['language'] == "Python"):
runnable_file = os.path.join(runnable_dir, config_json['runnable_file'])
runnable_return = subprocess.run(
args=[sys.executable, runnable_file] + config_json_arguments_list, input=subprocess_stdin, timeout=runnable_timeout)
exit_code = runnable_return.returncode

elif (config_json['language'] == "Javascript"):
os.chdir(config_json['runnable_file'])

config_json_arguments_list.append("--is_ci")
config_json_arguments_list.append("true")

runnable_return_one = None
if not 'skip_install' in config_json:
if sys.platform == "win32" or sys.platform == "cygwin":
runnable_return_one = subprocess.run(args=["npm", "install"], shell=True, timeout=runnable_timeout)
else:
runnable_return_one = subprocess.run(args=["npm", "install"], timeout=runnable_timeout)

if (runnable_return_one == None or runnable_return_one.returncode != 0):
exit_code = runnable_return_one.returncode
else:
runnable_return_two = None
arguments = []
if 'node_cmd' in config_json:
arguments = config_json['node_cmd'].split(" ")
if not 'skip_install' in config_json and (runnable_return_one == None or runnable_return_one.returncode != 0):
exit_code = runnable_return_one.returncode
else:
arguments = ["node", "dist/index.js"]
runnable_return_two = None
arguments = []
if 'node_cmd' in config_json:
arguments = config_json['node_cmd'].split(" ")
else:
arguments = ["node", "dist/index.js"]

if sys.platform == "win32" or sys.platform == "cygwin":
runnable_return_two = subprocess.run(
args=arguments + config_json_arguments_list, shell=True)
else:
runnable_return_two = subprocess.run(
args=arguments + config_json_arguments_list, input=subprocess_stdin)
if sys.platform == "win32" or sys.platform == "cygwin":
runnable_return_two = subprocess.run(
args=arguments + config_json_arguments_list, shell=True, check=True, timeout=runnable_timeout)
else:
runnable_return_two = subprocess.run(
args=arguments + config_json_arguments_list, input=subprocess_stdin, timeout=runnable_timeout)

if (runnable_return_two != None):
exit_code = runnable_return_two.returncode
else:
exit_code = 1
if (runnable_return_two != None):
exit_code = runnable_return_two.returncode
else:
exit_code = 1
except subprocess.CalledProcessError as e:
print(e.output)
exit_code = 1

cleanup_runnable()
return exit_code
Expand Down

0 comments on commit 0506505

Please sign in to comment.