From 9188a10d88f9efbde57ed1375720124584755122 Mon Sep 17 00:00:00 2001 From: Mahmoud Elmorabea Date: Thu, 7 Nov 2024 21:04:15 +0400 Subject: [PATCH 1/3] chore: Improve sample apps build info (#458) --- .../workflows/reusable_build_sample_apps.yml | 5 +++ .../sample/java_layout/utils/ViewUtils.java | 42 +++++++++++++++---- .../main/res/layout/activity_dashboard.xml | 1 - .../src/main/res/layout/activity_login.xml | 1 - samples/sample-app.gradle | 7 ++++ 5 files changed, 45 insertions(+), 11 deletions(-) diff --git a/.github/workflows/reusable_build_sample_apps.yml b/.github/workflows/reusable_build_sample_apps.yml index 58da882d3..d6365dafa 100644 --- a/.github/workflows/reusable_build_sample_apps.yml +++ b/.github/workflows/reusable_build_sample_apps.yml @@ -58,10 +58,15 @@ jobs: bundler-cache: true # cache tools to make builds faster in future - name: Setup local.properties file for sample app + env: + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} + COMMIT_HASH: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} run: | touch "samples/local.properties" echo "cdpApiKey=${{ secrets[matrix.cio-cdpapikey-secret-key] }}" >> "samples/local.properties" echo "siteId=${{ secrets[matrix.cio-siteid-secret-key] }}" >> "samples/local.properties" + echo "branch=$BRANCH_NAME" >> "samples/local.properties" + echo "commit=${COMMIT_HASH:0:7}" >> "samples/local.properties" if [ "${{ inputs.use_latest_sdk_version == true }}" ]; then echo "sdkVersion=${{ steps.latest-sdk-version-step.outputs.LATEST_TAG }}" >> "samples/local.properties" fi diff --git a/samples/java_layout/src/main/java/io/customer/android/sample/java_layout/utils/ViewUtils.java b/samples/java_layout/src/main/java/io/customer/android/sample/java_layout/utils/ViewUtils.java index b5363d5d1..c98fc1beb 100644 --- a/samples/java_layout/src/main/java/io/customer/android/sample/java_layout/utils/ViewUtils.java +++ b/samples/java_layout/src/main/java/io/customer/android/sample/java_layout/utils/ViewUtils.java @@ -15,12 +15,12 @@ import com.google.android.material.textfield.TextInputEditText; import com.google.android.material.textfield.TextInputLayout; +import java.text.DateFormat; +import java.util.Date; import java.util.Locale; import io.customer.android.sample.java_layout.BuildConfig; import io.customer.android.sample.java_layout.R; -import io.customer.sdk.core.di.AndroidSDKComponent; -import io.customer.sdk.core.di.SDKComponent; public class ViewUtils { public static void prepareForAutomatedTests(@NonNull View view, @StringRes int contentDescResId) { @@ -55,16 +55,40 @@ public static void setError(@NonNull TextInputLayout textInputLayout, @Nullable } public static void setBuildInfo(@NonNull TextView textView) { - AndroidSDKComponent androidSDKComponent = SDKComponent.INSTANCE.android(); - String sdkVersion = androidSDKComponent.getClient().getSdkVersion(); - String buildInfo = String.format(Locale.ENGLISH, - "Customer.io Android SDK %s Java Layout %s (%s)", - sdkVersion, - BuildConfig.VERSION_NAME, - BuildConfig.VERSION_CODE); + String buildInfo = String.format( + Locale.ENGLISH, + "SDK version: %s\n" + + "Build date: %s\n" + + "Branch: %s\n" + + "Default workspace: Native iOS & Android\n" + + "App version: %s", + getSdkVersion(), + getBuildTime(), + getBranchName(), + BuildConfig.VERSION_CODE + ); textView.setText(buildInfo); } + private static String getBuildTime() { + return DateFormat.getDateTimeInstance().format(new Date(BuildConfig.BUILD_TIMESTAMP)); + } + + private static String getSdkVersion() { + if (isEmptyOrUnset(BuildConfig.SDK_VERSION)) return "as source code"; + return BuildConfig.SDK_VERSION; + } + + private static String getBranchName() { + if (isEmptyOrUnset(BuildConfig.BRANCH)) return "local development"; + return BuildConfig.BRANCH + "." + BuildConfig.COMMIT; + } + + private static boolean isEmptyOrUnset(String text) { + // When local properties are not set, they have a string value of "null" + return TextUtils.isEmpty(text) || "null".equalsIgnoreCase(text); + } + @NonNull public static MaterialAlertDialogBuilder createAlertDialog(@NonNull Activity activity) { return new MaterialAlertDialogBuilder(activity) diff --git a/samples/java_layout/src/main/res/layout/activity_dashboard.xml b/samples/java_layout/src/main/res/layout/activity_dashboard.xml index 25f7328f2..35052e862 100644 --- a/samples/java_layout/src/main/res/layout/activity_dashboard.xml +++ b/samples/java_layout/src/main/res/layout/activity_dashboard.xml @@ -177,7 +177,6 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginBottom="@dimen/margin_default" - android:gravity="center" android:textAppearance="@style/TextAppearance.Material3.BodySmall" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" diff --git a/samples/java_layout/src/main/res/layout/activity_login.xml b/samples/java_layout/src/main/res/layout/activity_login.xml index bb5c57e21..ef7d4c973 100644 --- a/samples/java_layout/src/main/res/layout/activity_login.xml +++ b/samples/java_layout/src/main/res/layout/activity_login.xml @@ -127,7 +127,6 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginBottom="@dimen/margin_default" - android:gravity="center" android:textAppearance="@style/TextAppearance.Material3.BodySmall" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" diff --git a/samples/sample-app.gradle b/samples/sample-app.gradle index 7f2450454..b424a3c53 100644 --- a/samples/sample-app.gradle +++ b/samples/sample-app.gradle @@ -20,10 +20,17 @@ android { // cdpApiKey=KEY can be used as a fallback for all sample apps String cdpApiKey = getConfigWithPrefix("cdpApiKey") String siteId = getConfigWithPrefix("siteId") + String sdkVersion = localProperties["sdkVersion"] + String branch = localProperties["branch"] + String commit = localProperties["commit"] // Set build config fields for API keys buildConfigField "String", "CDP_API_KEY", "\"${cdpApiKey}\"" buildConfigField "String", "SITE_ID", "\"${siteId}\"" + buildConfigField "String", "SDK_VERSION", "\"${sdkVersion}\"" + buildConfigField "String", "BRANCH", "\"${branch}\"" + buildConfigField "String", "COMMIT", "\"${commit}\"" + buildConfigField "long", "BUILD_TIMESTAMP", System.currentTimeMillis() + "L" } // Avoid redefining signing configs in sample apps to avoid breaking release // builds (specially on CI servers) From da9afb8f176e77ed9c71b50e7c641f967649bef2 Mon Sep 17 00:00:00 2001 From: Mahmoud Elmorabea Date: Mon, 11 Nov 2024 15:40:30 +0400 Subject: [PATCH 2/3] chore: Change sample app config default value for Test Mode to "NO" (#463) --- .../sample/java_layout/data/model/CustomerIOSDKConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/java_layout/src/main/java/io/customer/android/sample/java_layout/data/model/CustomerIOSDKConfig.java b/samples/java_layout/src/main/java/io/customer/android/sample/java_layout/data/model/CustomerIOSDKConfig.java index 35b76c735..f53da4f00 100644 --- a/samples/java_layout/src/main/java/io/customer/android/sample/java_layout/data/model/CustomerIOSDKConfig.java +++ b/samples/java_layout/src/main/java/io/customer/android/sample/java_layout/data/model/CustomerIOSDKConfig.java @@ -43,7 +43,7 @@ public static CustomerIOSDKConfig getDefaultConfigurations() { CioLogLevel.DEBUG, Region.US.INSTANCE, true, - true, + false, true); } From 7bde5d8e3cfa7983e6f4872aca3802710b45447f Mon Sep 17 00:00:00 2001 From: Mahmoud Elmorabea Date: Mon, 11 Nov 2024 15:41:01 +0400 Subject: [PATCH 3/3] chore: Update sample app version to include dots instead of forwrad slashes coming form branch names (#462) --- samples/fastlane/Fastfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/fastlane/Fastfile b/samples/fastlane/Fastfile index 43179cc80..c7eb36d05 100644 --- a/samples/fastlane/Fastfile +++ b/samples/fastlane/Fastfile @@ -64,7 +64,7 @@ platform :android do path_to_root_directory_sample_app = File.expand_path('../', Dir.pwd) # We are currently in `samples/N/fastlane/` and we need the directory name `samples/N`` name_of_sample_app_module = File.basename(path_to_root_directory_sample_app) # just get the name of the directory I am in now. `samples/N` - new_app_version = get_new_app_version() + new_app_version = get_new_app_version().gsub("/", ".") test_groups = get_build_test_groups() app_package_name = CredentialsManager::AppfileConfig.try_fetch_value(:package_name) # get package_name from Appfile