Skip to content

Commit

Permalink
Feature/fs3 1034 fetch warning (#11)
Browse files Browse the repository at this point in the history
- **Changed**
  - userExposed has been renamed to visitorExposed
- **Added**
  - Flagmetadata now returns campaign name, variation group name and variation name.
  - onVisitorExposed callback
  - Warning when Flags need to be updated
  • Loading branch information
raf-abtasty authored Nov 8, 2023
1 parent a739940 commit 1092282
Show file tree
Hide file tree
Showing 48 changed files with 1,108 additions and 466 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/ci-unitest-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ jobs:
runs-on: ubuntu-latest
if: contains(github.event.head_commit.message, '#ci-auto') == false
steps:
- uses: actions/checkout@v2
- name: set up JDK 1.11
uses: actions/setup-java@v1
- uses: actions/checkout@v3
- name: set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 1.11
distribution: "oracle"
java-version: '17'
- name: Unit tests
run: bash ./gradlew flagship:testAllVariantsWithCoverage
- name: Upload coverage to codecov
Expand Down
26 changes: 17 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,28 @@ jobs:
runs-on: ubuntu-latest
if: contains(github.event.head_commit.message, '#ci-auto') == false
steps:
- uses: actions/checkout@v2
- name: set up JDK 1.11
uses: actions/setup-java@v1
- uses: actions/checkout@v3
- name: set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 1.11
distribution: "oracle"
java-version: "17"
- name: Unit tests
run: bash ./gradlew clean flagship:testAllVariantsWithCoverage
- name: Get version
run: |
echo "FLAGSHIP_VERSION_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Upload Test Report
run: bash <(curl -s https://codecov.io/bash) -f "flagship/build/reports/jacoco/testCommonDebugUnitTestCoverage/testCommonDebugUnitTestCoverage.xml"
# - name: Build and Publish
# env:
# ARTIFACTORY_USER: ${{ secrets.ARTIFACTORY_USER }}
# ARTIFACTORY_KEY: ${{ secrets.ARTIFACTORY_KEY }}
# run: bash ./gradlew clean :flagship:releaseAllVariantsToArtifactory
- name: Build and Publish
env:
SONATYPE_SIGNING_KEY: ${{ secrets.SONATYPE_SIGNING_KEY }}
SONATYPE_SIGNING_PWD: ${{ secrets.SONATYPE_SIGNING_PWD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_REPOSITORY: ${{ secrets.SONATYPE_REPOSITORY }}
run: |
bash ./gradlew clean
bash ./gradlew flagship:assembleRelease
bash ./gradlew publishToSonatype closeSonatypeStagingRepository
bash ./gradlew publishToSonatype -Dvariant=compat closeSonatypeStagingRepository
19 changes: 0 additions & 19 deletions .github/workflows/rollback.yml

This file was deleted.

20 changes: 10 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {
compileSdkVersion 33
compileSdk 34

signingConfigs {
release {
Expand All @@ -26,7 +26,7 @@ android {

applicationId "com.abtasty.flagshipqa"
minSdkVersion 21
targetSdkVersion 33
targetSdk 34
versionCode 1
versionName "1.0"
multiDexEnabled true
Expand All @@ -45,11 +45,11 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '1.8'
jvmTarget = '17'
}

flavorDimensions 'default'
Expand All @@ -70,14 +70,14 @@ dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'com.google.android.material:material:1.10.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.6.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.6.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.7.4'
implementation 'androidx.navigation:navigation-ui-ktx:2.7.4'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation "org.jetbrains.kotlin:kotlin-reflect:1.8.10"
implementation "org.jetbrains.kotlin:kotlin-reflect:1.9.10"

implementation project(path: ':flagship') //Use local project
// implementation 'com.abtasty:flagship-android:3.0.5' //Use remote maven repository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ class ConfigViewModel(val appContext: Application) : AndroidViewModel(appContext
ready()
}
}
flagshipConfig.withOnVisitorExposed { visitorExposed, exposedFlag ->
System.out.println("[OnVisitorExposed] : " + visitorExposed.visitorId + " \n"
+ "key: " + exposedFlag.key + "\n"
+ "value: " + exposedFlag.value + "\n"
+ "Campaign name: " + exposedFlag.metadata.campaignName + "\n"
+ "variation name: " + exposedFlag.metadata.variationName
)
}
Flagship.start(getApplication(), env_id.value!!, api_key.value!!, flagshipConfig.build())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ class ModificationFragment : Fragment() {
})

binding.activate.setOnClickListener {
modificationViewModel.activate(binding.editTextKey.text.toString())
modificationViewModel.activate( binding.editTextKey.text.toString(),
binding.editTextDefault.text.toString(),
binding.spinner.selectedItem.toString())
}

return binding.root
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
import com.abtasty.flagship.main.Flagship
import com.abtasty.flagship.model.Modification
import com.abtasty.flagship.model._Flag
import com.abtasty.flagship.visitor.VisitorDelegate
import org.json.JSONObject
import java.util.concurrent.ConcurrentHashMap
Expand Down Expand Up @@ -34,39 +35,41 @@ class ModificationViewModel(val appContext: Application) : AndroidViewModel(appC
}

fun loadModification() {
var visitorModification : ConcurrentMap<String, Modification> = ConcurrentHashMap()
var visitorFlags: ConcurrentMap<String, _Flag> = ConcurrentHashMap()
try {
visitorModification = readInstanceProperty<VisitorDelegate>(Flagship.getVisitor()!!,
"delegate").modifications
} catch (e : Exception) {

visitorFlags = readInstanceProperty<VisitorDelegate>(
Flagship.getVisitor()!!,
"delegate"
).flags
} catch (e: Exception) {
e.printStackTrace()
}
val json = JSONObject("{}")
for (e in visitorModification) {
if (e.value.value == null)
json.put(e.key, JSONObject.NULL)
for ((key, flag) in visitorFlags) {
if (flag.value == null)
json.put(key, JSONObject.NULL)
else
json.put(e.key, e.value.value)
json.put(key, flag.value)
}
modifications.value = json.toString(4)
}

fun getModification(key: String, default: String, type: String) {
value.value = when (type) {
"String" -> Flagship.getVisitor()?.getModification(key, default)
"Boolean" -> Flagship.getVisitor()?.getModification(key, default.toLowerCase().toBoolean())
fun getTypedValue(type: String, default : String) : Any {
return when (type) {
"String" -> default
"Boolean" -> default.toLowerCase().toBoolean()
"Number" -> {
try {
Flagship.getVisitor()?.getModification(key, default.toInt())
default.toInt()
} catch (e: NumberFormatException) {
try {
Flagship.getVisitor()?.getModification(key, default.toDouble())
default.toDouble()
} catch (e: NumberFormatException) {
try {
Flagship.getVisitor()?.getModification(key, default.toFloat())
default.toFloat()
} catch (e: NumberFormatException) {
try {
Flagship.getVisitor()?.getModification(key, default.toLong())
default.toLong()
} catch (e: NumberFormatException) {
-1
}
Expand All @@ -75,15 +78,26 @@ class ModificationViewModel(val appContext: Application) : AndroidViewModel(appC
}
}
"Json" -> {
Flagship.getVisitor()?.getModification(key, JSONObject()).toString();
JSONObject()
}

else -> "unknown"
}
info.value = Flagship.getVisitor()?.getModificationInfo(key) ?: JSONObject()
}

fun activate(key : String) {
Flagship.getVisitor()?.activateModification(key)
fun getModification(key: String, default: String, type: String) {
Flagship.getVisitor()?.let { visitor ->
value.value = visitor.getModification(key, getTypedValue(type, default))
info.value = visitor.getFlag(key, getTypedValue(type, default)).metadata().toJson()
}

}

fun activate(key: String, default: String, type: String) {
// Flagship.getVisitor()?.activateModification(key)
Flagship.getVisitor()?.let { visitor ->
visitor.getFlag(key, getTypedValue(type, default)).visitorExposed()
}
Toast.makeText(appContext, "Activation sent", Toast.LENGTH_SHORT).show();
}
}
95 changes: 41 additions & 54 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,82 +1,69 @@


buildscript {

/*
releaseAllVariantsToBintray =
- ./gradlew assembleRelease
- ./gradlew artifactoryPublish
- ./gradlew artifactoryPublish -Dvariant=compat
testAllVariantsWithCoverage =
./gradlew clean testCommonDebugUnitTestCoverage
./gradlew clean testCompatDebugUnitTestCoverage
./gradlew publishToSonatype closeSonatypeStagingRepository
./gradlew publishToSonatype -Dvariant=compat closeSonatypeStagingRepository
*/

ext {
kotlin_version = '1.8.20'
artifactory_artifact_id = "flagship-android"
artifactory_repo = "flagship-android"
artifactory_group_id = "com.abtasty"
artifactory_user_org = "abtasty"
artifactory_variant = System.getProperty("variant", "");
}

if (!artifactory_variant.isEmpty()) {
artifactory_artifact_id = artifactory_artifact_id + '-' + artifactory_variant
}

def flagship_version_name = System.getenv('FLAGSHIP_VERSION_NAME')
def flagship_version_code = System.getenv('FLAGSHIP_VERSION_CODE')

def artifactory_user = System.getenv('ARTIFACTORY_USER')
def artifactory_key = System.getenv('ARTIFACTORY_KEY')

if (flagship_version_name != null)
rootProject.ext.flagship_version_name = flagship_version_name
else
rootProject.ext.flagship_version_name = "3.0.5"

if (flagship_version_code != null)
rootProject.ext.flagship_version_code = flagship_version_code
else
rootProject.ext.flagship_version_code = 14

if (artifactory_user != null && artifactory_key != null) {
rootProject.ext.artifactory_user = artifactory_user
rootProject.ext.artifactory_key = artifactory_key
} else {
try {
def keystorePropertiesFile = file(getProjectDir().absolutePath+ "/keystore.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

rootProject.ext.artifactory_user = keystoreProperties.getProperty("artifactory_user")
rootProject.ext.artifactory_key = keystoreProperties.getProperty("artifactory_key")

} catch (Exception e) {
rootProject.ext.artifactory_user = ''
rootProject.ext.artifactory_key = ''
kotlin_version = '1.9.10'
maven_artifact_id = "flagship-android"
maven_repo = "flagship-android"
maven_group_id = "com.abtasty"
maven_user_org = "abtasty"
maven_variant = System.getProperty("variant", "")
if (!maven_variant.isEmpty()) {
maven_artifact_id = maven_artifact_id + '-' + maven_variant
}
flagship_version_name = System.getenv('FLAGSHIP_VERSION_NAME') ?: "3.1.0"
flagship_version_code = System.getenv('FLAGSHIP_VERSION_CODE') ?: 17
sonatype_signing_key = System.getenv('SONATYPE_SIGNING_KEY')
sonatype_signing_pwd = System.getenv('SONATYPE_SIGNING_PWD')
sonatype_username = System.getenv('SONATYPE_USERNAME') ?: ossrhUsername
sonatype_password = System.getenv('SONATYPE_PASSWORD') ?: ossrhPassword
sonatype_repository_id = System.getenv('SONATYPE_REPOSITORY') ?: stagingRepositoryId
}

repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.4.2'
classpath 'com.android.tools.build:gradle:8.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.24.18"
classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:0.9.16"
classpath "io.github.gradle-nexus:publish-plugin:1.3.0"
}
}

plugins {
id 'com.google.devtools.ksp' version '1.9.10-1.0.13' apply false
}

apply plugin: 'io.github.gradle-nexus.publish-plugin'

allprojects {
repositories {
google()
mavenCentral()
}
}

nexusPublishing {
repositories {
sonatype {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
stagingProfileId = sonatype_repository_id
username = sonatype_username
password = sonatype_password
}
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
}

Loading

0 comments on commit 1092282

Please sign in to comment.