CircleCI-Public / android-orb

An orb for working with Android on CircleCI
https://circleci.com/developer/orbs/orb/circleci/android
MIT License
41 stars 25 forks source link

Passing environment variables to `start-emulator-and-run-tests` arguments causes job to fail as of 2.1.1 #56

Open growse opened 1 year ago

growse commented 1 year ago

Orb version 2.1.1

What happened

Orb can no longer accept step arguments that are environment variables.

I have a step that looks like this:

run-andoid-emulator-and-tests:
    steps:
      - android/start-emulator-and-run-tests:
          additional-avd-args: "-d pixel_3a -c 1G"
          additional-emulator-args: "-memory 4096 -cores 3"
          test-command: $GRADLE_TEST_COMMAND
          system-image: $SYSTEM_IMAGE

This works great on 2.1.0. On 2.1.1 however, it fails at "Create avd 'test'":

#!/bin/bash -eo pipefail
#!/bin/bash
echo "no" | avdmanager --verbose create avd -n ${PARAM_AVD_NAME} -k ${PARAM_SYSTEM_IMAGE} ${PARAM_ADDITIONAL_ARGS}

Error: Package path is not valid. Valid system image paths are:ository...       
system-images;android-29;default;x86_64
null

Exited with code exit status 1

CircleCI received exit code 1

(See https://app.circleci.com/pipelines/github/owntracks/android/1025/workflows/7844a0b9-deec-447a-838e-99d67c476e2a/jobs/4071)

If I replace system-image: $SYSTEM_IMAGE with a hard-coded value, the create AVD stage works, but then the "Run tests with max tries of 2" step fails with:

#!/bin/bash -eo pipefail
#!/bin/bash
run_with_retry() {
            MAX_TRIES=${PARAM_MAX_TRIES}
            n=1
            until [ $n -gt $MAX_TRIES ]
            do
              echo "Starting test attempt $n"
              ${PARAM_TEST_COMMAND} && break
              n=$((n+1))
              sleep "${PARAM_RETRY_INTERVAL}"
            done
            if [ $n -gt $MAX_TRIES ]; then
              echo "Max tries reached (${PARAM_MAX_TRIES})"
              exit 1
            fi
        }
        run_with_retry

Starting test attempt 1
environment: line 7: ${GRADLE_TEST_COMMAND}: command not found
Starting test attempt 2
environment: line 7: ${GRADLE_TEST_COMMAND}: command not found
Max tries reached (2)

Exited with code exit status 1

CircleCI received exit code 1

(See https://app.circleci.com/pipelines/github/owntracks/android/1022/workflows/502e1a7a-d62e-43d8-9110-c3dfb6c649ee/jobs/4062)

Expected behavior

Environemnt var values should be passed through to the orb correctly, as they were in 2.1.0

ryanbourdais commented 1 year ago

Hi @growse are you still receiving this issue?

growse commented 1 year ago

Yep. See https://app.circleci.com/pipelines/github/owntracks/android/1558/workflows/1a5c499c-e269-4cbc-9e01-5948cd82691c/jobs/5474

ryanbourdais commented 1 year ago

Hi @growse, I've spent some time looking into this over the last few days, and it looks like using this command with environment variables is not currently possible with the state of the orb. Changing it to allow for this usage would require the step to be rewritten and remove other features that have been added to this command, such as running in background. As a result, I am going to backlog this issue for now and keep an eye on it to see how the orb changes in the coming months and revisit it periodically.

luzfcb commented 9 months ago

@ryanbourdais, any update on this? Circle-ci does not provide a way to invalidate the cache other than simply renaming the cache key, because of that, I need an easy way without changing the code of the application to invalidate the cache used by restore-gradle-cache-prefix and defines the API version of the android system-image

      - android/start-emulator-and-run-tests:
          restore-gradle-cache-prefix: ${ANDROID_LARGE_CACHE_VERSION}-android-${ANDROID_LARGE_API_VERSION}-large
          system-image: system-images;android-${ANDROID_LARGE_API_VERSION};google_apis;x86_64
          additional-avd-args: --device pixel_5
          avd-name: pixel5_api_31
ryanbourdais commented 9 months ago

Hi @luzfcb, no there is no update on this currently.