Skip to content

Commit a150f4c

Browse files
yigitdlam
andauthored
]fail action only if there are failed tests (#67)
* fail action only if there are failed tests This Cl changes CLIMain to only fail if there are known failres and ignore skips. Also, the prior CL missed passing the environment variable for this parameter, it is fixed in this CL. Finally, i've updated GCP credentials rule to accept application credentials, which is very handy for local testing * Update AndroidXCI/cli/src/main/kotlin/dev/androidx/ci/cli/Main.kt Co-authored-by: Dustin Lam <[email protected]> * ktformat --------- Co-authored-by: Dustin Lam <[email protected]>
1 parent d866dba commit a150f4c

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

AndroidXCI/cli/src/main/kotlin/dev/androidx/ci/cli/Main.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package dev.androidx.ci.cli
1818

1919
import com.github.ajalt.clikt.core.CliktCommand
20+
import com.github.ajalt.clikt.parameters.options.convert
21+
import com.github.ajalt.clikt.parameters.options.default
2022
import com.github.ajalt.clikt.parameters.options.option
2123
import com.github.ajalt.clikt.parameters.options.required
2224
import com.github.ajalt.clikt.parameters.types.file
@@ -154,7 +156,14 @@ private class Cli : CliktCommand() {
154156
are run for a TestMatrix.
155157
""".trimIndent(),
156158
envvar = "ANDROIDX_IGNORE_EMPTY_TEST_MATRICES"
157-
)
159+
).convert {
160+
if (it.isNullOrBlank()) {
161+
// default to true.
162+
true
163+
} else {
164+
it.toBoolean()
165+
}
166+
}.default(true)
158167

159168
override fun run() {
160169
logFile?.let(::configureLogger)
@@ -186,13 +195,13 @@ private class Cli : CliktCommand() {
186195
bucketPath = gcpBucketPath,
187196
useTestConfigFiles = useTestConfigFiles?.toBoolean() ?: false,
188197
testSuiteTags = testSuiteTags?.split(',')?.map { it.trim() } ?: emptyList(),
189-
ignoreEmptyTestMatrices = ignoreEmptyTestMatrices?.toBoolean() ?: true,
198+
ignoreEmptyTestMatrices = ignoreEmptyTestMatrices,
190199
)
191200
testRunner.runTests()
192201
}
193202
println(result.toJson())
194203
flushLogs()
195-
if (result.allTestsPassed) {
204+
if (!result.hasFailedTest) {
196205
exitProcess(0)
197206
} else {
198207
println("================= FAILURE LOG =================")

AndroidXCI/lib/src/test/kotlin/dev/androidx/ci/util/GoogleCloudCredentialsRule.kt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package dev.androidx.ci.util
1818

19+
import com.google.auth.oauth2.GoogleCredentials
1920
import com.google.auth.oauth2.ServiceAccountCredentials
2021
import dev.androidx.ci.config.Config
2122
import org.junit.AssumptionViolatedException
@@ -30,14 +31,23 @@ internal class GoogleCloudCredentialsRule : TestRule {
3031
lateinit var gcpConfig: Config.Gcp
3132
private set
3233
private fun loadCredentials() {
33-
val envValue = System.getenv("ANDROIDX_GCLOUD_CREDENTIALS")
34-
?: throw AssumptionViolatedException("skip test without credentials")
35-
val credentials = ServiceAccountCredentials.fromStream(
36-
envValue.byteInputStream(Charsets.UTF_8)
37-
)
34+
val appCredentialsProject = System.getenv("ANDROIDX_GCLOUD_APP_CREDENTIALS_PROJECT")
35+
val (projectId, credentials) = if (appCredentialsProject != null) {
36+
appCredentialsProject to GoogleCredentials.getApplicationDefault()
37+
} else {
38+
val credentialsParam = System.getenv("ANDROIDX_GCLOUD_CREDENTIALS")
39+
?: throw AssumptionViolatedException("skip test without credentials")
40+
val credentials = ServiceAccountCredentials.fromStream(
41+
credentialsParam.byteInputStream(Charsets.UTF_8)
42+
)
43+
credentials.projectId to credentials
44+
}
45+
if (credentials == null) {
46+
throw AssumptionViolatedException("need to provide app credentials")
47+
}
3848
gcpConfig = Config.Gcp(
3949
credentials = credentials,
40-
projectId = credentials.projectId
50+
projectId = projectId
4151
)
4252
}
4353

action.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,5 @@ runs:
6161
ANDROIDX_BUCKET_NAME: ${{ inputs.gcp-bucket-name }}
6262
ANDROIDX_BUCKET_PATH: ${{ inputs.gcp-bucket-path }}
6363
ANDROIDX_USE_TEST_CONFIG_FILES: ${{ inputs.use-test-config-files }}
64-
ANDROIDX_TEST_SUITE_TAGS: ${{ inputs.test-suite-tags }}
64+
ANDROIDX_TEST_SUITE_TAGS: ${{ inputs.test-suite-tags }}
65+
ANDROIDX_IGNORE_EMPTY_TEST_MATRICES: ${{ inputs.ignore-empty-test-matrices }}

0 commit comments

Comments
 (0)