Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
Merge branch 'main' into metadatas
Browse files Browse the repository at this point in the history
  • Loading branch information
vahidlazio authored Jul 14, 2023
2 parents 80f9d2b + 885e7e7 commit caad9b6
Show file tree
Hide file tree
Showing 13 changed files with 197 additions and 138 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Release
on:
push:
tags:
- 'v*'

jobs:
publish:
name: Release Openfeature SDK
runs-on: ubuntu-latest

steps:
- name: Cache Gradle and wrapper
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-
- uses: actions/checkout@v1

- name: Set up JDK 12
uses: actions/setup-java@v1
with:
java-version: 12

- name: Grant Permission for Gradlew to Execute
run: chmod +x gradlew

- name: Build AAR ⚙️🛠
run: bash ./gradlew :openfeature:assemble
- name: Create Release ✅
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.TOKEN_PUBLISH }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: true
prerelease: false

- name: Upload Openfeature SDK AAR 🗳
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.TOKEN_PUBLISH }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: OpenFeature/build/outputs/aar/OpenFeature-release.aar
asset_name: openfeature-sdk.aar
asset_content_type: application/aar
42 changes: 26 additions & 16 deletions OpenFeature/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ktlint-disable max-line-length
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
Expand Down Expand Up @@ -27,17 +28,11 @@ android {
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
publishing {
singleVariant("release") {
withSourcesJar()
withJavadocJar()
}
jvmTarget = JavaVersion.VERSION_11.toString()
}
}

Expand All @@ -48,16 +43,31 @@ dependencies {
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.1")
}

publishing {
publications {
register<MavenPublication>("release") {
groupId = "dev.openfeature"
artifactId = "kotlin-sdk"
version = "0.0.1-SNAPSHOT"
afterEvaluate {
publishing {
publications {
register<MavenPublication>("release") {
groupId = "dev.openfeature"
artifactId = "kotlin-sdk"
version = "0.0.1-SNAPSHOT"

afterEvaluate {
from(components["release"])
artifact(androidSourcesJar.get())

pom {
name.set("OpenfeatureSDK")
}
}
}
}
}

val androidSourcesJar by tasks.registering(Jar::class) {
archiveClassifier.set("sources")
from(android.sourceSets.getByName("main").java.srcDirs)
}

// Assembling should be performed before publishing package
tasks.named("publish") {
dependsOn("assemble")
}
2 changes: 2 additions & 0 deletions OpenFeature/jitpack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
jdk:
- openjdk11
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dev.openfeature.sdk

class MutableContext
(private var targetingKey: String = "", attributes: MutableMap<String, Value> = mutableMapOf()) : EvaluationContext {
private var structure: MutableStructure = MutableStructure(attributes)
class ImmutableContext
(private var targetingKey: String = "", attributes: Map<String, Value> = mapOf()) : EvaluationContext {
private var structure: ImmutableStructure = ImmutableStructure(attributes)
override fun getTargetingKey(): String {
return targetingKey
}
Expand All @@ -19,19 +19,14 @@ class MutableContext
return structure.getValue(key)
}

override fun asMap(): MutableMap<String, Value> {
override fun asMap(): Map<String, Value> {
return structure.asMap()
}

override fun asObjectMap(): Map<String, Any?> {
return structure.asObjectMap()
}

fun add(key: String, value: Value): MutableContext {
structure.add(key, value)
return this
}

override fun hashCode(): Int {
var result = targetingKey.hashCode()
result = 31 * result + structure.hashCode()
Expand All @@ -42,7 +37,7 @@ class MutableContext
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as MutableContext
other as ImmutableContext

if (targetingKey != other.targetingKey) return false
if (structure != other.structure) return false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.openfeature.sdk

class MutableStructure(private var attributes: MutableMap<String, Value> = mutableMapOf()) : Structure {
class ImmutableStructure(private var attributes: Map<String, Value> = mapOf()) : Structure {
override fun keySet(): Set<String> {
return attributes.keys
}
Expand All @@ -9,19 +9,14 @@ class MutableStructure(private var attributes: MutableMap<String, Value> = mutab
return attributes[key]
}

override fun asMap(): MutableMap<String, Value> {
override fun asMap(): Map<String, Value> {
return attributes
}

override fun asObjectMap(): Map<String, Any?> {
return attributes.mapValues { convertValue(it.value) }
}

fun add(key: String, value: Value): MutableStructure {
attributes[key] = value
return this
}

private fun convertValue(value: Value): Any? {
return when (value) {
is Value.List -> value.list.map { t -> convertValue(t) }
Expand All @@ -43,7 +38,7 @@ class MutableStructure(private var attributes: MutableMap<String, Value> = mutab
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as MutableStructure
other as ImmutableStructure

if (attributes != other.attributes) return false

Expand Down
2 changes: 1 addition & 1 deletion OpenFeature/src/main/java/dev/openfeature/sdk/Structure.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dev.openfeature.sdk
interface Structure {
fun keySet(): Set<String>
fun getValue(key: String): Value?
fun asMap(): MutableMap<String, Value>
fun asMap(): Map<String, Value>
fun asObjectMap(): Map<String, Any?>

// Make sure these are implemented for correct object comparisons
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ class DeveloperExperienceTests {

@Test
fun testSimpleBooleanFlag() = runTest {
OpenFeatureAPI.setProvider(NoOpProvider(), MutableContext())
OpenFeatureAPI.setProvider(NoOpProvider(), ImmutableContext())
val booleanValue = OpenFeatureAPI.getClient().getBooleanValue("test", false)
Assert.assertFalse(booleanValue)
}

@Test
fun testClientHooks() = runTest {
OpenFeatureAPI.setProvider(NoOpProvider(), MutableContext())
OpenFeatureAPI.setProvider(NoOpProvider(), ImmutableContext())
val client = OpenFeatureAPI.getClient()

val hook = GenericSpyHookMock()
Expand All @@ -38,7 +38,7 @@ class DeveloperExperienceTests {

@Test
fun testEvalHooks() = runTest {
OpenFeatureAPI.setProvider(NoOpProvider(), MutableContext())
OpenFeatureAPI.setProvider(NoOpProvider(), ImmutableContext())
val client = OpenFeatureAPI.getClient()

val hook = GenericSpyHookMock()
Expand All @@ -50,7 +50,7 @@ class DeveloperExperienceTests {

@Test
fun testBrokenProvider() = runTest {
OpenFeatureAPI.setProvider(AlwaysBrokenProvider(), MutableContext())
OpenFeatureAPI.setProvider(AlwaysBrokenProvider(), ImmutableContext())
val client = OpenFeatureAPI.getClient()

val details = client.getBooleanDetails("test", false)
Expand Down
Loading

0 comments on commit caad9b6

Please sign in to comment.