Skip to content

Commit 3cba467

Browse files
authored
Upload FTL results to a specified directory. (#307)
This makes sure results land in PRs artifacts directory to make them accessible through CI UI.
1 parent d0e0dd2 commit 3cba467

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/ci/device/FirebaseTestServer.groovy

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,20 @@
1515
package com.google.firebase.gradle.plugins.ci.device
1616

1717
import com.android.builder.testing.api.TestServer
18+
import java.nio.file.Paths
1819
import org.gradle.api.Project
1920

2021

2122
class FirebaseTestServer extends TestServer {
2223
private static final String BUCKET_NAME = 'android-ci'
2324
final Project project
2425
final FirebaseTestLabExtension extension
26+
final Random random
2527

2628
FirebaseTestServer(Project project, FirebaseTestLabExtension extension) {
2729
this.project = project
2830
this.extension = extension
31+
this.random = new Random(System.currentTimeMillis())
2932
}
3033

3134
@Override
@@ -42,17 +45,30 @@ class FirebaseTestServer extends TestServer {
4245

4346
def devicesCmd = extension.devices.collectMany { ['--device', it] }
4447

48+
def resultsArgs = getResultUploadArgs()
49+
4550
project.exec {
46-
commandLine('gcloud','firebase','test','android','run',
47-
'--type', 'instrumentation',
48-
"--results-bucket=$BUCKET_NAME", "--app=$testedApkPath", "--test=$testApk",
49-
'--no-auto-google-login', '--no-record-video', '--no-performance-metrics', '-q',
50-
*devicesCmd)
51+
commandLine('gcloud', 'firebase', 'test', 'android', 'run',
52+
'--type=instrumentation',
53+
"--app=$testedApkPath", "--test=$testApk",
54+
'--no-auto-google-login', '--no-record-video', '--no-performance-metrics', '-q',
55+
*resultsArgs, *devicesCmd)
5156
}
5257
}
5358

5459
@Override
5560
boolean isConfigured() {
5661
return true
5762
}
63+
64+
private List<String> getResultUploadArgs() {
65+
Optional<String> resultsBucket = Optional.ofNullable(System.getenv('FTL_RESULTS_BUCKET'))
66+
Optional<String> resultsDir = Optional.ofNullable(System.getenv('FTL_RESULTS_DIR'))
67+
68+
List<String> args = ['--results-bucket', resultsBucket.orElse('android-ci')]
69+
if (resultsDir.isPresent()) {
70+
args += ['--results-dir', Paths.get(resultsDir.get(), "${project.path}_${random.nextLong()}")]
71+
}
72+
return args
73+
}
5874
}

0 commit comments

Comments
 (0)