Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions .github/mergify.yml

This file was deleted.

50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: CI

on:
push:
branches: [ base ]
pull_request:

jobs:
test:

runs-on: ubuntu-latest

strategy:
matrix:
scala:
- 3.3.8

steps:
- uses: actions/checkout@v7

- uses: coursier/cache-action@v8

- name: setup Java 17
uses: actions/setup-java@v5
with:
java-version: '17'
distribution: 'temurin'
cache: 'sbt'

- name: setup SBT
uses: sbt/setup-sbt@v1

- name: check code ${{ matrix.scala }}
run: sbt "++${{ matrix.scala }}; clean; check"

- name: build ${{ matrix.scala }}
run: sbt "++${{ matrix.scala }}; clean; coverage; test; coverageAggregate"

- name: locate coverage report
id: coverage
if: success()
run: echo "file=$(find . -path '*/coverage-report/cobertura.xml' | head -1)" >> "$GITHUB_OUTPUT"

- name: test coverage
if: success()
uses: coverallsapp/github-action@v2
with:
file: ${{ steps.coverage.outputs.file }}
format: cobertura
flag-name: Scala ${{ matrix.scala }}
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Publish new Release
name: Publish Release

on:
release:
types: [published]
branches: [base]
push:
tags:
- 'v*'

jobs:
release:
uses: evolution-gaming/scala-github-actions/.github/workflows/release.yml@v1
uses: evolution-gaming/scala-github-actions/.github/workflows/release.yml@v5
secrets: inherit
29 changes: 0 additions & 29 deletions .github/workflows/scala-steward.yml

This file was deleted.

53 changes: 0 additions & 53 deletions .github/workflows/scala.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ project/**/metals.sbt
.idea
.bsp
.vscode
.DS_Store
.DS_Store
target/
5 changes: 0 additions & 5 deletions .scalafix.conf

This file was deleted.

6 changes: 4 additions & 2 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.7.2"
version = "3.11.4"
runner.dialect = scala3

maxColumn = 120
Expand All @@ -8,6 +8,8 @@ indent.main = 4

align.preset = most

rewrite.scala3 = common

rewrite.scala3.insertEndMarkerMinLines = 7

rewrite.scala3.removeEndMarkerMaxLines = 5
rewrite.scala3.removeEndMarkerMaxLines = 5
17 changes: 12 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@ ThisBuild / organizationHomepage := Some(url("https://evolution.com"))

ThisBuild / versionScheme := Some("early-semver")

testFrameworks += new TestFramework("munit.Framework")
testFrameworks += TestFrameworks.MUnit

addCommandAlias("fmt", "scalafmtRepo")
//addCommandAlias("check", "all versionPolicyCheck Compile/doc scalafmtCheckRepo")
addCommandAlias("check", "+scalafmtCheckRepo")
Comment thread
mr-git marked this conversation as resolved.
addCommandAlias("build", "+all compile test")

val scala3Settings = scalacOptions ++= Vector(
Comment thread
mr-git marked this conversation as resolved.
"-Yexplicit-nulls",
"-Yshow-suppressed-errors",
"-encoding",
"utf-8",
"-Yshow-suppressed-errors",
"--explain",
"--explain-types",
Comment thread
mr-git marked this conversation as resolved.
"--deprecation",
)

val testDependencies = libraryDependencies ++= Vector(
Expand All @@ -47,15 +55,14 @@ lazy val publishSettings = Vector(
publishMavenStyle := true,
Test / publishArtifact := false,
versionScheme := Some("early-semver"),
description := "A derivation library for scala 3 with annotation based configuration.",
description := "A derivation library for Scala 3 with annotation based configuration.",
scmInfo := Some(
ScmInfo(
url("https://github.com/evolution-gaming/derivation"),
"git@github.com:evolution-gaming/derivation.git",
),
),
licenses += ("MIT", url("https://opensource.org/licenses/MIT")),
releaseCrossBuild := true,
publishTo := Some(Resolver.evolutionReleases),
)

Expand Down Expand Up @@ -121,7 +128,7 @@ lazy val playJson = project
.in(modules / "playJson")
.settings(
name := "derivation-play-json",
libraryDependencies += "com.typesafe.play" %% "play-json" % Version.playJson cross CrossVersion.for3Use2_13,
libraryDependencies += "org.playframework" %% "play-json" % Version.playJson,
defaultSettings,
)
.dependsOn(derivation)
14 changes: 10 additions & 4 deletions modules/cats/src/main/scala/evo/derivation/cats/EvoEq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ object BaseEvoEq:
inline given [A]: BaseEvoEq[A] =
summonFrom {
case byCats: cats.kernel.Eq[A] =>
new:
class NamedByCats extends BaseEvoEq[A]:
def eqv(a: A, b: A) = byCats.eqv(a, b)
new NamedByCats
case byScala: Equiv[A] =>
new:
class NamedByScala extends BaseEvoEq[A]:
def eqv(a: A, b: A) = byScala.equiv(a, b)
new NamedByScala
}
end BaseEvoEq

Expand All @@ -30,12 +32,16 @@ trait EvoEq[A] extends BaseEvoEq[A] with cats.kernel.Eq[A] with Equiv[A]:
def equiv(x: A, y: A): Boolean = eqv(x, y)

object EvoEq extends ConsistentTemplate[BaseEvoEq, EvoEq] with SummonHierarchy:
override def product[A](using mirror: Mirror.ProductOf[A])(fields: All[BaseEvoEq, mirror.MirroredElemTypes])(using
override def product[A](using
mirror: Mirror.ProductOf[A],
)(fields: All[BaseEvoEq, mirror.MirroredElemTypes])(using
=> Config[A],
A <:< Product,
): EvoEq[A] = ProductEq(fields)

override def sum[A](using mirror: Mirror.SumOf[A])(
override def sum[A](using
mirror: Mirror.SumOf[A],
)(
subs: All[BaseEvoEq, mirror.MirroredElemTypes],
mkSubMap: => Map[String, BaseEvoEq[A]],
)(using config: => Config[A], matching: Matching[A]): EvoEq[A] = SumEq(mkSubMap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,4 @@ object EvoObjectCodec:
export encoder.encodeObject

override def decodeAccumulating(c: HCursor) = decoder.decodeAccumulating(c)
end EvoCodecImpl
end EvoObjectCodec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ object EvoDecoder extends ConsistentTemplate[Decoder, EvoDecoder] with SummonHie

type Provide[A] = EvoDecoder[A]

def product[A](using mirror: Mirror.ProductOf[A])(
def product[A](using
mirror: Mirror.ProductOf[A],
)(
fields: LazySummon.All[Decoder, mirror.MirroredElemTypes],
)(using config: => Config[A], ev: A <:< Product): EvoDecoder[A] = new:

Expand All @@ -35,7 +37,6 @@ object EvoDecoder extends ConsistentTemplate[Decoder, EvoDecoder] with SummonHie
)(decoder: LazySummon.Of[Decoder], info: ForField[_ <: A]): Decoder.Result[decoder.FieldType] =
val cursor = if info.embed then cur else cur.downField(info.name)
decoder.use(cursor.as[decoder.FieldType])
end onField

def apply(cur: HCursor): Decoder.Result[A] =
fields.useEitherFast(infos)(onField(cur)) match
Expand All @@ -48,7 +49,9 @@ object EvoDecoder extends ConsistentTemplate[Decoder, EvoDecoder] with SummonHie
case Left(_) => Validated.invalidNel(DecodingFailure("unknown error", Nil))
case Right(tuple) => Validated.Valid(mirror.fromProduct(tuple))

def sum[A](using mirror: Mirror.SumOf[A])(
def sum[A](using
mirror: Mirror.SumOf[A],
)(
subs: LazySummon.All[Decoder, mirror.MirroredElemTypes],
mkSubMap: => Map[String, Decoder[A]],
)(using config: => Config[A], matching: Matching[A]): EvoDecoder[A] = new:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ abstract class EvoTemplateEncoder extends Template:

type Provide[A] >: EvoObjectEncoder[A] <: EvoEncoder[A]

def product[A](using mirror: Mirror.ProductOf[A])(
def product[A](using
mirror: Mirror.ProductOf[A],
)(
fieldInstances: LazySummon.All[Encoder, mirror.MirroredElemTypes],
)(using config: => Config[A], ev: A <:< Product): EvoObjectEncoder[A] = new:
lazy val infos = config.top.fields.map(_._2)
Expand All @@ -33,13 +35,15 @@ abstract class EvoTemplateEncoder extends Template:
def encodeObject(a: A): JsonObject =
val fields = tupleFromProduct(a)
type Res = Vector[(String, Json)]
val results = fieldInstances.useCollect[Res, ForField[_]](fields, infos)(
[X] => (info: ForField[_], a: X, enc: Encoder[X]) => encodeField(info, enc(a)),
val results = fieldInstances.useCollect[Res, ForField[_]](fields, infos)([X] =>
(info: ForField[_], a: X, enc: Encoder[X]) => encodeField(info, enc(a)),
)
JsonObject.fromIterable(results.flatten)
end encodeObject

def sum[A](using mirror: Mirror.SumOf[A])(
def sum[A](using
mirror: Mirror.SumOf[A],
)(
subs: LazySummon.All[Encoder, mirror.MirroredElemTypes],
mkEncoders: => Map[String, Encoder[A]],
)(using config: => Config[A], matching: Matching[A]): EvoObjectEncoder[A] = new:
Expand All @@ -58,7 +62,6 @@ abstract class EvoTemplateEncoder extends Template:
(field -> Json.fromString(discrimValue)) +: obj
case None =>
JsonObject.singleton(discrimValue, json)
end match
end encodeObject
end EvoTemplateEncoder

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ private object EnumerationCodec:
case Right(value) if value == name => Right(mirror.fromProduct(EmptyTuple))
case Right(value) => Left(DecodingFailure(s"got $value, expected $name", c.history))
case Left(err) => Left(err)
end apply

def apply(a: A): Json = Json.fromString(name)
}
Expand All @@ -64,7 +63,7 @@ private object EnumerationCodec:
val matching: Matching[A] = Matching.create[A]

val decoder: Decoder[A] = codecs.reduceLeft(_ or _)
new EnumerationCodec[A] {
class NamedEnumerationCodec extends EnumerationCodec[A] {
def apply(c: HCursor): Decoder.Result[A] =
c.value.asString match
case None => Left(DecodingFailure(s"Expected string value, got ${c.value}", c.history))
Expand All @@ -75,5 +74,6 @@ private object EnumerationCodec:

def apply(a: A): Json = Json.fromString(matching.matched(a))
}
new NamedEnumerationCodec
}
end EnumerationCodec
Loading