Upload FTL results to a specified directory.
This makes sure results land in PRs artifacts directory to make them
accessible through CI UI.
package com.google.firebase.gradle.plugins.ci.device
import com.android.builder.testing.api.TestServer
+import java.nio.file.Paths
import org.gradle.api.Project
@@ -22,10 +23,12 @@ class FirebaseTestServer extends TestServer {
private static final String BUCKET_NAME = 'android-ci'
final Project project
final FirebaseTestLabExtension extension
+ final Random random
FirebaseTestServer(Project project, FirebaseTestLabExtension extension) {
this.project = project
this.extension = extension
+ this.random = new Random(System.currentTimeMillis())
}
@Override
@@ -42,12 +45,14 @@ class FirebaseTestServer extends TestServer {
def devicesCmd = extension.devices.collectMany { ['--device', it] }
+ def resultsArgs = getResultUploadArgs()
+
project.exec {
commandLine('gcloud', 'firebase', 'test', 'android', 'run',
- '--type', 'instrumentation',
- "--results-bucket=$BUCKET_NAME", "--app=$testedApkPath", "--test=$testApk",
+ '--type=instrumentation',
+ "--app=$testedApkPath", "--test=$testApk",
'--no-auto-google-login', '--no-record-video', '--no-performance-metrics', '-q',
- *devicesCmd)
+ *resultsArgs, *devicesCmd)
}
}
@@ -55,4 +60,15 @@ class FirebaseTestServer extends TestServer {
boolean isConfigured() {
return true
}
+
+ private List<String> getResultUploadArgs() {
+ Optional<String> resultsBucket = Optional.ofNullable(System.getenv('FTL_RESULTS_BUCKET'))
+ Optional<String> resultsDir = Optional.ofNullable(System.getenv('FTL_RESULTS_DIR'))
+
+ List<String> args = ['--results-bucket', resultsBucket.orElse('android-ci')]
+ if (resultsDir.isPresent()) {
+ args += ['--results-dir', Paths.get(resultsDir.get(), "${project.path}_${random.nextLong()}")]
+ }
+ return args
+ }
}
