Skip to content

Commit

Permalink
extracted method for shell exec on service
Browse files Browse the repository at this point in the history
Signed-off-by: nidhi-singh02 <[email protected]>
  • Loading branch information
nidhi-singh02 committed Sep 30, 2024
1 parent e07c670 commit f7246c7
Showing 1 changed file with 18 additions and 28 deletions.
46 changes: 18 additions & 28 deletions testing/hardhat-deployment/main.star
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
SOURCE_DIR_PATH = "/app/contracts"
IMAGE_NODE = "node:current-alpine3.20"
DEPENDENCY_DIR_PATH = "/app/dependency"
LOCAL_DEPENDENCY = "local"
GIT_DEPENDENCY = "git"

def run(plan, deployment = {}):
repository = deployment["repository"]
Expand All @@ -16,9 +18,9 @@ def run(plan, deployment = {}):

wallet_value = wallet["value"]

folder = plan.upload_files(src = repository, name = "contracts")
plan.upload_files(src = repository, name = "contracts")

if dependency_type == "local" or dependency_type == "git":
if dependency_type == LOCAL_DEPENDENCY or dependency_type == GIT_DEPENDENCY:
dependency_path = dependency["path"]
plan.upload_files(src = "dependency", name = "dependency")
dependency_artifact_name = "dependency"
Expand All @@ -33,37 +35,17 @@ def run(plan, deployment = {}):
else:
contract_path = SOURCE_DIR_PATH

if dependency_type == "local":
plan.exec(
service_name = node_service.name,
recipe = ExecRecipe(
command = ["/bin/sh", "-c", "sh {}/{}".format(DEPENDENCY_DIR_PATH, dependency_path)],
),
)
elif dependency_type == "git":
plan.exec(
service_name = node_service.name,
recipe = ExecRecipe(
command = ["/bin/sh", "-c", "cd {} && sh {}".format(contract_path, dependency_path)],
),
)
if dependency_type == LOCAL_DEPENDENCY:
exec_on_service(plan, node_service.name, "sh {}/{}".format(DEPENDENCY_DIR_PATH, dependency_path))
elif dependency_type == GIT_DEPENDENCY:
exec_on_service(plan, node_service.name, "cd {} && sh {}".format(contract_path, dependency_path))

# Compile the contracts
result = plan.exec(
service_name = node_service.name,
recipe = ExecRecipe(
command = ["/bin/sh", "-c", "cd {} && npx hardhat compile --network {}".format(contract_path, network)],
),
)
result = exec_on_service(plan, node_service.name, "cd {} && npx hardhat compile --network {}".format(contract_path, network))
plan.verify(result["code"], "==", 0)

# Deploy the contracts
result = plan.exec(
service_name = node_service.name,
recipe = ExecRecipe(
command = ["/bin/sh", "-c", "cd {} && npx hardhat run {}".format(contract_path, script_path)],
),
)
result = exec_on_service(plan, node_service.name, "cd {} && npx hardhat run {}".format(contract_path, script_path))
plan.verify(result["code"], "==", 0)

def get_service_config(wallet, dependency_artifact_name):
Expand All @@ -81,3 +63,11 @@ def get_service_config(wallet, dependency_artifact_name):
"WALLET_KEY": wallet,
},
)

def exec_on_service(plan, service_name, command):
return plan.exec(
service_name = service_name,
recipe = ExecRecipe(
command = ["/bin/sh", "-c", command],
),
)

0 comments on commit f7246c7

Please sign in to comment.