Skip to content

Commit

Permalink
Merge pull request #204 from caarmen/improve-ci-tests
Browse files Browse the repository at this point in the history
Improve ci tests
  • Loading branch information
caarmen authored Oct 19, 2024
2 parents f2fd742 + 7cbda06 commit 2631109
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,11 @@ jobs:
with:
name: logcat
path: /tmp/lolcat.log
- name: Archive apks
if: always()
uses: actions/upload-artifact@v4
with:
name: apks
path: |
./app/build/outputs/apk/debug/app-debug.apk
./app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk
31 changes: 16 additions & 15 deletions scripts/gmsaas-run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
)
parser = argparse.ArgumentParser()
parser.add_argument("recipe_uuid", type=str)
parser.add_argument("instance_name", type=str)
args = parser.parse_args()
recipe_uuid = args.recipe_uuid


def run_gmsaas_command(command: str) -> dict:
Expand All @@ -23,15 +23,6 @@ def run_gmsaas_command(command: str) -> dict:
)


def gmsaas_stop_all_instances():
logger.info("Stop all instances.")
instances_list_output = run_gmsaas_command("instances list")

for instance in instances_list_output["instances"]:
run_gmsaas_command(f"instances stop {instance["uuid"]}")
logger.info(f"Stopped {instance["uuid"]} ({instance["name"]})")


def gmsaas_authenticate():
logger.info("Authenticate.")
auth_token_output = run_gmsaas_command(
Expand All @@ -55,16 +46,24 @@ def gmsaas_config():
logger.info(f"Configuration now {config_set_output["configuration"]}")


def gmsaas_start_instance() -> str:
def gmsaas_start_instance(
recipe_uuid: str,
instance_name: str,
) -> str:
logger.info("Start new instance.")
instances_start_output = run_gmsaas_command(
f"instances start {recipe_uuid} poet-assistant-tests"
f"instances start --max-run-duration 30 {recipe_uuid} '{instance_name}'"
)
instance_uuid = instances_start_output["instance"]["uuid"]
logger.info(f"Started instance {instance_uuid}.")
return instance_uuid


def gmsaas_stop_instance(instance_uuid: str):
logger.info(f"Stop instance {instance_uuid}.")
run_gmsaas_command(f"instances stop {instance_uuid}")


def gmsaas_connect_adb(instance_uuid: str):
logger.info("Connect to adb.")
instances_adbconnect_output = run_gmsaas_command(
Expand Down Expand Up @@ -114,8 +113,10 @@ def gradle_run_tests() -> int:
# Setup the device.
gmsaas_authenticate()
gmsaas_config()
gmsaas_stop_all_instances()
instance_uuid = gmsaas_start_instance()
instance_uuid = gmsaas_start_instance(
recipe_uuid=args.recipe_uuid,
instance_name=args.instance_name,
)
gmsaas_connect_adb(instance_uuid)

# Run the tests.
Expand All @@ -124,7 +125,7 @@ def gradle_run_tests() -> int:
tests_return_code = gradle_run_tests()

# Cleanup.
gmsaas_stop_all_instances()
gmsaas_stop_instance(instance_uuid)
gmsaas_logout()

exit(code=tests_return_code)
3 changes: 2 additions & 1 deletion scripts/run_tests.bash
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pip install gmsaas==1.12.0
python ./scripts/gmsaas-run-tests.py ${GMSAAS_RECIPE_UUID}
instance_name="poet-assistant-tests [${GITHUB_REF_NAME}-${GITHUB_SHA}] [${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}]"
python ./scripts/gmsaas-run-tests.py ${GMSAAS_RECIPE_UUID} "${instance_name}"

0 comments on commit 2631109

Please sign in to comment.