Skip to content

Commit 2c1ffe7

Browse files
authored
Expand nested env vars. (#309)
1 parent 3cba467 commit 2c1ffe7

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2018 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.gradle.plugins.ci
16+
17+
import java.util.regex.Matcher
18+
import java.util.regex.Pattern
19+
20+
class Environment {
21+
private static final Pattern ENV_PATTERN = Pattern.compile(/\$\(([A-Za-z0-9_-]+)\)/)
22+
23+
static String expand(String value) {
24+
Matcher m = ENV_PATTERN.matcher(value)
25+
while (m.find()) {
26+
value = value.replace(m.group(), env(m.group(1)))
27+
}
28+
return value
29+
30+
}
31+
32+
private static String env(String varName) {
33+
return Optional.ofNullable(System.getenv(varName)).orElse('')
34+
}
35+
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
package com.google.firebase.gradle.plugins.ci.device
1616

1717
import com.android.builder.testing.api.TestServer
18+
import com.google.firebase.gradle.plugins.ci.Environment
19+
1820
import java.nio.file.Paths
1921
import org.gradle.api.Project
2022

2123

2224
class FirebaseTestServer extends TestServer {
23-
private static final String BUCKET_NAME = 'android-ci'
25+
private static final String DEFAULT_BUCKET_NAME = 'android-ci'
2426
final Project project
2527
final FirebaseTestLabExtension extension
2628
final Random random
@@ -62,10 +64,10 @@ class FirebaseTestServer extends TestServer {
6264
}
6365

6466
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+
Optional<String> resultsBucket = Optional.ofNullable(System.getenv('FTL_RESULTS_BUCKET')).map(Environment.&expand)
68+
Optional<String> resultsDir = Optional.ofNullable(System.getenv('FTL_RESULTS_DIR')).map(Environment.&expand)
6769

68-
List<String> args = ['--results-bucket', resultsBucket.orElse('android-ci')]
70+
List<String> args = ['--results-bucket', resultsBucket.orElse(DEFAULT_BUCKET_NAME)]
6971
if (resultsDir.isPresent()) {
7072
args += ['--results-dir', Paths.get(resultsDir.get(), "${project.path}_${random.nextLong()}")]
7173
}

0 commit comments

Comments
 (0)