Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Improve sample apps build info #458

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/reusable_build_sample_apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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" +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably rather have that data being injected via secrets than hardcode? cause the next time we wish to change source, we can do that with CI but we will need to do another release just to change this hardcoded string.

or skip it if we don't want to have it via secret?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point about trying to make the value dynamic.

However, the CI values (if it's secrets of env variables) are picked up when you build a new samples app version. So even if it's done using secrets, you still need another release to pick the new values, they won't change for existing builds.

Also I don't see those default workspaces changing too often.

If you are okay with it, let's KISS this one and the first time we have to change it, we make it dynamic 😄

"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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion samples/java_layout/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions samples/sample-app.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading