Skip to content

Commit

Permalink
[PM-10515] CI build info on version copy (#4456)
Browse files Browse the repository at this point in the history
Co-authored-by: Álison Fernandes <[email protected]>
  • Loading branch information
aj-rosado and vvolkgang authored Dec 17, 2024
1 parent 889457a commit 3a41138
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ android {
buildConfigField(
type = "String",
name = "CI_INFO",
value = "\"${ciProperties.getOrDefault("ci.info", "local")}\""
value = "${ciProperties.getOrDefault("ci.info", "\"local\"")}"
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(),
),
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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())
}
}

Expand Down
38 changes: 38 additions & 0 deletions scripts/update_app_ci_build_info.sh
Original file line number Diff line number Diff line change
@@ -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."

0 comments on commit 3a41138

Please sign in to comment.