[PM-10515] CI build info on version copy (#4456)

Co-authored-by: Álison Fernandes <vvolkgang@users.noreply.github.com>
This commit is contained in:
aj-rosado 2024-12-17 17:36:46 +00:00 committed by GitHub
parent 889457ae96
commit 3a41138f39
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 86 additions and 4 deletions

View File

@ -460,6 +460,10 @@ jobs:
distribution: "temurin"
java-version: ${{ env.JAVA_VERSION }}
- name: Update app CI Build info
run: |
./Scripts/update_app_ci_build_info.sh $GITHUB_REPOSITORY $GITHUB_REF_NAME $GITHUB_SHA $GITHUB_RUN_ID $GITHUB_RUN_ATTEMPT
# Start from 11000 to prevent collisions with mobile build version codes
- name: Increment version
run: |

View File

@ -68,7 +68,7 @@ android {
buildConfigField(
type = "String",
name = "CI_INFO",
value = "\"${ciProperties.getOrDefault("ci.info", "local")}\""
value = "${ciProperties.getOrDefault("ci.info", "\"local\"")}"
)
}

View File

@ -1,5 +1,6 @@
package com.x8bit.bitwarden.ui.platform.feature.settings.about
import android.os.Build
import android.os.Parcelable
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope
@ -91,8 +92,34 @@ class AboutViewModel @Inject constructor(
}
private fun handleVersionClick() {
val buildFlavour = when (BuildConfig.FLAVOR) {
"standard" -> ""
else -> "-${BuildConfig.FLAVOR}"
}
val buildVariant = when (BuildConfig.BUILD_TYPE) {
"debug" -> "dev"
"release" -> "prod"
else -> BuildConfig.BUILD_TYPE
}
val deviceBrandModel = "\uD83D\uDCF1 ${Build.BRAND} ${Build.MODEL}"
val osInfo = "\uD83E\uDD16 ${Build.VERSION.RELEASE}@${Build.VERSION.SDK_INT}"
val buildInfo = "\uD83D\uDCE6 $buildVariant$buildFlavour"
val ciBuildInfoString = BuildConfig.CI_INFO
clipboardManager.setText(
text = state.copyrightInfo.concat("\n\n".asText()).concat(state.version),
text = state.copyrightInfo
.concat("\n\n".asText())
.concat(state.version)
.concat("\n".asText())
.concat("$deviceBrandModel $osInfo $buildInfo".asText())
.concat(
"\n$ciBuildInfoString"
.takeUnless { ciBuildInfoString.isEmpty() }
.orEmpty()
.asText(),
),
)
}

View File

@ -1,5 +1,6 @@
package com.x8bit.bitwarden.ui.platform.feature.settings.about
import android.os.Build
import androidx.lifecycle.SavedStateHandle
import app.cash.turbine.test
import com.x8bit.bitwarden.BuildConfig
@ -111,12 +112,24 @@ class AboutViewModelTest : BaseViewModelTest() {
fun `on VersionClick should call setText on the ClipboardManager with specific Text`() {
val versionName = BuildConfig.VERSION_NAME
val versionCode = BuildConfig.VERSION_CODE
val deviceBrandModel = "\uD83D\uDCF1 ${Build.BRAND} ${Build.MODEL}"
val osInfo = "\uD83E\uDD16 ${Build.VERSION.RELEASE}@${Build.VERSION.SDK_INT}"
val buildInfo = "\uD83D\uDCE6 dev"
val ciInfo = BuildConfig.CI_INFO
val expectedText = "© Bitwarden Inc. 2015-"
.asText()
.concat(Year.now(fixedClock).value.toString().asText())
.concat("\n\n".asText())
.concat("Version: $versionName ($versionCode)".asText())
.concat("\n".asText())
.concat("$deviceBrandModel $osInfo $buildInfo".asText())
.concat(
"Version: $versionName ($versionCode)".asText(),
"\n$ciInfo"
.takeUnless { ciInfo.isEmpty() }
.orEmpty()
.asText(),
)
every { clipboardManager.setText(expectedText, true, null) } just runs
@ -125,7 +138,7 @@ class AboutViewModelTest : BaseViewModelTest() {
viewModel.trySendAction(AboutAction.VersionClick)
verify(exactly = 1) {
clipboardManager.setText(expectedText, true, null)
clipboardManager.setText(expectedText, ofType(Boolean::class), isNull())
}
}

View File

@ -0,0 +1,38 @@
#!/bin/sh
# CI Build Info Updater
#
# Updates the ci.properties file with additional info from the CI build.
#
# Prerequisites:
# - Git command line tools installed
# - Write access to ci.properties file
if [ $# -ne 5 ]; then
echo "Usage: $0 <repository> <branch> <commit_hash> <ci_run_number> <ci_run_attempt>"
echo "E.g: $0 bitwarden/android main abc123 123 1"
exit 1
fi
set -euo pipefail
repository=$1
branch=$2
commit_hash=$3
ci_run_number=$4
ci_run_attempt=$5
ci_build_info_file="../ci.properties"
git_source="${repository}/${branch}@${commit_hash}"
ci_run_source="${repository}/actions/runs/${ci_run_number}/attempts/${ci_run_attempt}"
emoji_brick="\\ud83e\\uddf1" # 🧱
emoji_computer="\\ud83d\\udcbb" # 💻
echo "🧱 Updating app CI Build info..."
echo "🧱 🧱 commit: ${git_source}"
echo "🧱 💻 build source: ${ci_run_source}"
cat << EOF > ${ci_build_info_file}
ci.info="${emoji_brick} commit: ${git_source}\\\n${emoji_computer} build source: ${ci_run_source}"
EOF
echo "✅ CI Build info updated successfully."