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) diff --git a/e2e/bitrise.yml b/e2e/bitrise.yml index eecdc43..626b5fd 100644 --- a/e2e/bitrise.yml +++ b/e2e/bitrise.yml @@ -8,10 +8,29 @@ workflows: - TEST_APP_BRANCH: maintenance - TEST_APP_MODULE: app - TEST_APP_VARIANT: DemoDebug - after_run: + - JDK_VERSION: 17 + before_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 + - JDK_VERSION: 17 + 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: - TEST_APP_URL: https://github.com/bitrise-io/Bitrise-Android-Modules-Sample.git @@ -19,29 +38,18 @@ 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: - - 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: + - set_java_version: $JDK_VERSION + - script@1: inputs: - content: |- #!/bin/env bash 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) + } + }) + } +}