Browse Source

Merge pull request #2292 from element-hq/feature/bma/gitSha

Git sha and branch in log
pull/2294/head
Benoit Marty 8 months ago committed by GitHub
parent
commit
f88d96fbc5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      app/build.gradle.kts
  2. 8
      app/src/main/kotlin/io/element/android/x/di/AppModule.kt
  3. 3
      app/src/main/kotlin/io/element/android/x/info/Logs.kt
  4. 1
      features/preferences/impl/build.gradle.kts
  5. 12
      features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/VersionFormatter.kt
  6. 23
      features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/root/FakeVersionFormatter.kt
  7. 50
      features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/root/VersionFormatterTest.kt
  8. 2
      features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporter.kt
  9. 8
      features/rageshake/impl/src/test/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporterTest.kt
  10. 1
      libraries/core/src/main/kotlin/io/element/android/libraries/core/meta/BuildMeta.kt
  11. 2
      libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/core/BuildMeta.kt
  12. 40
      plugins/src/main/kotlin/extension/Utils.kt
  13. 8
      samples/minimal/src/main/kotlin/io/element/android/samples/minimal/Singleton.kt

5
app/build.gradle.kts

@ -20,6 +20,8 @@ import com.android.build.api.variant.FilterConfiguration.FilterType.ABI @@ -20,6 +20,8 @@ import com.android.build.api.variant.FilterConfiguration.FilterType.ABI
import extension.allFeaturesImpl
import extension.allLibrariesImpl
import extension.allServicesImpl
import extension.gitBranchName
import extension.gitRevision
import extension.koverDependencies
import extension.setupKover
import org.jetbrains.kotlin.cli.common.toBooleanLenient
@ -54,6 +56,9 @@ android { @@ -54,6 +56,9 @@ android {
abiFilters += listOf("armeabi-v7a", "x86", "arm64-v8a", "x86_64")
}
buildConfigField("String", "GIT_REVISION", "\"${gitRevision()}\"")
buildConfigField("String", "GIT_BRANCH_NAME", "\"${gitBranchName()}\"")
// Ref: https://developer.android.com/studio/build/configure-apk-splits.html#configure-abi-split
splits {
// Configures multiple APKs based on ABI.

8
app/src/main/kotlin/io/element/android/x/di/AppModule.kt

@ -85,12 +85,8 @@ object AppModule { @@ -85,12 +85,8 @@ object AppModule {
lowPrivacyLoggingEnabled = false,
versionName = BuildConfig.VERSION_NAME,
versionCode = BuildConfig.VERSION_CODE,
// BuildConfig.GIT_REVISION,
gitRevision = "TODO",
// BuildConfig.GIT_REVISION_DATE,
gitRevisionDate = "TODO",
// BuildConfig.GIT_BRANCH_NAME,
gitBranchName = "TODO",
gitRevision = BuildConfig.GIT_REVISION,
gitBranchName = BuildConfig.GIT_BRANCH_NAME,
flavorDescription = BuildConfig.FLAVOR_DESCRIPTION,
flavorShortDescription = BuildConfig.SHORT_FLAVOR_DESCRIPTION,
)

3
app/src/main/kotlin/io/element/android/x/info/Logs.kt

@ -29,6 +29,8 @@ fun logApplicationInfo() { @@ -29,6 +29,8 @@ fun logApplicationInfo() {
append(BuildConfig.VERSION_CODE)
append(") - ")
append(BuildConfig.BUILD_TYPE)
append(" / ")
append(BuildConfig.FLAVOR)
}
// TODO Get SDK version somehow
val sdkVersion = "SDK VERSION (TODO)"
@ -37,6 +39,7 @@ fun logApplicationInfo() { @@ -37,6 +39,7 @@ fun logApplicationInfo() {
Timber.d("----------------------------------------------------------------")
Timber.d("----------------------------------------------------------------")
Timber.d(" Application version: $appVersion")
Timber.d(" Git SHA: ${BuildConfig.GIT_REVISION}")
Timber.d(" SDK version: $sdkVersion")
Timber.d(" Local time: $date")
Timber.d("----------------------------------------------------------------")

1
features/preferences/impl/build.gradle.kts

@ -82,6 +82,7 @@ dependencies { @@ -82,6 +82,7 @@ dependencies {
testImplementation(projects.libraries.indicator.impl)
testImplementation(projects.features.logout.impl)
testImplementation(projects.services.analytics.test)
testImplementation(projects.services.toolbox.test)
testImplementation(projects.features.analytics.impl)
testImplementation(projects.tests.testutils)
}

12
features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/VersionFormatter.kt

@ -33,16 +33,16 @@ class DefaultVersionFormatter @Inject constructor( @@ -33,16 +33,16 @@ class DefaultVersionFormatter @Inject constructor(
private val buildMeta: BuildMeta,
) : VersionFormatter {
override fun get(): String {
return stringProvider.getString(
val base = stringProvider.getString(
CommonStrings.settings_version_number,
buildMeta.versionName,
buildMeta.versionCode.toString()
)
return if (buildMeta.gitBranchName == "main") {
base
} else {
// In case of a build not from main, we display the branch name and the revision
"$base\n${buildMeta.gitBranchName}\n${buildMeta.gitRevision}"
}
}
class FakeVersionFormatter : VersionFormatter {
override fun get(): String {
return "A Version"
}
}

23
features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/root/FakeVersionFormatter.kt

@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
/*
* Copyright (c) 2024 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.features.preferences.impl.root
class FakeVersionFormatter : VersionFormatter {
override fun get(): String {
return "A Version"
}
}

50
features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/root/VersionFormatterTest.kt

@ -0,0 +1,50 @@ @@ -0,0 +1,50 @@
/*
* Copyright (c) 2024 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.features.preferences.impl.root
import com.google.common.truth.Truth.assertThat
import io.element.android.libraries.matrix.test.core.aBuildMeta
import io.element.android.services.toolbox.test.strings.FakeStringProvider
import kotlinx.coroutines.test.runTest
import org.junit.Test
class VersionFormatterTest {
@Test
fun `version formatter should return simplified version for other branch`() = runTest {
val sut = DefaultVersionFormatter(
stringProvider = FakeStringProvider(defaultResult = VERSION),
buildMeta = aBuildMeta(gitBranchName = "main")
)
assertThat(sut.get()).isEqualTo(VERSION)
}
@Test
fun `version formatter should return simplified version for main branch`() = runTest {
val sut = DefaultVersionFormatter(
stringProvider = FakeStringProvider(defaultResult = VERSION),
buildMeta = aBuildMeta(
gitBranchName = "branch",
gitRevision = "1234567890",
)
)
assertThat(sut.get()).isEqualTo("$VERSION\nbranch\n1234567890")
}
companion object {
const val VERSION = "version"
}
}

2
features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporter.kt

@ -202,6 +202,8 @@ class DefaultBugReporter @Inject constructor( @@ -202,6 +202,8 @@ class DefaultBugReporter @Inject constructor(
// add some github labels
builder.addFormDataPart("label", buildMeta.versionName)
builder.addFormDataPart("label", buildMeta.flavorDescription)
builder.addFormDataPart("branch_name", buildMeta.gitBranchName)
if (crashCallStack.isNotEmpty() && withCrashLogs) {
builder.addFormDataPart("label", "crash")
}

8
features/rageshake/impl/src/test/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporterTest.kt

@ -80,7 +80,7 @@ class DefaultBugReporterTest { @@ -80,7 +80,7 @@ class DefaultBugReporterTest {
server.shutdown()
assertThat(onUploadCancelledCalled).isFalse()
assertThat(onUploadFailedCalled).isFalse()
assertThat(progressValues.size).isEqualTo(11)
assertThat(progressValues.size).isEqualTo(EXPECTED_NUMBER_OF_PROGRESS_VALUE)
assertThat(onUploadSucceedCalled).isTrue()
}
@ -131,7 +131,7 @@ class DefaultBugReporterTest { @@ -131,7 +131,7 @@ class DefaultBugReporterTest {
assertThat(onUploadCancelledCalled).isFalse()
assertThat(onUploadFailedCalled).isTrue()
assertThat(onUploadFailedReason).isEqualTo("An error body")
assertThat(progressValues.size).isEqualTo(11)
assertThat(progressValues.size).isEqualTo(EXPECTED_NUMBER_OF_PROGRESS_VALUE)
assertThat(onUploadSucceedCalled).isFalse()
}
@ -153,4 +153,8 @@ class DefaultBugReporterTest { @@ -153,4 +153,8 @@ class DefaultBugReporterTest {
bugReporterUrlProvider = { server.url("/") }
)
}
companion object {
private const val EXPECTED_NUMBER_OF_PROGRESS_VALUE = 12
}
}

1
libraries/core/src/main/kotlin/io/element/android/libraries/core/meta/BuildMeta.kt

@ -25,7 +25,6 @@ data class BuildMeta( @@ -25,7 +25,6 @@ data class BuildMeta(
val versionName: String,
val versionCode: Int,
val gitRevision: String,
val gitRevisionDate: String,
val gitBranchName: String,
val flavorDescription: String,
val flavorShortDescription: String,

2
libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/core/BuildMeta.kt

@ -28,7 +28,6 @@ fun aBuildMeta( @@ -28,7 +28,6 @@ fun aBuildMeta(
versionName: String = "",
versionCode: Int = 0,
gitRevision: String = "",
gitRevisionDate: String = "",
gitBranchName: String = "",
flavorDescription: String = "",
flavorShortDescription: String = "",
@ -41,7 +40,6 @@ fun aBuildMeta( @@ -41,7 +40,6 @@ fun aBuildMeta(
versionName,
versionCode,
gitRevision,
gitRevisionDate,
gitBranchName,
flavorDescription,
flavorShortDescription

40
plugins/src/main/kotlin/extension/Utils.kt

@ -0,0 +1,40 @@ @@ -0,0 +1,40 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package extension
import org.gradle.api.Project
import java.io.ByteArrayOutputStream
import java.io.IOException
private fun Project.runCommand(cmd: String): String {
val outputStream = ByteArrayOutputStream()
val errorStream = ByteArrayOutputStream()
project.exec {
commandLine = cmd.split(" ")
standardOutput = outputStream
errorOutput = errorStream
}
if (errorStream.size() > 0) {
println("Error while running command: $cmd")
throw IOException(String(errorStream.toByteArray()))
}
return String(outputStream.toByteArray()).trim()
}
fun Project.gitRevision() = runCommand("git rev-parse --short=8 HEAD")
fun Project.gitBranchName() = runCommand("git rev-parse --abbrev-ref HEAD")

8
samples/minimal/src/main/kotlin/io/element/android/samples/minimal/Singleton.kt

@ -37,12 +37,8 @@ object Singleton { @@ -37,12 +37,8 @@ object Singleton {
lowPrivacyLoggingEnabled = false,
versionName = "0.1.0",
versionCode = 1,
// BuildConfig.GIT_REVISION,
gitRevision = "TODO",
// BuildConfig.GIT_REVISION_DATE,
gitRevisionDate = "TODO",
// BuildConfig.GIT_BRANCH_NAME,
gitBranchName = "TODO",
gitRevision = "",
gitBranchName = "",
flavorDescription = "NA",
flavorShortDescription = "NA",
)

Loading…
Cancel
Save