Skip to content

Commit

Permalink
Merge branch 'release/0.9.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
usommerl committed Nov 26, 2024
2 parents 03476f5 + 73de371 commit 0e6953f
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 199 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4.1.4
uses: actions/checkout@v4.2.2
- name: Set up JDK
uses: actions/setup-java@v4
with:
Expand All @@ -16,7 +16,7 @@ jobs:
- name: Run tests
run: sbt coverage test coverageReport
- name: Upload coverage reports
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v5
with:
fail_ci_if_error: true
verbose: true
Expand All @@ -27,7 +27,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4.1.4
uses: actions/checkout@v4.2.2
- name: Create GitHub release draft
uses: release-drafter/release-drafter@v6
env:
Expand All @@ -43,14 +43,14 @@ jobs:
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4.1.4
uses: actions/checkout@v4.2.2
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-version: 11
- name: Login to GitHub Container Registry
uses: docker/login-action@v3.1.0
uses: docker/login-action@v3.3.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
Expand All @@ -68,7 +68,7 @@ jobs:
docker tag $IMAGE_GHCR $IMAGE_GCR
echo "image_gcr=$IMAGE_GCR" >> $GITHUB_ENV
- name: Login to Google Container Registry
uses: docker/login-action@v3.1.0
uses: docker/login-action@v3.3.0
with:
registry: eu.gcr.io
username: _json_key
Expand Down
4 changes: 2 additions & 2 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version = "3.8.1"
version = "3.8.3"

maxColumn = 140
align.preset = most
continuationIndent.defnSite = 2
rewrite.rules = [SortImports, AvoidInfix, PreferCurlyFors, RedundantBraces, RedundantParens]
runner.dialect = scala213source3
runner.dialect = scala3
24 changes: 1 addition & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,9 @@
FROM ghcr.io/graalvm/graalvm-ce:ol8-java17-22.3.3 as builder
FROM ghcr.io/graalvm/native-image-community:23.0.1-muslib-ol9 as builder

ARG upx_compression
ARG print_reports
RUN gu install native-image
RUN curl -L https://www.scala-sbt.org/sbt-rpm.repo | tee /etc/yum.repos.d/sbt-rpm.repo && microdnf install sbt git xz

# BEGIN INSTALL PRE-REQUISITES FOR STATIC NATIVE IMAGES WITH GRAAL >= 20.2.0
# See:
# - https://github.com/oracle/graal/issues/2824#issuecomment-685159371
# - https://github.com/oracle/graal/blob/vm-20.3.0/substratevm/StaticImages.md
ARG TOOLCHAIN_DIR="/toolchain"

RUN mkdir ${TOOLCHAIN_DIR} && \
curl -L -o musl.tar.gz https://more.musl.cc/10.2.1/x86_64-linux-musl/x86_64-linux-musl-native.tgz && \
tar -xvzf musl.tar.gz -C ${TOOLCHAIN_DIR} --strip-components 1 && \
rm -f /musl.tar.gz

ENV PATH="$PATH:${TOOLCHAIN_DIR}/bin"
ENV CC="${TOOLCHAIN_DIR}/bin/gcc"

RUN curl -L -o zlib.tar.gz https://zlib.net/fossils/zlib-1.2.12.tar.gz && \
mkdir zlib && tar -xvzf zlib.tar.gz -C zlib --strip-components 1 && cd zlib && \
./configure --static --prefix=${TOOLCHAIN_DIR} && \
make && make install && \
cd / && rm -rf /zlib && rm -f /zlib.tar.gz
#END INSTALL PRE-REQUISITES FOR STATIC NATIVE IMAGES WITH GRAAL >= 20.2.0

COPY . /build
WORKDIR /build
RUN sbt graalvm-native-image:packageBin
Expand Down
31 changes: 14 additions & 17 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
ThisBuild / scalaVersion := "2.13.13"
ThisBuild / organization := "dev.usommerl"
ThisBuild / scalafixDependencies += "com.github.liancheng" %% "organize-imports" % "0.6.0"
ThisBuild / scalaVersion := "3.5.2"
ThisBuild / organization := "dev.usommerl"

ThisBuild / libraryDependencySchemes += "com.softwaremill.sttp.apispec" %% "openapi-model" % "early-semver"
ThisBuild / libraryDependencySchemes += "com.softwaremill.sttp.apispec" %% "apispec-model" % "early-semver"

val v = new {
val apispec = "0.9.0"
val circe = "0.14.6"
val ciris = "3.5.0"
val http4s = "0.23.26"
val odin = "0.13.0"
val tapir = "1.10.5"
val munit = "0.7.29"
val munitCE = "1.0.7"
val apispec = "0.11.3"
val circe = "0.14.10"
val ciris = "3.6.0"
val http4s = "0.23.29"
val odin = "0.14.0"
val tapir = "1.11.9"
val munit = "1.0.2"
val munitCE = "2.0.0"
}

val upx = "UPX_COMPRESSION"
Expand All @@ -22,19 +21,17 @@ lazy val graalnative4s = project
.in(file("."))
.enablePlugins(BuildInfoPlugin, sbtdocker.DockerPlugin, GraalVMNativeImagePlugin)
.settings(
scalacOptions ++= Seq("-Xsource:3-cross"),
libraryDependencies ++= Seq(
compilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"),
"com.softwaremill.sttp.apispec" %% "openapi-circe-yaml" % v.apispec,
"com.softwaremill.sttp.tapir" %% "tapir-core" % v.tapir,
"com.softwaremill.sttp.tapir" %% "tapir-http4s-server" % v.tapir,
"com.softwaremill.sttp.tapir" %% "tapir-json-circe" % v.tapir,
"com.softwaremill.sttp.tapir" %% "tapir-openapi-docs" % v.tapir,
"com.softwaremill.sttp.tapir" %% "tapir-refined" % v.tapir,
"com.softwaremill.sttp.tapir" %% "tapir-swagger-ui" % v.tapir,
"com.github.valskalla" %% "odin-core" % v.odin,
"com.github.valskalla" %% "odin-json" % v.odin,
"com.github.valskalla" %% "odin-slf4j" % v.odin,
"dev.scalafreaks" %% "odin-core" % v.odin,
"dev.scalafreaks" %% "odin-json" % v.odin,
"dev.scalafreaks" %% "odin-slf4j" % v.odin,
"io.circe" %% "circe-core" % v.circe,
"io.circe" %% "circe-generic" % v.circe,
"io.circe" %% "circe-parser" % v.circe,
Expand All @@ -45,7 +42,7 @@ lazy val graalnative4s = project
"org.http4s" %% "http4s-circe" % v.http4s,
"org.http4s" %% "http4s-dsl" % v.http4s,
"org.scalameta" %% "munit" % v.munit % Test,
"org.typelevel" %% "munit-cats-effect-3" % v.munitCE % Test
"org.typelevel" %% "munit-cats-effect" % v.munitCE % Test
),
testFrameworks += new TestFramework("munit.Framework"),
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion, Test / libraryDependencies),
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.9
sbt.version=1.10.5
14 changes: 7 additions & 7 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.0")
addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.0.1")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.2.0")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.12.0")
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.10.0")
addSbtPlugin("org.typelevel" % "sbt-tpolecat" % "0.5.1")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.13.0")
addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.1.0")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.3.0")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.13.1")
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.10.4")
addSbtPlugin("org.typelevel" % "sbt-tpolecat" % "0.5.2")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.11")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.2.2")
addSbtPlugin("se.marcuslonnberg" % "sbt-docker" % "1.11.0")
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ Args = --no-fallback \
--libc=musl \
--enable-http \
--enable-https \
--report-unsupported-elements-at-runtime \
--initialize-at-build-time=scala.Symbol$ \
--install-exit-handlers \
-H:+UnlockExperimentalVMOptions \
-H:+ReportExceptionStackTraces \
-H:+ReportUnsupportedElementsAtRuntime \
-H:+PrintClassInitialization \
-H:+StackTrace \
-H:+JNI \
-H:+RemoveSaturatedTypeFlows \
-H:-SpawnIsolates \
-H:-UseServiceLoaderFeature
60 changes: 0 additions & 60 deletions src/main/resources/META-INF/native-image/reflect-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
{
"name": "eu.timepit.refined.StringInference"
},
{
"name": "eu.timepit.refined.api.Refined"
},
{
"name": "eu.timepit.refined.boolean"
},
Expand Down Expand Up @@ -822,69 +819,12 @@
}
]
},
{
"name": "scala.reflect.api.Exprs"
},
{
"name": "scala.reflect.api.JavaUniverse"
},
{
"name": "scala.reflect.api.Mirror"
},
{
"name": "scala.reflect.api.Quasiquotes"
},
{
"name": "scala.reflect.api.TreeCreator"
},
{
"name": "scala.reflect.api.Trees"
},
{
"name": "scala.reflect.api.TypeCreator"
},
{
"name": "scala.reflect.api.TypeTags"
},
{
"name": "scala.reflect.api.Universe"
},
{
"name": "scala.reflect.api.package"
},
{
"name": "scala.reflect.internal.Symbols$Symbol[]"
},
{
"name": "scala.reflect.internal.Types$Type[]"
},
{
"name": "scala.reflect.internal.annotations.package"
},
{
"name": "scala.reflect.internal.annotations.uncheckedBounds"
},
{
"name": "scala.reflect.macros.blackbox.Context"
},
{
"name": "scala.reflect.macros.internal.macroImpl"
},
{
"name": "scala.reflect.macros.package"
},
{
"name": "scala.reflect.macros.whitebox.Context"
},
{
"name": "scala.reflect.package"
},
{
"name": "scala.reflect.runtime.JavaMirrors$JavaMirror$JavaAnnotationProxy[]"
},
{
"name": "scala.reflect.runtime.package"
},
{
"name": "scala.runtime.AbstractFunction0"
},
Expand Down
48 changes: 22 additions & 26 deletions src/main/scala/app/Api.scala
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
package app

import cats.Applicative
import cats.data.Kleisli
import cats.effect.kernel.Async
import cats.implicits._
import cats.syntax.all.*
import dev.usommerl.BuildInfo
import eu.timepit.refined.api.Refined
import eu.timepit.refined.auto._
import eu.timepit.refined.collection._
import io.circe.generic.auto._
import eu.timepit.refined.collection.*
import io.circe.generic.auto.*
import org.http4s.{HttpRoutes, Request, Response}
import org.http4s.dsl.Http4sDsl
import org.http4s.headers.Location
import org.http4s.implicits._
import org.http4s.implicits.*
import org.http4s.server.middleware.CORS
import sttp.model.StatusCode
import sttp.apispec.openapi.OpenAPI
import sttp.apispec.Tag
import sttp.apispec.openapi.Info as OpenApiInfo
import sttp.apispec.openapi.Server
import sttp.apispec.openapi.circe.yaml._
import sttp.tapir._
import sttp.tapir.codec.refined._
import sttp.tapir.docs.openapi._
import sttp.tapir.generic.auto._
import sttp.apispec.openapi.circe.yaml.*
import sttp.tapir.*
import sttp.tapir.codec.refined.*
import sttp.tapir.docs.openapi.*
import sttp.tapir.generic.auto.*
import sttp.tapir.json.circe.jsonBody
import sttp.tapir.server.ServerEndpoint
import sttp.tapir.server.http4s.Http4sServerInterpreter
Expand All @@ -39,7 +37,7 @@ object Api {

val docs: OpenAPI = OpenAPIDocsInterpreter()
.toOpenAPI(apis.flatMap(_.endpoints), OpenApiInfo(BuildInfo.name, BuildInfo.version, description = config.description))
.servers(List(Server(config.serverUrl)))
.servers(List(Server(config.server.toString)))
.tags(apis.map(_.tag))

val swaggerUi: HttpRoutes[F] = Http4sServerInterpreter().toRoutes(SwaggerUI[F](docs.toYaml))
Expand All @@ -51,7 +49,7 @@ object Api {
}

object Examples {
def apply[F[_]: Async]()(implicit F: Applicative[F]) = new TapirApi[F] {
def apply[F[_]: Async]() = new TapirApi[F] {
override val tag: Tag = Tag("Getting started", None)
override lazy val serverEndpoints: List[ServerEndpoint[Any, F]] = List(info, hello)
type NonEmptyString = String Refined NonEmpty
Expand All @@ -64,17 +62,15 @@ object Examples {
.out(jsonBody[Info])
.errorOut(statusCode)
.serverLogic(_ =>
F.pure(
Info(
BuildInfo.name,
BuildInfo.version,
System.getProperty("java.vm.version"),
BuildInfo.scalaVersion,
BuildInfo.sbtVersion,
BuildInfo.builtAtString,
BuildInfo.test_libraryDependencies.sorted
).asRight
)
Info(
BuildInfo.name,
BuildInfo.version,
System.getProperty("java.vm.version"),
BuildInfo.scalaVersion,
BuildInfo.sbtVersion,
BuildInfo.builtAtString,
BuildInfo.test_libraryDependencies.sorted
).asRight.pure
)

private val hello: ServerEndpoint.Full[Unit, Unit, Option[NonEmptyString], StatusCode, String, Any, F] =
Expand All @@ -85,7 +81,7 @@ object Examples {
.in(query[Option[NonEmptyString]]("name").description("Optional name to greet"))
.out(stringBody)
.errorOut(statusCode)
.serverLogic(name => F.pure(s"Hello ${name.getOrElse("World")}!".asRight))
.serverLogic(name => s"Hello ${name.getOrElse("World")}!".asRight.pure)

case class Info(
name: String,
Expand All @@ -102,6 +98,6 @@ object Examples {
abstract class TapirApi[F[_]: Async] {
def tag: Tag
def serverEndpoints: List[ServerEndpoint[Any, F]]
def endpoints: List[Endpoint[_, _, _, _, _]] = serverEndpoints.map(_.endpoint)
def endpoints: List[Endpoint[?, ?, ?, ?, ?]] = serverEndpoints.map(_.endpoint)
def routes: HttpRoutes[F] = Http4sServerInterpreter().toRoutes(serverEndpoints)
}
Loading

0 comments on commit 0e6953f

Please sign in to comment.