Skip to content

Commit

Permalink
Upgrade deps and add Scala 3 support
Browse files Browse the repository at this point in the history
* Upgrade all deps
* Split sources in scala-2 and scala-3 for required compat changes
* Mostly bincompat, but had to remove a few functions in Resources
  object
  • Loading branch information
hamnis committed Jul 29, 2024
1 parent 560abdc commit dac23e3
Show file tree
Hide file tree
Showing 15 changed files with 330 additions and 75 deletions.
28 changes: 26 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,21 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12, 2.13]
scala: [2.12, 2.13, 3]
java: [temurin@11, temurin@17]
project: [rootJVM]
exclude:
- scala: 2.12
java: temurin@17
- scala: 3
java: temurin@17
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 @@ -115,6 +121,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 @@ -166,6 +176,16 @@ jobs:
tar xf targets.tar
rm targets.tar
- name: Download target directories (3, rootJVM)
uses: actions/download-artifact@v4
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3-rootJVM

- name: Inflate target directories (3, rootJVM)
run: |
tar xf targets.tar
rm targets.tar
- name: Import signing key
if: env.PGP_SECRET != '' && env.PGP_PASSPHRASE == ''
env:
Expand Down Expand Up @@ -199,6 +219,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 @@ -233,5 +257,5 @@ jobs:
- name: Submit Dependencies
uses: scalacenter/sbt-dependency-submission@v2
with:
modules-ignore: rootjs_2.12 rootjs_2.13 rootjvm_2.12 rootjvm_2.13 rootnative_2.12 rootnative_2.13 example1_2.12 example1_2.13
modules-ignore: rootjs_2.12 rootjs_2.13 rootjs_3 rootjvm_2.12 rootjvm_2.13 rootjvm_3 rootnative_2.12 rootnative_2.13 rootnative_3 example1_2.12 example1_2.13 example1_3
configs-ignore: test scala-tool scala-doc-tool test-internal
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ target/
.classpath
tmp/
.bsp/
.metals/
.vscode/
.jvm/
*.semanticdb
8 changes: 7 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version = 3.5.0
runner.dialect = scala213
runner.dialect = scala3
continuationIndent.defnSite = 2
docstrings.style = Asterisk
includeCurlyBraceInSelectChains = false
Expand All @@ -15,3 +15,9 @@ rewrite.rules = [
AsciiSortImports,
PreferCurlyFors
]

fileOverride {
"glob:**/scala-3/**/*.scala" {
runner.dialect = scala3
}
}
29 changes: 19 additions & 10 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ ThisBuild / circeRootOfCodeCoverage := None
ThisBuild / startYear := Some(2016)

val scala212 = "2.12.19"
val scala213 = "2.13.11"
val scala213 = "2.13.14"
val scala3 = "3.3.3"
ThisBuild / scalaVersion := scala213
ThisBuild / crossScalaVersions := Seq(scala212, scala213)
ThisBuild / crossScalaVersions := Seq(scala212, scala213, scala3)

val circeVersion = "0.14.6"
val scalacheckVersion = "1.17.0"
val disciplineScalatestVersion = "2.2.0"
val scalacheckScalaTestVersion = "3.2.18.0"
val circeVersion = "0.14.9"
val scalacheckVersion = "1.18.0"
val disciplineScalatestVersion = "2.3.0"
val scalacheckScalaTestVersion = "3.2.19.0"

val root = tlCrossRootProject.aggregate(golden, example1)

Expand All @@ -21,15 +22,23 @@ lazy val golden = crossProject(JVMPlatform)
.settings(
moduleName := "circe-golden",
libraryDependencies ++= Seq(
"org.scalatestplus" %%% "scalacheck-1-17" % scalacheckScalaTestVersion,
"org.scalatestplus" %%% "scalacheck-1-18" % scalacheckScalaTestVersion,
"io.circe" %%% "circe-core" % circeVersion,
"io.circe" %%% "circe-parser" % circeVersion,
"io.circe" %%% "circe-testing" % circeVersion,
"io.circe" %%% "circe-generic" % circeVersion % Test,
"org.scalacheck" %% "scalacheck" % scalacheckVersion,
"org.typelevel" %%% "discipline-scalatest" % disciplineScalatestVersion % Test,
scalaOrganization.value % "scala-reflect" % scalaVersion.value % Provided
)
"org.typelevel" %%% "discipline-scalatest" % disciplineScalatestVersion % Test
),
libraryDependencies ++= {
if (tlIsScala3.value) Nil
else
Seq(
scalaOrganization.value % "scala-reflect" % scalaVersion.value % Provided
)
},
Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.Flat,
tlVersionIntroduced := Map("2.13" -> "0.14.0", "2.12" -> "0.4.0", "3" -> "0.4.1")
)

lazy val example1 = crossProject(JVMPlatform)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2016 circe
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.circe.testing.golden

import io.circe.Decoder
import io.circe.Encoder
import io.circe.Printer
import org.scalacheck.Arbitrary

import scala.reflect.runtime.universe.TypeTag

trait GoldenCodecTestsCompanion { self: GoldenCodecTests.type =>
def apply[A: Decoder: Encoder: Arbitrary: TypeTag]: GoldenCodecTests[A] =
fromLaws[A](ResourceFileGoldenCodecLaws[A]())

def apply[A: Decoder: Encoder: Arbitrary: TypeTag](printer: Printer): GoldenCodecTests[A] =
fromLaws[A](ResourceFileGoldenCodecLaws[A](printer = printer))

def apply[A: Decoder: Encoder: Arbitrary: TypeTag](count: Int): GoldenCodecTests[A] =
fromLaws[A](ResourceFileGoldenCodecLaws[A](count = count))

def apply[A: Decoder: Encoder: Arbitrary: TypeTag](count: Int, printer: Printer): GoldenCodecTests[A] =
fromLaws[A](ResourceFileGoldenCodecLaws[A](count = count, printer = printer))

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2016 circe
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.circe.testing.golden

import io.circe.Decoder
import io.circe.Encoder
import io.circe.Printer
import org.scalacheck.Arbitrary

import scala.reflect.runtime.universe.TypeTag

trait ResourceFileGoldenCodecLawsCompanion { self: ResourceFileGoldenCodecLaws.type =>

def apply[A](
size: Int = 100,
count: Int = 1,
printer: Printer = Printer.spaces2
)(implicit
decodeA: Decoder[A],
encodeA: Encoder[A],
arbitraryA: Arbitrary[A],
typeTagA: TypeTag[A]
): GoldenCodecLaws[A] =
self.apply[A](
Scala2Naming.inferName[A],
Resources.inferRootDir(typeTagA.mirror.runtimeClass(typeTagA.tpe)),
Scala2Naming.inferPackage[A],
size,
count,
printer
)
}
47 changes: 47 additions & 0 deletions golden/src/main/scala-2/io/circe/testing/golden/Scala2Naming.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2016 circe
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.circe.testing.golden

import scala.reflect.runtime.universe.Symbol
import scala.reflect.runtime.universe.Type
import scala.reflect.runtime.universe.TypeTag

object Scala2Naming {

/**
* Attempt to guess the packaging of the type indicated by the provided type tag.
*/
def inferPackage[A](implicit A: TypeTag[A]): List[String] =
owners(A.tpe).collectFirst { case s if s.isPackage => s.fullName.split('.').toList }.getOrElse(List.empty)

private def owners(tpe: Type): Iterator[Symbol] =
Iterator.iterate(tpe.typeSymbol)(_.owner)

/**
* Attempt to guess the name of the type indicated by the provided type tag.
*/
def inferName[A](implicit A: TypeTag[A]): String = inferNameForType(A.tpe)

private def baseSymbols(tpe: Type): List[Symbol] =
owners(tpe).takeWhile(!_.isPackage).toList.reverse

private def inferNameForType(tpe: Type): String = {
val baseNames = baseSymbols(tpe).map(_.name.decodedName.toString)

(baseNames ::: tpe.typeArgs.map(inferNameForType)).mkString("_")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2016 circe
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.circe.testing.golden

import io.circe.Decoder
import io.circe.Encoder
import io.circe.Printer
import org.scalacheck.Arbitrary

import scala.reflect.ClassTag

trait GoldenCodecTestsCompanion { self: GoldenCodecTests.type =>
inline def apply[A: Decoder: Encoder: Arbitrary: ClassTag]: GoldenCodecTests[A] =
fromLaws[A](ResourceFileGoldenCodecLaws[A]())

inline def apply[A: Decoder: Encoder: Arbitrary: ClassTag](printer: Printer): GoldenCodecTests[A] =
fromLaws[A](ResourceFileGoldenCodecLaws[A](printer = printer))

inline def apply[A: Decoder: Encoder: Arbitrary: ClassTag](count: Int): GoldenCodecTests[A] =
fromLaws[A](ResourceFileGoldenCodecLaws[A](count = count))

inline def apply[A: Decoder: Encoder: Arbitrary: ClassTag](count: Int, printer: Printer): GoldenCodecTests[A] =
fromLaws[A](ResourceFileGoldenCodecLaws[A](count = count, printer = printer))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2016 circe
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.circe.testing.golden

import io.circe.Decoder
import io.circe.Encoder
import io.circe.Printer
import org.scalacheck.Arbitrary

import scala.reflect.ClassTag

trait ResourceFileGoldenCodecLawsCompanion { self: ResourceFileGoldenCodecLaws.type =>

inline def apply[A](
size: Int = 100,
count: Int = 1,
printer: Printer = Printer.spaces2
)(using
decodeA: Decoder[A],
encodeA: Encoder[A],
arbitraryA: Arbitrary[A],
classT: ClassTag[A]
): GoldenCodecLaws[A] =
self.apply[A](
Scala3Naming.name[A],
Resources.inferRootDir(classT.runtimeClass),
Scala3Naming.pkg[A],
size,
count,
printer
)
}
Loading

0 comments on commit dac23e3

Please sign in to comment.