From 0ee574a1e532a1da1f744435df927c14e115aed9 Mon Sep 17 00:00:00 2001 From: Domas Poliakas Date: Wed, 22 Feb 2023 16:46:47 +0100 Subject: [PATCH 1/3] Migrated to sbt-circe-org --- .github/workflows/ci.yml | 183 ++++++++++++++++-- .scalafix.conf | 4 + build.sbt | 128 ++---------- .../scala/io/circe/examples/package.scala | 24 ++- .../io/circe/examples/ExamplesSuite.scala | 18 +- .../testing/golden/ExampleGeneration.scala | 17 ++ .../testing/golden/GoldenCodecLaws.scala | 29 ++- .../testing/golden/GoldenCodecTests.scala | 30 ++- .../golden/ResourceFileGoldenCodecLaws.scala | 36 +++- .../io/circe/testing/golden/Resources.scala | 20 +- .../golden/example/VisitRepositorySuite.scala | 20 +- .../testing/golden/example/VisitSuite.scala | 17 ++ project/build.properties | 2 +- project/plugins.sbt | 13 +- version.sbt | 1 - 15 files changed, 388 insertions(+), 154 deletions(-) create mode 100644 .scalafix.conf delete mode 100644 version.sbt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 964ccef..829ef93 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,35 +9,73 @@ name: Continuous Integration on: pull_request: - branches: ['**'] + branches: ['**', '!update/**', '!pr/**'] push: - branches: ['**'] + branches: ['**', '!update/**', '!pr/**'] + tags: [v*] env: + PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + SONATYPE_CREDENTIAL_HOST: ${{ secrets.SONATYPE_CREDENTIAL_HOST }} + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + PGP_SECRET: ${{ secrets.PGP_SECRET }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} jobs: build: name: Build and Test strategy: + fail-fast: false matrix: os: [ubuntu-latest] scala: [2.12.15, 2.13.7] - java: [adopt@1.8] + java: [temurin@11, temurin@17] + project: [rootJVM] + exclude: + - scala: 2.12.15 + java: temurin@17 runs-on: ${{ matrix.os }} steps: - name: Checkout current branch (full) - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 0 - - name: Setup Java and Scala - uses: olafurpg/setup-scala@v13 + - name: Download Java (temurin@11) + id: download-java-temurin-11 + if: matrix.java == 'temurin@11' + uses: typelevel/download-java@v2 with: - java-version: ${{ matrix.java }} + distribution: temurin + java-version: 11 + + - name: Setup Java (temurin@11) + if: matrix.java == 'temurin@11' + uses: actions/setup-java@v3 + with: + distribution: jdkfile + java-version: 11 + jdkFile: ${{ steps.download-java-temurin-11.outputs.jdkFile }} + + - name: Download Java (temurin@17) + id: download-java-temurin-17 + if: matrix.java == 'temurin@17' + uses: typelevel/download-java@v2 + with: + distribution: temurin + java-version: 17 + + - name: Setup Java (temurin@17) + if: matrix.java == 'temurin@17' + uses: actions/setup-java@v3 + with: + distribution: jdkfile + java-version: 17 + jdkFile: ${{ steps.download-java-temurin-17.outputs.jdkFile }} - name: Cache sbt - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: | ~/.sbt @@ -49,9 +87,132 @@ jobs: key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }} - name: Check that workflows are up to date - run: sbt ++${{ matrix.scala }} githubWorkflowCheck + run: sbt githubWorkflowCheck + + - name: Check headers and formatting + if: matrix.java == 'temurin@11' && matrix.os == 'ubuntu-latest' + run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' headerCheckAll scalafmtCheckAll 'project /' scalafmtSbtCheck - name: Test - run: sbt ++${{ matrix.scala }} clean coverage test coverageReport scalafmtCheckAll + run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' test + + - name: Check scalafix lints + if: matrix.java == 'temurin@11' && matrix.os == 'ubuntu-latest' + run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' 'scalafixAll --check' + + - name: Check binary compatibility + if: matrix.java == 'temurin@11' && matrix.os == 'ubuntu-latest' + run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' mimaReportBinaryIssues + + - name: Generate API documentation + if: matrix.java == 'temurin@11' && matrix.os == 'ubuntu-latest' + run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' doc + + - name: Make target directories + if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main') + run: mkdir -p target .js/target .jvm/target .native/target examples/example-1/target golden/.jvm/target project/target + + - name: Compress target directories + if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main') + run: tar cf targets.tar target .js/target .jvm/target .native/target examples/example-1/target golden/.jvm/target project/target + + - name: Upload target directories + if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main') + uses: actions/upload-artifact@v3 + with: + name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }}-${{ matrix.project }} + path: targets.tar + + publish: + name: Publish Artifacts + needs: [build] + if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main') + strategy: + matrix: + os: [ubuntu-latest] + scala: [2.13.7] + java: [temurin@11] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout current branch (full) + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Download Java (temurin@11) + id: download-java-temurin-11 + if: matrix.java == 'temurin@11' + uses: typelevel/download-java@v2 + with: + distribution: temurin + java-version: 11 + + - name: Setup Java (temurin@11) + if: matrix.java == 'temurin@11' + uses: actions/setup-java@v3 + with: + distribution: jdkfile + java-version: 11 + jdkFile: ${{ steps.download-java-temurin-11.outputs.jdkFile }} + + - name: Download Java (temurin@17) + id: download-java-temurin-17 + if: matrix.java == 'temurin@17' + uses: typelevel/download-java@v2 + with: + distribution: temurin + java-version: 17 + + - name: Setup Java (temurin@17) + if: matrix.java == 'temurin@17' + uses: actions/setup-java@v3 + with: + distribution: jdkfile + java-version: 17 + jdkFile: ${{ steps.download-java-temurin-17.outputs.jdkFile }} + + - name: Cache sbt + uses: actions/cache@v3 + with: + path: | + ~/.sbt + ~/.ivy2/cache + ~/.coursier/cache/v1 + ~/.cache/coursier/v1 + ~/AppData/Local/Coursier/Cache/v1 + ~/Library/Caches/Coursier/v1 + key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }} + + - name: Download target directories (2.12.15, rootJVM) + uses: actions/download-artifact@v3 + with: + name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.15-rootJVM + + - name: Inflate target directories (2.12.15, rootJVM) + run: | + tar xf targets.tar + rm targets.tar + + - name: Download target directories (2.13.7, rootJVM) + uses: actions/download-artifact@v3 + with: + name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.7-rootJVM + + - name: Inflate target directories (2.13.7, rootJVM) + run: | + tar xf targets.tar + rm targets.tar + + - name: Import signing key + if: env.PGP_SECRET != '' && env.PGP_PASSPHRASE == '' + run: echo $PGP_SECRET | base64 -di | gpg --import + + - name: Import signing key and strip passphrase + if: env.PGP_SECRET != '' && env.PGP_PASSPHRASE != '' + run: | + echo "$PGP_SECRET" | base64 -di > /tmp/signing-key.gpg + echo "$PGP_PASSPHRASE" | gpg --pinentry-mode loopback --passphrase-fd 0 --import /tmp/signing-key.gpg + (echo "$PGP_PASSPHRASE"; echo; echo) | gpg --command-fd 0 --pinentry-mode loopback --change-passphrase $(gpg --list-secret-keys --with-colons 2> /dev/null | grep '^sec:' | cut --delimiter ':' --fields 5 | tail -n 1) - - uses: codecov/codecov-action@v1 + - name: Publish + run: sbt '++ ${{ matrix.scala }}' tlRelease diff --git a/.scalafix.conf b/.scalafix.conf new file mode 100644 index 0000000..36159f3 --- /dev/null +++ b/.scalafix.conf @@ -0,0 +1,4 @@ +rules = [ + OrganizeImports +] +OrganizeImports.removeUnused = false diff --git a/build.sbt b/build.sbt index 0eb7352..9fa27cb 100644 --- a/build.sbt +++ b/build.sbt @@ -1,38 +1,14 @@ import sbtcrossproject.{ CrossType, crossProject } -ThisBuild / organization := "io.circe" -ThisBuild / crossScalaVersions := Seq("2.12.15", "2.13.7") -ThisBuild / githubWorkflowJavaVersions := Seq("adopt@1.8") -ThisBuild / githubWorkflowPublishTargetBranches := Nil -ThisBuild / githubWorkflowBuild := Seq( - WorkflowStep.Sbt( - List("clean", "coverage", "test", "coverageReport", "scalafmtCheckAll"), - id = None, - name = Some("Test") - ), - WorkflowStep.Use( - UseRef.Public( - "codecov", - "codecov-action", - "v1" - ) - ) -) +ThisBuild / tlBaseVersion := "0.14" +ThisBuild / circeRootOfCodeCoverage := None +ThisBuild / startYear := Some(2016) +ThisBuild / scalafixScalaBinaryVersion := "2.12" +ThisBuild / githubWorkflowBuildMatrixFailFast := Some(false) -val compilerOptions = Seq( - "-deprecation", - "-encoding", - "UTF-8", - "-feature", - "-language:existentials", - "-language:higherKinds", - "-unchecked", - "-Ywarn-dead-code", - "-Ywarn-numeric-widen" -) +ThisBuild / crossScalaVersions := Seq("2.12.15", "2.13.7") val circeVersion = "0.14.1" -val previousCirceGoldenVersion = "0.2.1" def priorTo2_13(scalaVersion: String): Boolean = CrossVersion.partialVersion(scalaVersion) match { @@ -42,48 +18,24 @@ def priorTo2_13(scalaVersion: String): Boolean = val baseSettings = Seq( resolvers += "jitpack".at("https://jitpack.io"), - scalacOptions ++= compilerOptions, - scalacOptions ++= ( - if (priorTo2_13(scalaVersion.value)) - Seq( - "-Xfuture", - "-Yno-adapted-args", - "-Ywarn-unused-import" - ) - else - Seq( - "-Ywarn-unused:imports" - ) - ), Compile / console / scalacOptions ~= { _.filterNot(Set("-Ywarn-unused-import", "-Ywarn-unused:imports")) }, Test / console / scalacOptions ~= { _.filterNot(Set("-Ywarn-unused-import", "-Ywarn-unused:imports")) }, - coverageHighlighting := true, - Compile / scalastyleSources ++= (Compile / unmanagedSourceDirectories).value + coverageHighlighting := true ) -val allSettings = baseSettings ++ publishSettings - -val docMappingsApiDir = settingKey[String]("Subdirectory in site target directory for API docs") - -val root = project - .in(file(".")) - .settings(allSettings) - .settings(noPublishSettings) - .aggregate(goldenJVM, example1) - .dependsOn(goldenJVM) +val root = tlCrossRootProject.aggregate(golden, example1) -lazy val golden = crossProject(JSPlatform, JVMPlatform) +lazy val golden = crossProject(JVMPlatform) .withoutSuffixFor(JVMPlatform) .crossType(CrossType.Pure) .in(file("golden")) - .settings(allSettings) + .settings(baseSettings) .settings( moduleName := "circe-golden", - mimaPreviousArtifacts := Set("io.circe" %% "circe-golden" % previousCirceGoldenVersion), libraryDependencies ++= Seq( "io.circe" %%% "circe-core" % circeVersion, "io.circe" %%% "circe-parser" % circeVersion, @@ -92,13 +44,9 @@ lazy val golden = crossProject(JSPlatform, JVMPlatform) "org.typelevel" %%% "discipline-scalatest" % "2.1.5" % Test, scalaOrganization.value % "scala-reflect" % scalaVersion.value % Provided ), - ghpagesNoJekyll := true, - docMappingsApiDir := "api", - addMappingsToSiteDir(Compile / packageDoc / mappings, docMappingsApiDir) ) lazy val goldenJVM = golden.jvm -lazy val goldenJS = golden.js lazy val example1 = project .in(file("examples/example-1")) @@ -109,56 +57,14 @@ lazy val example1 = project "org.typelevel" %%% "discipline-scalatest" % "2.1.5" % Test ) ) - .settings(noPublishSettings) + .enablePlugins(NoPublishPlugin) .dependsOn(goldenJVM % Test) -lazy val publishSettings = Seq( - releaseCrossBuild := true, - releasePublishArtifactsAction := PgpKeys.publishSigned.value, - homepage := Some(url("https://github.com/circe/circe-golden")), - licenses := Seq("Apache 2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")), - publishMavenStyle := true, - Test / publishArtifact := false, - pomIncludeRepository := { _ => false }, - publishTo := { - val nexus = "https://oss.sonatype.org/" - if (isSnapshot.value) - Some("snapshots".at(nexus + "content/repositories/snapshots")) - else - Some("releases".at(nexus + "service/local/staging/deploy/maven2")) - }, - autoAPIMappings := true, - apiURL := Some(url("https://circe.github.io/circe-golden/api/")), - scmInfo := Some( - ScmInfo( - url("https://github.com/circe/circe-golden"), - "scm:git:git@github.com:circe/circe-golden.git" - ) - ), - developers := List( - Developer( - "travisbrown", - "Travis Brown", - "travisrobertbrown@gmail.com", - url("https://twitter.com/travisbrown") - ) +ThisBuild / developers := List( + Developer( + "travisbrown", + "Travis Brown", + "travisrobertbrown@gmail.com", + url("https://twitter.com/travisbrown") ) ) - -lazy val noPublishSettings = Seq( - publish := {}, - publishLocal := {}, - publishArtifact := false -) - -credentials ++= ( - for { - username <- Option(System.getenv().get("SONATYPE_USERNAME")) - password <- Option(System.getenv().get("SONATYPE_PASSWORD")) - } yield Credentials( - "Sonatype Nexus Repository Manager", - "oss.sonatype.org", - username, - password - ) -).toSeq diff --git a/examples/example-1/src/main/scala/io/circe/examples/package.scala b/examples/example-1/src/main/scala/io/circe/examples/package.scala index c89cc55..c2bdb1e 100644 --- a/examples/example-1/src/main/scala/io/circe/examples/package.scala +++ b/examples/example-1/src/main/scala/io/circe/examples/package.scala @@ -1,10 +1,30 @@ +/* + * 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.examples import cats.kernel.Eq import cats.kernel.instances.long._ import cats.syntax.functor._ -import io.circe.{ Decoder, DecodingFailure, Encoder, Json } -import org.scalacheck.{ Arbitrary, Gen } +import io.circe.Decoder +import io.circe.DecodingFailure +import io.circe.Encoder +import io.circe.Json +import org.scalacheck.Arbitrary +import org.scalacheck.Gen case class Wub(x: Long) diff --git a/examples/example-1/src/test/scala/io/circe/examples/ExamplesSuite.scala b/examples/example-1/src/test/scala/io/circe/examples/ExamplesSuite.scala index 109c4dc..109df43 100644 --- a/examples/example-1/src/test/scala/io/circe/examples/ExamplesSuite.scala +++ b/examples/example-1/src/test/scala/io/circe/examples/ExamplesSuite.scala @@ -1,8 +1,24 @@ +/* + * 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.examples import cats.instances.list._ -import io.circe.testing.instances._ import io.circe.testing.golden._ +import io.circe.testing.instances._ import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.prop.Configuration import org.typelevel.discipline.scalatest.FlatSpecDiscipline diff --git a/golden/src/main/scala/io/circe/testing/golden/ExampleGeneration.scala b/golden/src/main/scala/io/circe/testing/golden/ExampleGeneration.scala index cc0709f..d7a4e1e 100644 --- a/golden/src/main/scala/io/circe/testing/golden/ExampleGeneration.scala +++ b/golden/src/main/scala/io/circe/testing/golden/ExampleGeneration.scala @@ -1,7 +1,24 @@ +/* + * 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 org.scalacheck.Gen import org.scalacheck.rng.Seed + import scala.util.Try trait ExampleGeneration[A] { self: GoldenCodecLaws[A] => diff --git a/golden/src/main/scala/io/circe/testing/golden/GoldenCodecLaws.scala b/golden/src/main/scala/io/circe/testing/golden/GoldenCodecLaws.scala index efb26dc..f80eee3 100644 --- a/golden/src/main/scala/io/circe/testing/golden/GoldenCodecLaws.scala +++ b/golden/src/main/scala/io/circe/testing/golden/GoldenCodecLaws.scala @@ -1,11 +1,32 @@ +/* + * 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 cats.instances.list._, cats.instances.try_._ -import cats.syntax.traverse._ +import cats.instances.list._ +import cats.instances.try_._ import cats.laws._ -import io.circe.{ Json, Printer } +import cats.syntax.traverse._ +import io.circe.Json +import io.circe.Printer import io.circe.testing.CodecLaws -import scala.util.{ Failure, Success, Try } + +import scala.util.Failure +import scala.util.Success +import scala.util.Try trait GoldenCodecLaws[A] extends CodecLaws[A] { diff --git a/golden/src/main/scala/io/circe/testing/golden/GoldenCodecTests.scala b/golden/src/main/scala/io/circe/testing/golden/GoldenCodecTests.scala index e64cfe8..d3a1e95 100644 --- a/golden/src/main/scala/io/circe/testing/golden/GoldenCodecTests.scala +++ b/golden/src/main/scala/io/circe/testing/golden/GoldenCodecTests.scala @@ -1,14 +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 cats.instances.string._ import cats.kernel.Eq import cats.laws.IsEq import cats.laws.discipline.catsLawsIsEqToProp -import io.circe.{ Decoder, Encoder, Json, Printer } +import io.circe.Decoder +import io.circe.Encoder +import io.circe.Json +import io.circe.Printer import io.circe.testing.CodecTests -import org.scalacheck.{ Arbitrary, Prop, Shrink } +import org.scalacheck.Arbitrary +import org.scalacheck.Prop +import org.scalacheck.Shrink + import scala.reflect.runtime.universe.TypeTag -import scala.util.{ Failure, Success, Try } +import scala.util.Failure +import scala.util.Success +import scala.util.Try trait GoldenCodecTests[A] extends CodecTests[A] { def laws: GoldenCodecLaws[A] diff --git a/golden/src/main/scala/io/circe/testing/golden/ResourceFileGoldenCodecLaws.scala b/golden/src/main/scala/io/circe/testing/golden/ResourceFileGoldenCodecLaws.scala index 64f851d..5c08e7c 100644 --- a/golden/src/main/scala/io/circe/testing/golden/ResourceFileGoldenCodecLaws.scala +++ b/golden/src/main/scala/io/circe/testing/golden/ResourceFileGoldenCodecLaws.scala @@ -1,12 +1,36 @@ +/* + * 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 cats.instances.list._, cats.instances.try_._ -import cats.syntax.apply._, cats.syntax.traverse._ -import io.circe.{ Decoder, Encoder, Printer } -import java.io.{ File, PrintWriter } -import org.scalacheck.{ Arbitrary, Gen } +import cats.instances.list._ +import cats.instances.try_._ +import cats.syntax.apply._ +import cats.syntax.traverse._ +import io.circe.Decoder +import io.circe.Encoder +import io.circe.Printer +import org.scalacheck.Arbitrary +import org.scalacheck.Gen + +import java.io.File +import java.io.PrintWriter import scala.reflect.runtime.universe.TypeTag -import scala.util.{ Failure, Try } +import scala.util.Failure +import scala.util.Try import scala.util.matching.Regex abstract class ResourceFileGoldenCodecLaws[A]( diff --git a/golden/src/main/scala/io/circe/testing/golden/Resources.scala b/golden/src/main/scala/io/circe/testing/golden/Resources.scala index 7a0fea6..d41040c 100644 --- a/golden/src/main/scala/io/circe/testing/golden/Resources.scala +++ b/golden/src/main/scala/io/circe/testing/golden/Resources.scala @@ -1,8 +1,26 @@ +/* + * 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 java.io.File import scala.io.Source -import scala.reflect.runtime.universe.{ Symbol, Type, TypeTag } +import scala.reflect.runtime.universe.Symbol +import scala.reflect.runtime.universe.Type +import scala.reflect.runtime.universe.TypeTag import scala.util.Try /** diff --git a/golden/src/test/scala/io/circe/testing/golden/example/VisitRepositorySuite.scala b/golden/src/test/scala/io/circe/testing/golden/example/VisitRepositorySuite.scala index 18d3f84..89b9775 100644 --- a/golden/src/test/scala/io/circe/testing/golden/example/VisitRepositorySuite.scala +++ b/golden/src/test/scala/io/circe/testing/golden/example/VisitRepositorySuite.scala @@ -1,7 +1,25 @@ +/* + * 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.example -import io.circe.{ Codec, Printer } +import io.circe.Codec +import io.circe.Printer import io.circe.generic.semiauto.deriveCodec + import java.time.Instant case class VisitRepository(visits: Map[String, Visit]) diff --git a/golden/src/test/scala/io/circe/testing/golden/example/VisitSuite.scala b/golden/src/test/scala/io/circe/testing/golden/example/VisitSuite.scala index 44ba919..3aa7a03 100644 --- a/golden/src/test/scala/io/circe/testing/golden/example/VisitSuite.scala +++ b/golden/src/test/scala/io/circe/testing/golden/example/VisitSuite.scala @@ -1,7 +1,24 @@ +/* + * 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.example import io.circe.Codec import io.circe.generic.semiauto.deriveCodec + import java.time.Instant case class Visit(id: Long, page: String, ts: Instant) diff --git a/project/build.properties b/project/build.properties index c8fcab5..c13a9b3 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.6.2 +sbt.version=1.8.1 diff --git a/project/plugins.sbt b/project/plugins.sbt index 79b4cff..7ace567 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,12 +1 @@ -addSbtPlugin("com.codecommit" % "sbt-github-actions" % "0.13.0") -addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0") -addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2") -addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.0.1") -addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.3") -addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.2") -addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.4.1") -addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.1.0") -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.7.1") -addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6") -addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0") -addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.9.3") +addSbtPlugin("io.circe" % "sbt-circe-org" % "0.1.2") diff --git a/version.sbt b/version.sbt deleted file mode 100644 index 83b6ae3..0000000 --- a/version.sbt +++ /dev/null @@ -1 +0,0 @@ -ThisBuild / version := "0.3.1-SNAPSHOT" From 7d53f546517e4122eb130e71eba2e7640bca5dd4 Mon Sep 17 00:00:00 2001 From: Domas Poliakas Date: Wed, 22 Feb 2023 16:59:21 +0100 Subject: [PATCH 2/3] Scalafmt and fixed warnings --- build.sbt | 2 +- .../io/circe/examples/ExamplesSuite.scala | 1 - .../testing/golden/GoldenCodecTests.scala | 2 +- .../golden/ResourceFileGoldenCodecLaws.scala | 30 +++++++++++-------- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/build.sbt b/build.sbt index 9fa27cb..2dda212 100644 --- a/build.sbt +++ b/build.sbt @@ -43,7 +43,7 @@ lazy val golden = crossProject(JVMPlatform) "io.circe" %%% "circe-generic" % circeVersion % Test, "org.typelevel" %%% "discipline-scalatest" % "2.1.5" % Test, scalaOrganization.value % "scala-reflect" % scalaVersion.value % Provided - ), + ) ) lazy val goldenJVM = golden.jvm diff --git a/examples/example-1/src/test/scala/io/circe/examples/ExamplesSuite.scala b/examples/example-1/src/test/scala/io/circe/examples/ExamplesSuite.scala index 109df43..f5c5f5a 100644 --- a/examples/example-1/src/test/scala/io/circe/examples/ExamplesSuite.scala +++ b/examples/example-1/src/test/scala/io/circe/examples/ExamplesSuite.scala @@ -16,7 +16,6 @@ package io.circe.examples -import cats.instances.list._ import io.circe.testing.golden._ import io.circe.testing.instances._ import org.scalatest.flatspec.AnyFlatSpec diff --git a/golden/src/main/scala/io/circe/testing/golden/GoldenCodecTests.scala b/golden/src/main/scala/io/circe/testing/golden/GoldenCodecTests.scala index d3a1e95..b1487da 100644 --- a/golden/src/main/scala/io/circe/testing/golden/GoldenCodecTests.scala +++ b/golden/src/main/scala/io/circe/testing/golden/GoldenCodecTests.scala @@ -82,7 +82,7 @@ object GoldenCodecTests { def apply[A: Decoder: Encoder: Arbitrary: TypeTag](count: Int, printer: Printer): GoldenCodecTests[A] = apply[A](ResourceFileGoldenCodecLaws[A](count = count, printer = printer)) - def apply[A: Decoder: Encoder: Arbitrary](laws0: GoldenCodecLaws[A]): GoldenCodecTests[A] = + def apply[A](laws0: GoldenCodecLaws[A]): GoldenCodecTests[A] = new GoldenCodecTests[A] { val laws: GoldenCodecLaws[A] = laws0 } diff --git a/golden/src/main/scala/io/circe/testing/golden/ResourceFileGoldenCodecLaws.scala b/golden/src/main/scala/io/circe/testing/golden/ResourceFileGoldenCodecLaws.scala index 5c08e7c..f1a977e 100644 --- a/golden/src/main/scala/io/circe/testing/golden/ResourceFileGoldenCodecLaws.scala +++ b/golden/src/main/scala/io/circe/testing/golden/ResourceFileGoldenCodecLaws.scala @@ -51,21 +51,25 @@ abstract class ResourceFileGoldenCodecLaws[A]( private[this] lazy val loadGoldenFiles: Try[List[(A, String)]] = Resources.open(resourceRootPath).flatMap { dirSource => - val files = dirSource.getLines.flatMap { - case fileName if fileName.startsWith(name) => - fileName.drop(name.length) match { - case GoldenFilePattern(seed) => Some((seed, fileName)) - case _ => None + val files = dirSource + .getLines() + .flatMap { + case fileName if fileName.startsWith(name) => + fileName.drop(name.length) match { + case GoldenFilePattern(seed) => Some((seed, fileName)) + case _ => None + } + case _ => None + } + .toList + .traverse[Try, (A, String)] { case (seed, name) => + val contents = Resources.open(resourceRootPath + name).map { source => + val lines = source.getLines().mkString("\n") + source.close() + lines } - case _ => None - }.toList.traverse[Try, (A, String)] { case (seed, name) => - val contents = Resources.open(resourceRootPath + name).map { source => - val lines = source.getLines.mkString("\n") - source.close() - lines + (getValueFromBase64Seed(seed), contents).tupled } - (getValueFromBase64Seed(seed), contents).tupled - } dirSource.close() From 92b7bb9f3483e298dc11734b253598ea5555e598 Mon Sep 17 00:00:00 2001 From: Domas Poliakas Date: Wed, 22 Feb 2023 17:12:03 +0100 Subject: [PATCH 3/3] Fixed type shadowing --- .../main/scala/io/circe/testing/golden/GoldenCodecTests.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/golden/src/main/scala/io/circe/testing/golden/GoldenCodecTests.scala b/golden/src/main/scala/io/circe/testing/golden/GoldenCodecTests.scala index b1487da..56452b6 100644 --- a/golden/src/main/scala/io/circe/testing/golden/GoldenCodecTests.scala +++ b/golden/src/main/scala/io/circe/testing/golden/GoldenCodecTests.scala @@ -37,7 +37,7 @@ import scala.util.Try trait GoldenCodecTests[A] extends CodecTests[A] { def laws: GoldenCodecLaws[A] - private[this] def tryListToProp[A: Eq](result: Try[List[IsEq[A]]]): Prop = result match { + private[this] def tryListToProp[T: Eq](result: Try[List[IsEq[T]]]): Prop = result match { case Failure(error) => Prop.exception(error) case Success(equalities) => Prop.all(equalities.map(catsLawsIsEqToProp(_)): _*) }