Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…nch-deep-linking-attribution into gdeluna-branch/SDK-2104
  • Loading branch information
gdeluna-branch committed Oct 11, 2023
2 parents 10aa606 + 452a473 commit 2f29f7a
Show file tree
Hide file tree
Showing 17 changed files with 490 additions and 230 deletions.
96 changes: 96 additions & 0 deletions .github/workflows/sync-readme-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Update Version History on Readme

on:
release:
types: [published]

jobs:
update-changelog:
runs-on: ubuntu-latest

steps:
- name: Format and publish release notes to version history doc
id: update
run: |
# Get release name, body, and date from the release event
release_name="${{ github.event.release.tag_name }}"
release_body="${{ github.event.release.body }}"
release_date=$(date -d "${{ github.event.release.published_at }}" +"%Y-%B-%d")
# Format release notes
formatted_notes="## v$release_name\n\n**($release_date)**\n\n$release_body"
# Get existing version history page
existing_content=$(curl --request GET \
--url https://dash.readme.com/api/v1/docs/android-version-history \
--header 'accept: application/json' \
--header "authorization: Basic ${{ secrets.readme_api_key_base64 }}" \
| jq -r '.body')
# Prepend new release notes to existing content
new_content=$(echo -e "$formatted_notes\n\n$existing_content")
payload=$(jq -n --arg nc "$new_content" '{"body": $nc}')

# Update version history page with new release notes
curl --request PUT \
--url https://dash.readme.com/api/v1/docs/android-version-history \
--header 'accept: application/json' \
--header "authorization: Basic ${{ secrets.readme_api_key_base64 }}" \
--header 'content-type: application/json' \
--data "$payload"

- name: Announce New Release in Slack
uses: slackapi/[email protected]
with:
channel-id: "CDFGXRM9S"
payload: |
{
"text": "New Release: Branch Android SDK v${{ github.event.release.tag_name }}",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": ":rocket: New Release: Branch Android SDK v${{ github.event.release.tag_name }}",
"emoji": true
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":star: *What's New*"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ${{ toJSON(github.event.release.body) }}
}
},
{
"type": "divider"
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": ":git: GitHub Release",
"emoji": true
},
"value": "github",
"action_id": "github",
"url": "${{ github.event.release.html_url }}"
}
]
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_SDK_BOT_TOKEN }}
39 changes: 39 additions & 0 deletions .github/workflows/unit-and-instrumented-tests-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
with:
name: unit-test-api-level-$API_MIN
path: ./Branch-SDK/build/

instrumented-test-api-level-min:
name: instrumented-test-api-level-$API_MIN
runs-on: macos-latest
Expand Down Expand Up @@ -66,6 +67,44 @@ jobs:
with:
name: instrumented-test-api-level-$API_MIN
path: ./Branch-SDK/build/

jacoco-test-coverage-api-level-min:
name: jacoco-test-coverage-api-level-$API_MIN
if: ${{ always() && contains(join(needs.*.result, ','), 'success') }}
needs: [unit-test-api-level-min, instrumented-test-api-level-min]
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v3
# create an emulator with google apis, runs on java 8
- name: Create Android emulator
run: |
echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --licenses
echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install "system-images;android-"$API_MIN";google_apis;x86_64"
echo "no" | $ANDROID_HOME/tools/bin/avdmanager --verbose create avd --force --name test --package "system-images;android-"$API_MIN";google_apis;x86_64"
# boots and waits for the emulator to be ready
- name: Launch Emulator
run: |
echo "Starting emulator and waiting for boot to complete."
nohup $ANDROID_HOME/tools/emulator -avd test -no-audio -no-boot-anim -camera-back none -camera-front none -qemu -m 2048 2>&1 &
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do echo "waiting..."; sleep 1; done; input keyevent 82'
echo "Emulator has finished booting"
# repo's gradle is configured to run on java 17
- name: Setup java 17 for gradle
uses: actions/setup-java@v3
with:
distribution: ${{ env.JAVA_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
- name: Run Coverage
run: |
./gradlew :Branch-SDK:jacocoTestReport --info
- name: Upload Coverage Test Report
if: success()
uses: codecov/codecov-action@v3
with:
file: ./Branch-SDK/build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml
fail_ci_if_error: true

unit-test-api-level-current:
name: unit-test-api-level-$API_CURRENT
runs-on: macos-latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.app.Activity;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
Expand All @@ -26,6 +25,7 @@ protected void onCreate(Bundle savedInstanceState) {
setupDisableAdNetworkCalloutsSwitch();
setupPrepHelperView();
setupRetryEditText();
setupApiUrlText();
}

void setupRetryEditText() {
Expand All @@ -35,21 +35,40 @@ void setupRetryEditText() {

retryEditText.setText(Integer.toString(currentRetries));

retryEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_DONE) {
int retries = Integer.valueOf(textView.getText().toString());
PrefHelper.getInstance(SettingsActivity.this).setRetryCount(retries);

InputMethodManager imm = (InputMethodManager)getSystemService(SettingsActivity.this.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(retryEditText.getWindowToken(), 0);

Toast.makeText(getApplicationContext(), "Set Network Retries to " + retries, Toast.LENGTH_SHORT).show();
return true;
}
return false;
retryEditText.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_DONE) {
int retries = Integer.parseInt(textView.getText().toString());
PrefHelper.getInstance(SettingsActivity.this).setRetryCount(retries);

InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(retryEditText.getWindowToken(), 0);

Toast.makeText(getApplicationContext(), "Set Network Retries to " + retries, Toast.LENGTH_SHORT).show();
return true;
}
return false;
});
}

void setupApiUrlText() {
final EditText apiUrlText = findViewById(R.id.api_url_text);
final PrefHelper prefHelper = PrefHelper.getInstance(this);
String currentApiUrl = prefHelper.getAPIBaseUrl();

apiUrlText.setText(currentApiUrl);

apiUrlText.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_DONE) {
String newApiUrl = textView.getText().toString();
Branch.getInstance().setAPIUrl(newApiUrl);

InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(apiUrlText.getWindowToken(), 0);

Toast.makeText(getApplicationContext(), "Set API Base URL to " + newApiUrl, Toast.LENGTH_SHORT).show();
return true;
}
return false;
});
}

Expand Down
22 changes: 22 additions & 0 deletions Branch-SDK-TestBed/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,28 @@

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
style="@style/testbed_text_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="API Base URL" />

<EditText
android:id="@+id/api_url_text"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:gravity="center"
android:inputType="text"
android:maxLines="1"
android:hint="api2.branch.io" />

</LinearLayout>

<TextView
android:id="@+id/prefhelper_text_view"
style="@style/testbed_text_view"
Expand Down
30 changes: 30 additions & 0 deletions Branch-SDK/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ plugins {
`maven-publish`
signing
id("org.gradle.test-retry") version "1.5.3"
id("jacoco")
}
val coroutinesVersion = "1.6.4"
jacoco {
toolVersion = "0.8.10"
}

dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to "*.jar")))
Expand Down Expand Up @@ -92,6 +96,7 @@ android {

debug {
enableUnitTestCoverage = true
enableAndroidTestCoverage = true
buildConfigField("long", "VERSION_CODE", VERSION_CODE)
buildConfigField("String", "VERSION_NAME", VERSION_NAME.wrapInQuotes())
}
Expand Down Expand Up @@ -274,5 +279,30 @@ tasks {
retry {
maxRetries.set(3)
}
configure<JacocoTaskExtension> {
isIncludeNoLocationClasses = true
excludes = listOf("jdk.internal.*")
}
}
}

tasks.create<JacocoReport>("jacocoTestReport") {
group = "Reporting"
description = "Generate Jacoco code coverage reports after running tests."
dependsOn("testDebugUnitTest","createDebugCoverageReport")
reports {
xml.required.set(true)
html.required.set(true)
}
sourceDirectories.setFrom("${project.projectDir}/src/main/java")
classDirectories.setFrom("${project.buildDir}/intermediates/javac/debug/classes")
executionData.setFrom(
fileTree(project.buildDir) {
include(
"jacoco/testDebugUnitTest.exec",
"outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec",
"outputs/code_coverage/debugAndroidTest/connected/**/*.ec",
)
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,26 @@ public void testGetAPIBaseUrl() {

@Test
public void testSetAPIUrl_Example() {
PrefHelper.setAPIUrl("https://www.example.com/");
prefHelper.setAPIUrl("https://www.example.com/");
String actual = prefHelper.getAPIBaseUrl();
Assert.assertEquals("https://www.example.com/", actual);
}

@Test
public void testSetAPIUrl_InvalidHttp() {
PrefHelper.setAPIUrl("http://www.example.com/");
prefHelper.setAPIUrl("http://www.example.com/");
assertDefaultURL();
}

@Test
public void testSetAPIUrl_InvalidNull() {
PrefHelper.setAPIUrl(null);
prefHelper.setAPIUrl(null);
assertDefaultURL();
}

@Test
public void testSetAPIUrl_InvalidEmpty() {
PrefHelper.setAPIUrl("");
prefHelper.setAPIUrl("");
assertDefaultURL();
}

Expand Down
Loading

0 comments on commit 2f29f7a

Please sign in to comment.