Skip to content

Commit

Permalink
Add OpenFeature SDK (#10)
Browse files Browse the repository at this point in the history
Beginnings of an [OpenFeature](https://openfeature.dev/) SDK, with a
Flipt provider

Only supporting boolean evaluation for now because I'm lazy and need it
  • Loading branch information
alexcardell authored Sep 6, 2024
1 parent 8ef86fb commit aa154b8
Show file tree
Hide file tree
Showing 33 changed files with 1,427 additions and 149 deletions.
22 changes: 19 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ jobs:
runs-on: ${{ matrix.os }}
timeout-minutes: 60
steps:
- name: Install sbt
if: contains(runner.os, 'macos')
run: brew install sbt

- name: Checkout current branch (full)
uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -107,6 +111,10 @@ jobs:
java: [temurin@8]
runs-on: ${{ matrix.os }}
steps:
- name: Install sbt
if: contains(runner.os, 'macos')
run: brew install sbt

- name: Checkout current branch (full)
uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -211,13 +219,17 @@ jobs:

dependency-submission:
name: Submit Dependencies
if: github.event_name != 'pull_request'
if: github.event.repository.fork == false && github.event_name != 'pull_request'
strategy:
matrix:
os: [ubuntu-latest]
java: [temurin@8]
runs-on: ${{ matrix.os }}
steps:
- name: Install sbt
if: contains(runner.os, 'macos')
run: brew install sbt

- name: Checkout current branch (full)
uses: actions/checkout@v4
with:
Expand All @@ -239,7 +251,7 @@ jobs:
- name: Submit Dependencies
uses: scalacenter/sbt-dependency-submission@v2
with:
modules-ignore: rootjs_2.13 rootjs_3 docs_2.13 docs_3 rootjvm_2.13 rootjvm_3 rootnative_2.13 rootnative_3
modules-ignore: ff4s-open-feature-provider-flipt-it_2.13 ff4s-open-feature-provider-flipt-it_3 ff4s-open-feature-provider-flipt_native0.4_2.13 ff4s-open-feature-provider-flipt_native0.4_3 ff4s-open-feature-sdk_native0.4_2.13 ff4s-open-feature-sdk_native0.4_3 ff4s-open-feature-provider-flipt_2.13 ff4s-open-feature-provider-flipt_3 ff4s-open-feature-sdk_2.13 ff4s-open-feature-sdk_3 rootjs_2.13 rootjs_3 docs_2.13 docs_3 ff4s-open-feature-provider-flipt_sjs1_2.13 ff4s-open-feature-provider-flipt_sjs1_3 rootjvm_2.13 rootjvm_3 rootnative_2.13 rootnative_3 ff4s-open-feature-sdk_sjs1_2.13 ff4s-open-feature-sdk_sjs1_3
configs-ignore: test scala-tool scala-doc-tool test-internal

site:
Expand All @@ -250,6 +262,10 @@ jobs:
java: [temurin@11]
runs-on: ${{ matrix.os }}
steps:
- name: Install sbt
if: contains(runner.os, 'macos')
run: brew install sbt

- name: Checkout current branch (full)
uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -286,7 +302,7 @@ jobs:

- name: Publish site
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
uses: peaceiris/actions-gh-pages@v3.9.3
uses: peaceiris/actions-gh-pages@v4.0.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: site/target/docs/site
Expand Down
2 changes: 2 additions & 0 deletions .sbtopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-J-Xmx4G
-J-Xss2M
35 changes: 0 additions & 35 deletions .scalafix-base.conf

This file was deleted.

4 changes: 2 additions & 2 deletions .scalafix.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ rules = [
NoValInForComprehension
# ProcedureSyntax
RedundantSyntax
# OrganizeImports
# RemoveUnused
# OrganizeImports
# RemoveUnused
]

# run on compile (not explicitly)
Expand Down
2 changes: 2 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
version = 3.7.1
include ".scalafmt-base.conf"

runner.dialect = scala3
159 changes: 109 additions & 50 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// https://typelevel.org/sbt-typelevel/faq.html#what-is-a-base-version-anyway
ThisBuild / tlBaseVersion := "0.0" // your current series x.y

ThisBuild / organization := "io.cardell"
ThisBuild / organization := "io.cardell"
ThisBuild / organizationName := "Alex Cardell"
ThisBuild / startYear := Some(2023)
ThisBuild / licenses := Seq(License.Apache2)
ThisBuild / startYear := Some(2023)
ThisBuild / licenses := Seq(License.Apache2)

ThisBuild / developers := List(
// your GitHub handle and name
tlGitHubDev("alexcardell", "Alex Cardell")
Expand All @@ -15,70 +16,128 @@ ThisBuild / tlSonatypeUseLegacyHost := false

// publish website from this branch
ThisBuild / tlSitePublishBranch := Some("main")
ThisBuild / tlSiteKeepFiles := false
ThisBuild / tlSiteKeepFiles := false

val Scala213 = "2.13.12"
val Scala33 = "3.3.3"
val Scala33 = "3.3.3"
ThisBuild / crossScalaVersions := Seq(Scala213, Scala33)
ThisBuild / scalaVersion := Scala213 // the default Scala
ThisBuild / scalaVersion := Scala213 // the default Scala

// hack until integration tests can run in parallel
// ThisBuild / Test / parallelExecution := false
Global / concurrentRestrictions += Tags.limit(Tags.Test, 1)

lazy val projects = Seq(
`flipt-sdk-server`,
`flipt-sdk-server-it`
`flipt-sdk-server-it`,
`open-feature-sdk`,
`open-feature-provider-flipt`,
`open-feature-provider-flipt-it`
)

lazy val commonDependencies = Seq(
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-core" % "2.10.0",
"org.typelevel" %%% "cats-effect" % "3.5.3",
"org.scalameta" %%% "munit" % "1.0.0-RC1" % Test,
"org.typelevel" %%% "munit-cats-effect" % "2.0.0-M5" % Test
"org.typelevel" %%% "cats-core" % "2.10.0",
"org.typelevel" %%% "cats-effect" % "3.5.3",
"org.scalameta" %%% "munit" % "1.0.0-RC1" % Test,
"org.typelevel" %%% "munit-cats-effect" % "2.0.0-M5" % Test
)
)

lazy val root = tlCrossRootProject.aggregate(projects: _*)

lazy val `flipt-sdk-server` =
crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Full)
.in(file("flipt/sdk-server"))
.settings(commonDependencies)
.settings(
name := "ff4s-flipt-sdk-server",
libraryDependencies ++= Seq(
"org.http4s" %%% "http4s-client" % "0.23.26",
"org.http4s" %%% "http4s-ember-client" % "0.23.26",
"org.http4s" %%% "http4s-circe" % "0.23.26",
"io.circe" %%% "circe-core" % "0.14.7",
"io.circe" %%% "circe-parser" % "0.14.7",
"io.circe" %%% "circe-generic" % "0.14.7"
)
lazy val `flipt-sdk-server` = crossProject(
JVMPlatform,
JSPlatform,
NativePlatform
)
.crossType(CrossType.Full)
.in(file("flipt/sdk-server"))
.settings(commonDependencies)
.settings(
name := "ff4s-flipt-sdk-server",
libraryDependencies ++= Seq(
"org.http4s" %%% "http4s-client" % "0.23.26",
"org.http4s" %%% "http4s-ember-client" % "0.23.26",
"org.http4s" %%% "http4s-circe" % "0.23.26",
"io.circe" %%% "circe-core" % "0.14.7",
"io.circe" %%% "circe-parser" % "0.14.7",
"io.circe" %%% "circe-generic" % "0.14.7"
)
)

lazy val `flipt-sdk-server-it` =
crossProject(JVMPlatform)
.crossType(CrossType.Pure)
.in(file("flipt/sdk-server-it"))
.dependsOn(`flipt-sdk-server`)
.settings(commonDependencies)
.settings(
libraryDependencies ++= Seq(
"com.dimafeng" %% "testcontainers-scala-munit" % "0.41.3" % Test
)
lazy val `flipt-sdk-server-it` = crossProject(JVMPlatform)
.crossType(CrossType.Pure)
.in(file("flipt/sdk-server-it"))
.settings(commonDependencies)
.settings(
libraryDependencies ++= Seq(
"com.dimafeng" %% "testcontainers-scala-munit" % "0.41.3" % Test
)
)
.dependsOn(`flipt-sdk-server`)

lazy val docs =
project
.in(file("site"))
.enablePlugins(TypelevelSitePlugin)
.settings(
tlSiteHelium := {
import laika.helium.config.IconLink
import laika.helium.config.HeliumIcon
import laika.ast.Path.Root
tlSiteHelium.value.site.topNavigationBar(
homeLink = IconLink.internal(Root / "index.md", HeliumIcon.home)
)
}
lazy val `open-feature-sdk` = crossProject(
JVMPlatform,
JSPlatform,
NativePlatform
)
.crossType(CrossType.Pure)
.in(file("open-feature/sdk"))
.enablePlugins(NoPublishPlugin)
.settings(commonDependencies)
.settings(
name := "ff4s-open-feature-sdk",
libraryDependencies ++= Seq(
"io.circe" %%% "circe-generic" % "0.14.7"
)
.dependsOn(`flipt-sdk-server`.jvm)
)

lazy val `open-feature-provider-flipt` = crossProject(
JVMPlatform,
JSPlatform,
NativePlatform
)
.crossType(CrossType.Pure)
.in(file("open-feature/provider-flipt"))
.enablePlugins(NoPublishPlugin)
.settings(commonDependencies)
.settings(
name := "ff4s-open-feature-provider-flipt"
)
.dependsOn(
`open-feature-sdk`,
`flipt-sdk-server`
)

lazy val `open-feature-provider-flipt-it` = crossProject(JVMPlatform)
.crossType(CrossType.Pure)
.in(file("open-feature/provider-flipt-it"))
.enablePlugins(NoPublishPlugin)
.settings(commonDependencies)
.settings(
name := "ff4s-open-feature-provider-flipt-it",
libraryDependencies ++= Seq(
"com.dimafeng" %% "testcontainers-scala-munit" % "0.41.3" % Test
)
)
.dependsOn(
`open-feature-provider-flipt`
)

lazy val docs = project
.in(file("site"))
.enablePlugins(TypelevelSitePlugin)
.settings(
tlSiteHelium := {
import laika.helium.config.IconLink
import laika.helium.config.HeliumIcon
import laika.ast.Path.Root
tlSiteHelium.value.site.topNavigationBar(
homeLink = IconLink.internal(Root / "index.md", HeliumIcon.home)
)
}
)
.dependsOn(`flipt-sdk-server`.jvm)

addCommandAlias("fix", "headerCreateAll;scalafixAll;scalafmtAll;scalafmtSbt")
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import com.dimafeng.testcontainers.ContainerDef
import com.dimafeng.testcontainers.DockerComposeContainer
import com.dimafeng.testcontainers.ExposedService
import com.dimafeng.testcontainers.munit.TestContainerForAll
import io.cardell.ff4s.flipt.auth.AuthenticationStrategy
import io.circe.Decoder
import io.circe.generic.semiauto.deriveDecoder
import java.io.File
import munit.CatsEffectSuite
import org.http4s.Uri
import org.http4s.ember.client.EmberClientBuilder
import org.testcontainers.containers.wait.strategy.Wait

import java.io.File
import io.cardell.ff4s.flipt.auth.AuthenticationStrategy

class FliptApiImplItTest extends CatsEffectSuite with TestContainerForAll {

Expand All @@ -43,10 +43,11 @@ class FliptApiImplItTest extends CatsEffectSuite with TestContainerForAll {
)

def api(containers: Containers): Resource[IO, FliptApi[IO]] = {
val flipt = containers
.asInstanceOf[DockerComposeContainer]
.getContainerByServiceName("flipt")
.get
val flipt =
containers
.asInstanceOf[DockerComposeContainer]
.getContainerByServiceName("flipt")
.get

val url = Uri
.fromString(
Expand Down Expand Up @@ -119,6 +120,7 @@ class FliptApiImplItTest extends CatsEffectSuite with TestContainerForAll {
}

case class TestVariant(field: String, intField: Int)

object TestVariant {
implicit val decoder: Decoder[TestVariant] = deriveDecoder
}
Expand Down Expand Up @@ -166,4 +168,5 @@ class FliptApiImplItTest extends CatsEffectSuite with TestContainerForAll {
}
}
}

}
Loading

0 comments on commit aa154b8

Please sign in to comment.