@@ -27,37 +27,38 @@ import kotlin.getOrDefault
2727 * @author Akash Yadav
2828 */
2929object CI {
30-
31- private var _commitHash : String? = null
32- private var _branchName : String? = null
30+ private var commitHash: String? = null
31+ private var branchName: String? = null
3332
3433 fun commitHash (project : Project ): String {
35- if (_commitHash == null ) {
34+ if (commitHash == null ) {
3635 val sha = System .getenv(" GITHUB_SHA" ) ? : " HEAD"
37- _commitHash =
36+ commitHash =
3837 project.cmdOutput(
3938 project.rootProject.projectDir,
4039 " git" ,
4140 " rev-parse" ,
4241 " --short" ,
43- sha
42+ sha,
4443 )
4544 }
4645
47- return _commitHash ? : " unknown"
46+ return commitHash ? : " unknown"
4847 }
4948
5049 fun branchName (project : Project ): String {
51- if (_branchName == null ) {
52- _branchName = System .getenv(" GITHUB_REF_NAME" )
50+ if (branchName == null ) {
51+ branchName = System .getenv(" GITHUB_REF_NAME" )
5352 ? : project.cmdOutput(
5453 project.rootProject.projectDir,
55- " git" , " rev-parse" , " --abbrev-ref" ,
56- " HEAD"
54+ " git" ,
55+ " rev-parse" ,
56+ " --abbrev-ref" ,
57+ " HEAD" ,
5758 )
5859 }
5960
60- return _branchName ? : " unknown"
61+ return branchName ? : " unknown"
6162 }
6263
6364 /* * Whether the current build is a CI build. */
@@ -66,23 +67,28 @@ object CI {
6667 /* * Whether the current build is for tests. This is set ONLY in CI builds. */
6768 val isTestEnv by lazy { " true" == System .getenv(" ANDROIDIDE_TEST" ) }
6869
69- private fun Project.cmdOutput (workDir : File , vararg args : String ): String? = runCatching {
70- val process = ProcessBuilder (* args)
71- .directory(File (" ." ))
72- .redirectErrorStream(true )
73- .start()
70+ private fun Project.cmdOutput (
71+ workDir : File ,
72+ vararg args : String ,
73+ ): String? =
74+ runCatching {
75+ val process =
76+ ProcessBuilder (* args)
77+ .directory(File (" ." ))
78+ .redirectErrorStream(true )
79+ .start()
7480
75- val exitCode = process.waitFor()
76- if (exitCode != 0 ) {
77- throw RuntimeException (" Command '$args ' failed with exit code $exitCode " )
78- }
81+ val exitCode = process.waitFor()
82+ if (exitCode != 0 ) {
83+ throw RuntimeException (" Command '$args ' failed with exit code $exitCode " )
84+ }
7985
80- process
81- .inputStream
82- .bufferedReader()
83- .readText()
84- .trim()
85- }.onFailure { err ->
86- logger.warn(" Unable to run command: ${args.joinToString(" " )} " , err)
87- }.getOrDefault(null )
86+ process
87+ .inputStream
88+ .bufferedReader()
89+ .readText()
90+ .trim()
91+ }.onFailure { err ->
92+ logger.warn(" Unable to run command: ${args.joinToString(" " )} " , err)
93+ }.getOrDefault(null )
8894}
0 commit comments