From 52d92637db256f928fe2dd96fe25661de7a09891 Mon Sep 17 00:00:00 2001 From: LaszloP <7979773+lpusok@users.noreply.github.com> Date: Thu, 30 Oct 2025 12:49:04 +0100 Subject: [PATCH 1/7] Use set java version step --- e2e/bitrise.yml | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/e2e/bitrise.yml b/e2e/bitrise.yml index eecdc43..5bd1a2c 100644 --- a/e2e/bitrise.yml +++ b/e2e/bitrise.yml @@ -12,6 +12,16 @@ workflows: - _run - _check_outputs + # test_two_steps_in_workflow: + # envs: + # - TEST_APP_URL: https://github.com/bitrise-io/android-multiple-test-results-sample.git + # - TEST_APP_BRANCH: maintenance + # - TEST_APP_MODULE: app + # - TEST_APP_VARIANT: DemoDebug + # after_run: + # - _run + # - _check_outputs + test_library_module: envs: - TEST_APP_URL: https://github.com/bitrise-io/Bitrise-Android-Modules-Sample.git @@ -25,23 +35,11 @@ workflows: _run: steps: - - script: + - set-java-version@1: run_if: $.IsCI inputs: - - content: |- - #!/usr/bin/env bash - set -ex - if [[ "$OSTYPE" == "linux-gnu"* ]]; then - sudo update-alternatives --set javac /usr/lib/jvm/java-11-openjdk-amd64/bin/javac - sudo update-alternatives --set java /usr/lib/jvm/java-11-openjdk-amd64/bin/java - export JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64" - envman add --key JAVA_HOME --value "/usr/lib/jvm/java-11-openjdk-amd64" - elif [[ "$OSTYPE" == "darwin"* ]]; then - jenv global 11 || jenv global 11.0 - export JAVA_HOME="$(jenv prefix)" - envman add --key JAVA_HOME --value "$(jenv prefix)" - fi - - script: + - java_version: 11 + - script@1: inputs: - content: |- #!/bin/env bash From aeb1111ac761713a57dab08e6849cd6bb445509d Mon Sep 17 00:00:00 2001 From: LaszloP <7979773+lpusok@users.noreply.github.com> Date: Thu, 30 Oct 2025 13:11:12 +0100 Subject: [PATCH 2/7] Find artifact with timestamp --- e2e/bitrise.yml | 25 ++++++++++++++++--------- main.go | 11 ++++++++++- main_test.go | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 10 deletions(-) diff --git a/e2e/bitrise.yml b/e2e/bitrise.yml index 5bd1a2c..2361e33 100644 --- a/e2e/bitrise.yml +++ b/e2e/bitrise.yml @@ -12,15 +12,22 @@ workflows: - _run - _check_outputs - # test_two_steps_in_workflow: - # envs: - # - TEST_APP_URL: https://github.com/bitrise-io/android-multiple-test-results-sample.git - # - TEST_APP_BRANCH: maintenance - # - TEST_APP_MODULE: app - # - TEST_APP_VARIANT: DemoDebug - # after_run: - # - _run - # - _check_outputs + test_two_steps_in_workflow: + envs: + - TEST_APP_URL: https://github.com/bitrise-io/android-multiple-test-results-sample.git + - TEST_APP_BRANCH: maintenance + - TEST_APP_MODULE: app + - TEST_APP_VARIANT: DemoDebug + before_run: + - _run + - _check_outputs + steps: + - path::./: + inputs: + - project_location: ./_tmp + - module: $TEST_APP_MODULE + - variant: $TEST_APP_VARIANT + - arguments: $GRADLE_ARGUMENTS --warn test_library_module: envs: diff --git a/main.go b/main.go index 638578e..317095a 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "os" "path" "path/filepath" + "regexp" "strings" "time" @@ -138,6 +139,14 @@ func androidTestVariantPairs(module string, variantsMap gradle.Variants) (gradle return variantPairs, nil } +func isTestAPK(apkPath string) bool { + // Example names: + // app-debug-androidTest.apk + // app-debug-androidTest-20250904183958.apk (timestamped, when duplicate) + testArtifactRegexp := regexp.MustCompile(`(?i).*android[tT]est.*\.apk$`) + return testArtifactRegexp.MatchString(path.Base(apkPath)) +} + func mainE(config Configs) error { started := time.Now() @@ -228,7 +237,7 @@ func mainE(config Configs) error { var exportedAppArtifact string var exportedTestArtifact string for _, pth := range exportedArtifactPaths { - if strings.HasSuffix(strings.ToLower(path.Base(pth)), "androidtest.apk") { + if isTestAPK(pth) { exportedTestArtifact = pth } else { exportedAppArtifact = pth diff --git a/main_test.go b/main_test.go index 968d48e..5542d8b 100644 --- a/main_test.go +++ b/main_test.go @@ -158,3 +158,40 @@ func wantVariantFilterForAnotherApp() gradle.Variants { want["another_app"] = []string{"AnotherDemoDebug", "AnotherDemoDebugAndroidTest"} return want } + +func Test_isTestModule(t *testing.T) { + tests := []struct { + name string + apkPath string + want bool + }{ + { + name: "test module apk", + apkPath: "app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk", + want: true, + }, + { + name: "test module apk, lowercased", + apkPath: "app/build/outputs/apk/androidTest/debug/app-debug-androidtest.apk", + want: true, + }, + { + name: "test module apk with timestamp", + apkPath: "app/build/outputs/apk/androidTest/debug/app-debug-androidTest-20250904183958.apk", + want: true, + }, + { + name: "non-test apk", + apkPath: "app/build/outputs/apk/debug/app-debug.apk", + want: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := isTestAPK(tt.apkPath) + if got != tt.want { + t.Errorf("isTestModule() = %v, want %v", got, tt.want) + } + }) + } +} From 4b060b045d9d54c97276d89ce09d3f5dc3f3619a Mon Sep 17 00:00:00 2001 From: LaszloP <7979773+lpusok@users.noreply.github.com> Date: Thu, 30 Oct 2025 13:12:17 +0100 Subject: [PATCH 3/7] Update readme --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5702bd4..2a59c4f 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Builds your Android project with Gradle with the belonging AndroidTest variant. Description [This Step](https://github.com/bitrise-steplib/bitrise-step-android-build-for-ui-testing) generates all the APKs you need to run instrumentation tests for your Android app: both an APK from your app and the belonging test APK, for example, `:app:assembleDemoDebug`, `:app:assembleDemoDebugAndroidTest` - + ### Configuring the Step 1. Add the **Project Location** which is the root directory of your Android project. 2. Set the **Module** you want to build. To see your available modules, open your project in Android Studio and go to **Project Structure** and see the list on the left. @@ -29,7 +29,7 @@ Builds your Android project with Gradle with the belonging AndroidTest variant. ## 🧩 Get started -Add this step directly to your workflow in the [Bitrise Workflow Editor](https://devcenter.bitrise.io/steps-and-workflows/steps-and-workflows-index/). +Add this step directly to your workflow in the [Bitrise Workflow Editor](https://docs.bitrise.io/en/bitrise-ci/workflows-and-pipelines/steps/adding-steps-to-a-workflow.html). You can also run this step directly with [Bitrise CLI](https://github.com/bitrise-io/bitrise). @@ -61,9 +61,8 @@ You can also run this step directly with [Bitrise CLI](https://github.com/bitris We welcome [pull requests](https://github.com/bitrise-steplib/bitrise-step-android-build-for-ui-testing/pulls) and [issues](https://github.com/bitrise-steplib/bitrise-step-android-build-for-ui-testing/issues) against this repository. -For pull requests, work on your changes in a forked repository and use the Bitrise CLI to [run step tests locally](https://devcenter.bitrise.io/bitrise-cli/run-your-first-build/). +For pull requests, work on your changes in a forked repository and use the Bitrise CLI to [run step tests locally](https://docs.bitrise.io/en/bitrise-ci/bitrise-cli/running-your-first-local-build-with-the-cli.html). Learn more about developing steps: -- [Create your own step](https://devcenter.bitrise.io/contributors/create-your-own-step/) -- [Testing your Step](https://devcenter.bitrise.io/contributors/testing-and-versioning-your-steps/) +- [Create your own step](https://docs.bitrise.io/en/bitrise-ci/workflows-and-pipelines/developing-your-own-bitrise-step/developing-a-new-step.html) From 782de61258799985e8ce823008d175d23b3676b9 Mon Sep 17 00:00:00 2001 From: LaszloP <7979773+lpusok@users.noreply.github.com> Date: Thu, 30 Oct 2025 13:14:52 +0100 Subject: [PATCH 4/7] Fix lint --- e2e/bitrise.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/bitrise.yml b/e2e/bitrise.yml index 2361e33..a480138 100644 --- a/e2e/bitrise.yml +++ b/e2e/bitrise.yml @@ -22,7 +22,7 @@ workflows: - _run - _check_outputs steps: - - path::./: + - path::./: inputs: - project_location: ./_tmp - module: $TEST_APP_MODULE From 63e4cb2b0510b34db450d8556495e05231d71014 Mon Sep 17 00:00:00 2001 From: LaszloP <7979773+lpusok@users.noreply.github.com> Date: Thu, 30 Oct 2025 13:26:31 +0100 Subject: [PATCH 5/7] use 17 java version --- e2e/bitrise.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/e2e/bitrise.yml b/e2e/bitrise.yml index a480138..c52f682 100644 --- a/e2e/bitrise.yml +++ b/e2e/bitrise.yml @@ -42,10 +42,10 @@ workflows: _run: steps: - - set-java-version@1: - run_if: $.IsCI - inputs: - - java_version: 11 + # - set-java-version@1: + # run_if: $.IsCI + # inputs: + # - java_version: 17 - script@1: inputs: - content: |- From 049b4b26c7c179e50f17913338f2fc5077afbc32 Mon Sep 17 00:00:00 2001 From: LaszloP <7979773+lpusok@users.noreply.github.com> Date: Thu, 30 Oct 2025 16:30:13 +0100 Subject: [PATCH 6/7] Set JDK version --- e2e/bitrise.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/e2e/bitrise.yml b/e2e/bitrise.yml index c52f682..0095f67 100644 --- a/e2e/bitrise.yml +++ b/e2e/bitrise.yml @@ -8,7 +8,8 @@ workflows: - TEST_APP_BRANCH: maintenance - TEST_APP_MODULE: app - TEST_APP_VARIANT: DemoDebug - after_run: + - JDK_VERSION: 17 + before_run: - _run - _check_outputs @@ -18,6 +19,7 @@ workflows: - TEST_APP_BRANCH: maintenance - TEST_APP_MODULE: app - TEST_APP_VARIANT: DemoDebug + - JDK_VERSION: 17 before_run: - _run - _check_outputs @@ -36,16 +38,17 @@ workflows: - TEST_APP_MODULE: feature:example1 - TEST_APP_VARIANT: debug - GRADLE_ARGUMENTS: :app:assembleDebug # workaround for building a main app for a library module - after_run: + - JDK_VERSION: 21 + before_run: - _run - _check_outputs _run: steps: - # - set-java-version@1: - # run_if: $.IsCI - # inputs: - # - java_version: 17 + - set-java-version@1: + run_if: $.IsCI + inputs: + - java_version: $JDK_VERSION - script@1: inputs: - content: |- From 22cc80d7df0515217cf886b8a01ab923b21bdc7b Mon Sep 17 00:00:00 2001 From: LaszloP <7979773+lpusok@users.noreply.github.com> Date: Thu, 30 Oct 2025 17:30:16 +0100 Subject: [PATCH 7/7] jdk version --- e2e/bitrise.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/bitrise.yml b/e2e/bitrise.yml index 0095f67..626b5fd 100644 --- a/e2e/bitrise.yml +++ b/e2e/bitrise.yml @@ -48,7 +48,7 @@ workflows: - set-java-version@1: run_if: $.IsCI inputs: - - java_version: $JDK_VERSION + - set_java_version: $JDK_VERSION - script@1: inputs: - content: |-