Skip to content

Commit 758fc5b

Browse files
committed
ci/build.gradle.kts: PrintToolVersions added
1 parent 574e987 commit 758fc5b

File tree

1 file changed

+85
-8
lines changed

1 file changed

+85
-8
lines changed

firebase-dataconnect/ci/build.gradle.kts

Lines changed: 85 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import java.io.File
2+
import java.io.IOException
23
import org.gradle.kotlin.dsl.*
34

45
plugins { alias(libs.plugins.spotless) }
@@ -59,15 +60,68 @@ abstract class InstallFirebaseToolsTask : DefaultTask() {
5960
}
6061
}
6162

62-
val installFirebaseToolsTask =
63-
tasks.register<InstallFirebaseToolsTask>("installFirebaseTools") {
64-
group = "Data Connect CI"
65-
description = "Install the firebase-tools npm package"
66-
initializeProperties(
67-
version = providers.requiredGradleProperty("firebaseToolsVersion"),
68-
destDir = layout.buildDirectory.dir("firebase-tools"),
69-
)
63+
abstract class PrintToolVersions : DefaultTask() {
64+
65+
@get:InputFile abstract val gradlewExecutable: RegularFileProperty
66+
67+
@get:InputFile abstract val firebaseExecutable: RegularFileProperty
68+
69+
@get:Inject abstract val execOperations: ExecOperations
70+
71+
fun initializeProperties(
72+
firebaseExecutable: Provider<RegularFile>,
73+
gradlewExecutable: Provider<RegularFile>
74+
) {
75+
this.firebaseExecutable.set(firebaseExecutable)
76+
this.gradlewExecutable.set(gradlewExecutable)
77+
}
78+
79+
@TaskAction
80+
fun execute() {
81+
val firebaseExecutable: File = firebaseExecutable.get().asFile
82+
val gradlewFile: File = gradlewExecutable.get().asFile
83+
84+
runCommandIgnoringExitCode("uname", "-a")
85+
runCommandIgnoringExitCode("which", "java")
86+
runCommandIgnoringExitCode("java", "-version")
87+
runCommandIgnoringExitCode("which", "javac")
88+
runCommandIgnoringExitCode("javac", "-version")
89+
runCommandIgnoringExitCode("which", "node")
90+
runCommandIgnoringExitCode("node", "--version")
91+
runCommandIgnoringExitCode(firebaseExecutable.path, "--version")
92+
runCommandIgnoringExitCode(gradlewFile.path, "--version")
93+
}
94+
95+
private fun runCommandIgnoringExitCode(vararg args: String) {
96+
val argsStr = args.joinToString(" ")
97+
logger.lifecycle("Running command: $argsStr")
98+
99+
val execResult =
100+
try {
101+
execOperations.exec {
102+
commandLine(*args)
103+
isIgnoreExitValue = true
104+
}
105+
} catch (e: Exception) {
106+
var ioException: Throwable? = e
107+
while (ioException !== null && ioException !is IOException) {
108+
ioException = ioException.cause
109+
}
110+
if (ioException !== null) {
111+
logger.warn("WARNING: unable to start process: $argsStr (${e.message})")
112+
return
113+
} else {
114+
throw e
115+
}
116+
}
117+
118+
if (execResult.exitValue != 0) {
119+
logger.warn(
120+
"WARNING: command completed with non-zero exit code " + "${execResult.exitValue}: $argsStr"
121+
)
122+
}
70123
}
124+
}
71125

72126
fun ProviderFactory.requiredGradleProperty(propertyName: String) =
73127
gradleProperty(propertyName)
@@ -83,3 +137,26 @@ fun ProviderFactory.requiredGradleProperty(propertyName: String) =
83137
)
84138

85139
class RequiredPropertyMissing(message: String) : Exception(message)
140+
141+
val ciTaskGroup = "Data Connect CI"
142+
143+
val installFirebaseToolsTask =
144+
tasks.register<InstallFirebaseToolsTask>("installFirebaseTools") {
145+
group = ciTaskGroup
146+
description = "Install the firebase-tools npm package"
147+
initializeProperties(
148+
version = providers.requiredGradleProperty("firebaseToolsVersion"),
149+
destDir = layout.buildDirectory.dir("firebase-tools"),
150+
)
151+
}
152+
153+
val printToolVersionsTask =
154+
tasks.register<PrintToolVersions>("printToolVersions") {
155+
group = ciTaskGroup
156+
description = "Print versions of notable command-line tools"
157+
val gradlewExecutable = layout.projectDirectory.file("../../gradlew")
158+
initializeProperties(
159+
firebaseExecutable = installFirebaseToolsTask.flatMap { it.firebaseExecutable },
160+
gradlewExecutable = providers.provider { gradlewExecutable },
161+
)
162+
}

0 commit comments

Comments
 (0)