diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fc4a1996..5e87553b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,131 +1,202 @@ -name: CI +# This file was autogenerated using `zio-sbt-ci` plugin via `sbt ciGenerateGithubWorkflow` +# task and should be included in the git repository. Please do not edit it manually. +name: CI env: - JDK_JAVA_OPTIONS: -XX:+PrintCommandLineFlags # JDK_JAVA_OPTIONS is _the_ env. variable to use for modern Java - JVM_OPTS: -XX:+PrintCommandLineFlags # for Java 8 only (sadly, it is not modern enough for JDK_JAVA_OPTIONS) - -on: - pull_request: - push: - branches: ['series/2.x'] + JDK_JAVA_OPTIONS: -XX:+PrintCommandLineFlags +'on': + workflow_dispatch: {} release: types: - published - + pull_request: + branches-ignore: + - gh-pages + push: + branches: + - series/2.x +concurrency: + group: ${{ github.workflow }}-${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && github.run_id || github.ref }} + cancel-in-progress: true jobs: - lint: - runs-on: ubuntu-20.04 - timeout-minutes: 30 + build: + name: Build + runs-on: ubuntu-latest + continue-on-error: true steps: - - name: Checkout current branch - uses: actions/checkout@v4.1.2 + - name: Git Checkout + uses: actions/checkout@v4 with: - fetch-depth: 0 - - name: Setup Java - uses: actions/setup-java@v4.2.1 + fetch-depth: '0' + - name: Install libuv + run: sudo apt-get update && sudo apt-get install -y libuv1-dev + - name: Setup Scala + uses: actions/setup-java@v4 with: - distribution: temurin - java-version: 21 - check-latest: true - - name: Cache scala dependencies + distribution: corretto + java-version: '17' + check-latest: 'true' + - name: Cache Dependencies uses: coursier/cache-action@v6 - - name: Lint code - run: sbt check - - benchmarks: - runs-on: ubuntu-20.04 - strategy: - fail-fast: false - matrix: - java: ['17', '21'] - scala: ['2.13.15'] + - name: Check all code compiles + run: sbt +Test/compile + - name: Check artifacts build process + run: sbt +publishLocal + - name: Check website build process + run: sbt docs/clean; sbt docs/buildWebsite + lint: + name: Lint + runs-on: ubuntu-latest + continue-on-error: false steps: - - name: Checkout current branch - uses: actions/checkout@v4.1.2 + - name: Git Checkout + uses: actions/checkout@v4 with: - fetch-depth: 0 - - name: Setup Java - uses: actions/setup-java@v4.2.1 + fetch-depth: '0' + - name: Install libuv + run: sudo apt-get update && sudo apt-get install -y libuv1-dev + - name: Setup Scala + uses: actions/setup-java@v4 with: - distribution: temurin - java-version: ${{ matrix.java }} - check-latest: true - - name: Cache scala dependencies + distribution: corretto + java-version: '17' + check-latest: 'true' + - name: Cache Dependencies uses: coursier/cache-action@v6 - - name: Compile benchmarks - run: sbt ++${{ matrix.scala }}! jmh:compile - - mdoc: - runs-on: ubuntu-20.04 - timeout-minutes: 60 - steps: - - name: Checkout current branch - uses: actions/checkout@v4.1.2 - - name: Setup Java - uses: actions/setup-java@v4.2.1 - with: - distribution: temurin - java-version: 8 - check-latest: true - - name: Cache scala dependencies - uses: coursier/cache-action@v6 - - name: Check Document Generation - run: sbt compileDocs - + - name: Check if the site workflow is up to date + run: sbt ciCheckGithubWorkflow + - name: Lint + run: sbt lint test: - runs-on: ubuntu-20.04 - timeout-minutes: 30 + name: Test + runs-on: ubuntu-latest + continue-on-error: false strategy: - fail-fast: false matrix: - java: ['17', '21'] - scala: ['2.12.19', '2.13.15', '3.3.4'] - platform: ['JVM', 'JS', 'Native'] + java: + - '11' + - '17' + - '21' + scalaVersion: + - 2.12.20 + - 2.13.15 + - 3.3.4 + scalaPlatform: + - JS + - JVM + - Native + fail-fast: false steps: - - name: Checkout current branch - uses: actions/checkout@v4.1.2 - with: - fetch-depth: 0 - - name: Setup Java - uses: actions/setup-java@v4.2.1 + - name: Install libuv + run: sudo apt-get update && sudo apt-get install -y libuv1-dev + - name: Setup Scala + uses: actions/setup-java@v4 with: - distribution: temurin + distribution: corretto java-version: ${{ matrix.java }} - check-latest: true - - name: Cache scala dependencies + check-latest: 'true' + - name: Cache Dependencies uses: coursier/cache-action@v6 + - name: Git Checkout + uses: actions/checkout@v4 + with: + fetch-depth: '0' + - name: Test + run: sbt +test${{ matrix.scalaPlatform }}${{ startsWith(matrix.scalaVersion, '2.12') && '2_12' || (startsWith(matrix.scalaVersion, '2.13') && '2_13' || (startsWith(matrix.scalaVersion, '3') && '3' || '')) }} + update-readme: + name: Update README + runs-on: ubuntu-latest + continue-on-error: false + if: ${{ github.event_name == 'push' }} + steps: + - name: Git Checkout + uses: actions/checkout@v4 + with: + fetch-depth: '0' - name: Install libuv - if: matrix.platform == 'Native' run: sudo apt-get update && sudo apt-get install -y libuv1-dev - - name: Run Macros tests - if: ${{ !startsWith(matrix.scala, '3.3.') }} - run: sbt ++${{ matrix.scala }}! testScala2${{ matrix.platform }} - - name: Run tests - run: sbt ++${{ matrix.scala }}! test${{ matrix.platform }} + - name: Setup Scala + uses: actions/setup-java@v4 + with: + distribution: corretto + java-version: '17' + check-latest: 'true' + - name: Cache Dependencies + uses: coursier/cache-action@v6 + - name: Generate Readme + run: sbt docs/generateReadme + - name: Commit Changes + run: | + git config --local user.email "zio-assistant[bot]@users.noreply.github.com" + git config --local user.name "ZIO Assistant" + git add README.md + git commit -m "Update README.md" || echo "No changes to commit" + - name: Generate Token + id: generate-token + uses: zio/generate-github-app-token@v1.0.0 + with: + app_id: ${{ secrets.APP_ID }} + app_private_key: ${{ secrets.APP_PRIVATE_KEY }} + - name: Create Pull Request + id: cpr + uses: peter-evans/create-pull-request@v6 + with: + body: |- + Autogenerated changes after running the `sbt docs/generateReadme` command of the [zio-sbt-website](https://zio.dev/zio-sbt) plugin. + I will automatically update the README.md file whenever there is new change for README.md, e.g. + - After each release, I will update the version in the installation section. + - After any changes to the "docs/index.md" file, I will update the README.md file accordingly. + branch: zio-sbt-website/update-readme + commit-message: Update README.md + token: ${{ steps.generate-token.outputs.token }} + delete-branch: 'true' + title: Update README.md + - name: Approve PR + if: ${{ steps.cpr.outputs.pull-request-number }} + run: gh pr review "$PR_URL" --approve + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_URL: ${{ steps.cpr.outputs.pull-request-url }} + - name: Enable Auto-Merge + if: ${{ steps.cpr.outputs.pull-request-number }} + run: gh pr merge --auto --squash "$PR_URL" || gh pr merge --squash "$PR_URL" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_URL: ${{ steps.cpr.outputs.pull-request-url }} ci: - runs-on: ubuntu-20.04 - needs: [lint, mdoc, benchmarks, test] + name: ci + runs-on: ubuntu-latest + continue-on-error: false + needs: + - lint + - test + - build steps: - - name: Aggregate of lint, and all tests + - name: Report Successful CI run: echo "ci passed" - - publish: - runs-on: ubuntu-20.04 - timeout-minutes: 60 - needs: [ci] - if: github.event_name != 'pull_request' + release: + name: Release + runs-on: ubuntu-latest + continue-on-error: false + needs: + - ci + if: ${{ github.event_name != 'pull_request' }} steps: - - name: Checkout current branch - uses: actions/checkout@v4.1.2 + - name: Git Checkout + uses: actions/checkout@v4 with: - fetch-depth: 0 - - name: Setup Java - uses: actions/setup-java@v4.2.1 + fetch-depth: '0' + - name: Install libuv + run: sudo apt-get update && sudo apt-get install -y libuv1-dev + - name: Setup Scala + uses: actions/setup-java@v4 with: - distribution: temurin - java-version: 8 - check-latest: true + distribution: corretto + java-version: '17' + check-latest: 'true' + - name: Cache Dependencies + uses: coursier/cache-action@v6 - name: Release run: sbt ci-release env: @@ -133,3 +204,64 @@ jobs: PGP_SECRET: ${{ secrets.PGP_SECRET }} SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + CI_RELEASE: +publishSigned + CI_SNAPSHOT_RELEASE: +publish + release-docs: + name: Release Docs + runs-on: ubuntu-latest + continue-on-error: false + needs: + - release + if: ${{ ((github.event_name == 'release') && (github.event.action == 'published')) || (github.event_name == 'workflow_dispatch') }} + steps: + - name: Git Checkout + uses: actions/checkout@v4 + with: + fetch-depth: '0' + - name: Install libuv + run: sudo apt-get update && sudo apt-get install -y libuv1-dev + - name: Setup Scala + uses: actions/setup-java@v4 + with: + distribution: corretto + java-version: '17' + check-latest: 'true' + - name: Cache Dependencies + uses: coursier/cache-action@v6 + - name: Setup NodeJs + uses: actions/setup-node@v4 + with: + node-version: 16.x + registry-url: https://registry.npmjs.org + - name: Publish Docs to NPM Registry + run: sbt docs/publishToNpm + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + notify-docs-release: + name: Notify Docs Release + runs-on: ubuntu-latest + continue-on-error: false + needs: + - release-docs + if: ${{ (github.event_name == 'release') && (github.event.action == 'published') }} + steps: + - name: Git Checkout + uses: actions/checkout@v4 + with: + fetch-depth: '0' + - name: notify the main repo about the new release of docs package + run: | + PACKAGE_NAME=$(cat docs/package.json | grep '"name"' | awk -F'"' '{print $4}') + PACKAGE_VERSION=$(npm view $PACKAGE_NAME version) + curl -L \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: token ${{ secrets.PAT_TOKEN }}"\ + https://api.github.com/repos/zio/zio/dispatches \ + -d '{ + "event_type":"update-docs", + "client_payload":{ + "package_name":"'"${PACKAGE_NAME}"'", + "package_version": "'"${PACKAGE_VERSION}"'" + } + }' diff --git a/README.md b/README.md index 17104468..a627dab1 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ The goal of this project is to create the best all-round JSON library for Scala: In order to use this library, we need to add the following line in our `build.sbt` file: ```scala -libraryDependencies += "dev.zio" %% "zio-json" % "0.6.2" +libraryDependencies += "dev.zio" %% "zio-json" % "0.7.0" ``` ## Example diff --git a/build.sbt b/build.sbt index 89a3a8ef..2407d1fe 100644 --- a/build.sbt +++ b/build.sbt @@ -1,12 +1,16 @@ -import BuildHelper._ import explicitdeps.ExplicitDepsPlugin.autoImport.moduleFilterRemoveValue import sbtcrossproject.CrossPlugin.autoImport.crossProject Global / onChangedBuildSource := IgnoreSourceChanges +enablePlugins(ZioSbtEcosystemPlugin, ZioSbtCiPlugin) + +usefulTasksAndSettings ++= BuildHelper.usefulTasksAndSettings.value + inThisBuild( List( organization := "dev.zio", + name := "zio-json", homepage := Some(url("https://zio.dev/zio-json/")), licenses := List("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")), developers := List( @@ -16,7 +20,10 @@ inThisBuild( "john@degoes.net", url("http://degoes.net") ) - ) + ), + scalaVersion := scala213.value, + javaPlatform := zio.sbt.JavaVersion.`11`, + ciEnabledBranches := Seq("series/2.x") ) ) @@ -25,43 +32,10 @@ addCommandAlias("fmt", "all scalafmtSbt scalafmtAll") addCommandAlias("fmtCheck", "all scalafmtSbtCheck scalafmtCheckAll") addCommandAlias("prepare", "fmt") -addCommandAlias( - "testJVM", - "zioJsonJVM/test; zioJsonYaml/test; zioJsonInteropHttp4s/test; zioJsonInteropScalaz7xJVM/test; zioJsonGolden/test" -) - -addCommandAlias( - "testScala2JVM", - "zioJsonMacrosJVM/test; zioJsonInteropRefinedJVM/test" -) - -addCommandAlias( - "testScala2JS", - "zioJsonMacrosJS/test; zioJsonInteropRefinedJS/test" -) - -addCommandAlias( - "testScala2Native", - "zioJsonMacrosNative/test; zioJsonInteropRefinedNative/test" -) - -addCommandAlias( - "testJS", - "zioJsonJS/test; zioJsonInteropScalaz7xJS/test" -) - -addCommandAlias( - "testNative", - "zioJsonNative/test; zioJsonInteropScalaz7xNative/test" -) - -val zioVersion = "2.1.7" - lazy val zioJsonRoot = project .in(file(".")) .settings( - publish / skip := true, - unusedCompileDependenciesFilter -= moduleFilter("org.scala-js", "scalajs-library") + publish / skip := true ) .aggregate( docs, @@ -82,53 +56,51 @@ lazy val zioJsonRoot = project zioJsonGolden ) -val circeVersion = "0.14.10" - lazy val zioJson = crossProject(JSPlatform, JVMPlatform, NativePlatform) .in(file("zio-json")) - .settings(stdSettings("zio-json")) + .settings(stdSettings(Some("zio-json"))) .settings(crossProjectSettings) .settings(buildInfoSettings("zio.json")) .enablePlugins(NeoJmhPlugin) .settings( scalacOptions -= "-Xfatal-warnings", // not quite ready. - // as per @fommil, optimization slows things down. scalacOptions -= "-opt:l:inline", scalacOptions -= "-opt-inline-from:zio.internal.**", Test / scalacOptions ++= { - if (scalaVersion.value == ScalaDotty) + if (isScala3.value) Vector("-Yretain-trees") else Vector.empty }, libraryDependencies ++= Seq( - "dev.zio" %%% "zio" % zioVersion, - "dev.zio" %%% "zio-streams" % zioVersion, + "dev.zio" %%% "zio" % Version.zio, + "dev.zio" %%% "zio-streams" % Version.zio, "org.scala-lang.modules" %%% "scala-collection-compat" % "2.12.0", - "dev.zio" %%% "zio-test" % zioVersion % "test", - "dev.zio" %%% "zio-test-sbt" % zioVersion % "test", - "io.circe" %%% "circe-core" % circeVersion % "test", - "io.circe" %%% "circe-generic" % circeVersion % "test", - "io.circe" %%% "circe-parser" % circeVersion % "test" + "dev.zio" %%% "zio-test" % Version.zio % "test", + "dev.zio" %%% "zio-test-sbt" % Version.zio % "test", + "io.circe" %%% "circe-core" % Version.circe % "test", + "io.circe" %%% "circe-generic" % Version.circe % "test", + "io.circe" %%% "circe-parser" % Version.circe % "test" ), // scala version specific dependencies libraryDependencies ++= { - CrossVersion.partialVersion(scalaVersion.value) match { - case Some((3, _)) => - Vector( - "com.softwaremill.magnolia1_3" %%% "magnolia" % "1.3.7" - ) - - case _ => - Vector( - "org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided, - "com.softwaremill.magnolia1_2" %%% "magnolia" % "1.1.10", - "io.circe" %%% "circe-generic-extras" % "0.14.4" % "test", - "com.github.plokhotnyuk.jsoniter-scala" %%% "jsoniter-scala-core" % "2.30.9" % "test", - "com.github.plokhotnyuk.jsoniter-scala" %%% "jsoniter-scala-macros" % "2.30.9" % "test" - ) - } + if (isScala3.value) + Vector( + "com.softwaremill.magnolia1_3" %%% "magnolia" % Version.magnolia1_3, + "com.github.ghik" % s"silencer-lib_${scala213.value}" % Version.silencer % Provided + ) + else + Vector( + "com.github.ghik" % "silencer-lib" % Version.silencer % Provided cross CrossVersion.full, + compilerPlugin("com.github.ghik" % "silencer-plugin" % Version.silencer cross CrossVersion.full), + compilerPlugin("org.typelevel" %% "kind-projector" % "0.13.3" cross CrossVersion.full), + "org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided, + "com.softwaremill.magnolia1_2" %%% "magnolia" % Version.magnolia1_2, + "io.circe" %%% "circe-generic-extras" % "0.14.4" % "test", + "com.github.plokhotnyuk.jsoniter-scala" %%% "jsoniter-scala-core" % "2.30.9" % "test", + "com.github.plokhotnyuk.jsoniter-scala" %%% "jsoniter-scala-macros" % "2.30.9" % "test" + ) }, Compile / sourceGenerators += Def.task { val dir = (Compile / sourceManaged).value @@ -192,7 +164,7 @@ lazy val zioJson = crossProject(JSPlatform, JVMPlatform, NativePlatform) |}""".stripMargin ) Seq(file) - }.taskValue, + }, Compile / sourceGenerators += Def.task { val dir = (Compile / sourceManaged).value val file = dir / "zio" / "json" / "GeneratedTupleCodecs.scala" @@ -215,168 +187,156 @@ lazy val zioJson = crossProject(JSPlatform, JVMPlatform, NativePlatform) }.taskValue, inConfig(Jmh)(org.scalafmt.sbt.ScalafmtPlugin.scalafmtConfigSettings) ) - .settings(testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework")) .jsSettings( - libraryDependencies ++= Seq( - "io.github.cquiroz" %%% "scala-java-time" % scalaJavaTimeVersion, - "io.github.cquiroz" %%% "scala-java-time-tzdb" % scalaJavaTimeVersion + jsSettings ++ Seq( + libraryDependencies ++= Seq( + "io.github.cquiroz" %%% "scala-java-time" % Version.scalaJavaTime, + "io.github.cquiroz" %%% "scala-java-time-tzdb" % Version.scalaJavaTime + ), + scalaJSUseMainModuleInitializer := true, + coverageEnabled := false + ) + ) + .jvmSettings(jvmSettings) + .nativeSettings( + nativeSettings ++ Seq( + libraryDependencies ++= Seq( + "io.github.cquiroz" %%% "scala-java-time" % Version.scalaJavaTime + ) ) ) .jvmSettings( libraryDependencies ++= { - CrossVersion.partialVersion(scalaVersion.value) match { - case Some((3, _)) => - Vector( - "org.typelevel" %% "jawn-ast" % "1.6.0" % "test" - ) - - case Some((2, n)) => - if (n >= 13) { - Seq( - "com.particeep" %% "play-json-extensions" % "0.43.1" % "test", - "com.typesafe.play" %%% "play-json" % "2.9.4" % "test", - "org.typelevel" %% "jawn-ast" % "1.6.0" % "test" - ) - } else { - Seq( - "ai.x" %% "play-json-extensions" % "0.42.0" % "test", - "com.typesafe.play" %%% "play-json" % "2.9.4" % "test", - "org.typelevel" %% "jawn-ast" % "1.6.0" % "test" - ) - } - - case _ => - Seq.empty - } + if (isScala3.value) + Vector( + "org.typelevel" %% "jawn-ast" % "1.6.0" % "test" + ) + else if (isScala2_13.value) + Seq( + "com.particeep" %% "play-json-extensions" % "0.43.1" % "test", + "com.typesafe.play" %%% "play-json" % "2.9.4" % "test", + "org.typelevel" %% "jawn-ast" % "1.6.0" % "test" + ) + else if (isScala2_12.value) + Seq( + "ai.x" %% "play-json-extensions" % "0.42.0" % "test", + "com.typesafe.play" %%% "play-json" % "2.9.4" % "test", + "org.typelevel" %% "jawn-ast" % "1.6.0" % "test" + ) + else + Seq.empty } ) - .nativeSettings(Test / fork := false) - .nativeSettings( - libraryDependencies ++= Seq( - "io.github.cquiroz" %%% "scala-java-time" % scalaJavaTimeVersion - ), - nativeConfig ~= { _.withMultithreading(false) } - ) - .enablePlugins(BuildInfoPlugin) lazy val zioJsonJS = zioJson.js - .settings( - scalaJSUseMainModuleInitializer := true, - testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"), - coverageEnabled := false - ) lazy val zioJsonJVM = zioJson.jvm lazy val zioJsonGolden = project .in(file("zio-json-golden")) - .settings(stdSettings("zio-json-golden")) + .settings(stdSettings(Some("zio-json-golden"))) .settings(buildInfoSettings("zio.json.golden")) .settings( libraryDependencies ++= Seq( - "dev.zio" %% "zio" % zioVersion, - "dev.zio" %% "zio-test" % zioVersion, - "dev.zio" %% "zio-test-sbt" % zioVersion, - "dev.zio" %% "zio-test-magnolia" % zioVersion - ), - testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework") + "dev.zio" %% "zio" % Version.zio, + "dev.zio" %% "zio-test" % Version.zio, + "dev.zio" %% "zio-test-sbt" % Version.zio, + "dev.zio" %% "zio-test-magnolia" % Version.zio + ) ) .dependsOn(zioJsonJVM) - .enablePlugins(BuildInfoPlugin) lazy val zioJsonYaml = project .in(file("zio-json-yaml")) - .settings(stdSettings("zio-json-yaml")) + .settings(stdSettings(Some("zio-json-yaml"))) .settings(buildInfoSettings("zio.json.yaml")) .settings( libraryDependencies ++= Seq( - "org.yaml" % "snakeyaml" % "2.3", - "dev.zio" %% "zio" % zioVersion, - "dev.zio" %% "zio-test" % zioVersion % "test", - "dev.zio" %% "zio-test-sbt" % zioVersion % "test" - ), - testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework") + "org.yaml" % "snakeyaml" % Version.snakeyaml, + "dev.zio" %% "zio" % Version.zio, + "dev.zio" %% "zio-test" % Version.zio % "test", + "dev.zio" %% "zio-test-sbt" % Version.zio % "test" + ) ) .dependsOn(zioJsonJVM) - .enablePlugins(BuildInfoPlugin) lazy val zioJsonMacros = crossProject(JSPlatform, JVMPlatform, NativePlatform) .in(file("zio-json-macros")) - .nativeConfigure(_.dependsOn(zioJson.native)) - .settings(stdSettings("zio-json-macros")) + .dependsOn(zioJson) + .settings(stdSettings(Some("zio-json-macros"))) .settings(crossProjectSettings) .settings(macroExpansionSettings) .settings( - crossScalaVersions -= ScalaDotty, - scalacOptions -= "-Xfatal-warnings", // not quite ready. + crossScalaVersions -= scala3.value, libraryDependencies ++= Seq( "org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided, - "dev.zio" %%% "zio-test" % zioVersion % "test", - "dev.zio" %%% "zio-test-sbt" % zioVersion % "test" - ), - testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"), - nativeConfig ~= { _.withMultithreading(false) } + "dev.zio" %%% "zio-test" % Version.zio % "test", + "dev.zio" %%% "zio-test-sbt" % Version.zio % "test" + ) + ) + .jsSettings( + coverageEnabled := false ) - .nativeSettings(Test / fork := false) + .jsSettings(jsSettings) + .jvmSettings(jvmSettings) + .nativeSettings(nativeSettings) -lazy val zioJsonMacrosJVM = zioJsonMacros.jvm.dependsOn(zioJsonJVM) +lazy val zioJsonMacrosJVM = zioJsonMacros.jvm lazy val zioJsonMacrosJS = zioJsonMacros.js - .settings(coverageEnabled := false) - .dependsOn(zioJsonJS) lazy val zioJsonInteropHttp4s = project .in(file("zio-json-interop-http4s")) - .settings(stdSettings("zio-json-interop-http4s")) + .settings(stdSettings(Some("zio-json-interop-http4s"))) .settings(buildInfoSettings("zio.json.interop.http4s")) .settings( - crossScalaVersions -= ScalaDotty, libraryDependencies ++= Seq( - "org.http4s" %% "http4s-dsl" % "0.23.29", - "dev.zio" %% "zio" % zioVersion, - "org.typelevel" %% "cats-effect" % "3.4.9", - "dev.zio" %% "zio-interop-cats" % "23.1.0.3" % "test", - "dev.zio" %% "zio-test" % zioVersion % "test", - "dev.zio" %% "zio-test-sbt" % zioVersion % "test" - ), - testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework") + "org.http4s" %% "http4s-dsl" % Version.http4s, + "dev.zio" %% "zio" % Version.zio, + "org.typelevel" %% "cats-effect" % Version.catsEffect, + "dev.zio" %% "zio-interop-cats" % Version.zioInteropCats % "test", + "dev.zio" %% "zio-test" % Version.zio % "test", + "dev.zio" %% "zio-test-sbt" % Version.zio % "test" + ) ) .dependsOn(zioJsonJVM) - .enablePlugins(BuildInfoPlugin) lazy val zioJsonInteropRefined = crossProject(JSPlatform, JVMPlatform, NativePlatform) .in(file("zio-json-interop-refined")) .dependsOn(zioJson) - .settings(stdSettings("zio-json-interop-refined")) + .settings(stdSettings(Some("zio-json-interop-refined"))) .settings(buildInfoSettings("zio.json.interop.refined")) .settings( + crossScalaVersions -= scala3.value, // no working version of refined for scala 3 yet, published artifacts are incomplete libraryDependencies ++= Seq( - "eu.timepit" %%% "refined" % "0.11.2", - "dev.zio" %%% "zio-test" % zioVersion % "test", - "dev.zio" %%% "zio-test-sbt" % zioVersion % "test" - ), - testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework") + "eu.timepit" %%% "refined" % Version.refined, + "dev.zio" %%% "zio-test" % Version.zio % "test", + "dev.zio" %%% "zio-test-sbt" % Version.zio % "test" + ) ) - .enablePlugins(BuildInfoPlugin) + .jsSettings(jsSettings) + .jvmSettings(jvmSettings) + .nativeSettings(nativeSettings) lazy val zioJsonInteropScalaz7x = crossProject(JSPlatform, JVMPlatform, NativePlatform) .in(file("zio-json-interop-scalaz7x")) .dependsOn(zioJson) - .settings(stdSettings("zio-json-interop-scalaz7x")) + .settings(stdSettings(Some("zio-json-interop-scalaz7x"))) .settings(buildInfoSettings("zio.json.interop.scalaz7x")) .settings( - crossScalaVersions -= ScalaDotty, libraryDependencies ++= Seq( - "org.scalaz" %%% "scalaz-core" % "7.3.8", - "dev.zio" %%% "zio-test" % zioVersion % "test", - "dev.zio" %%% "zio-test-sbt" % zioVersion % "test" - ), - testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework") + "org.scalaz" %%% "scalaz-core" % Version.scalaz, + "dev.zio" %%% "zio-test" % Version.zio % "test", + "dev.zio" %%% "zio-test-sbt" % Version.zio % "test" + ) ) - .enablePlugins(BuildInfoPlugin) + .jsSettings(jsSettings) + .jvmSettings(jvmSettings) + .nativeSettings(nativeSettings) lazy val docs = project .in(file("zio-json-docs")) + .settings(macroExpansionSettings) .dependsOn( zioJsonJVM, zioJsonYaml, @@ -387,9 +347,8 @@ lazy val docs = project zioJsonInteropScalaz7x.jvm ) .settings( - crossScalaVersions -= ScalaDotty, + crossScalaVersions -= scala3.value, moduleName := "zio-json-docs", - scalacOptions += "-Ymacro-annotations", projectName := "ZIO JSON", mainModuleName := (zioJsonJVM / moduleName).value, projectStage := ProjectStage.ProductionReady, diff --git a/project/BuildHelper.scala b/project/BuildHelper.scala index 77ec4c3c..53e63edd 100644 --- a/project/BuildHelper.scala +++ b/project/BuildHelper.scala @@ -5,99 +5,7 @@ import sbt._ import sbtbuildinfo.BuildInfoKeys._ import sbtbuildinfo._ import sbtcrossproject.CrossPlugin.autoImport._ - object BuildHelper { - private val versions: Map[String, String] = { - import org.snakeyaml.engine.v2.api.{ Load, LoadSettings } - import java.util.{ List => JList, Map => JMap } - import scala.jdk.CollectionConverters._ - - val doc = new Load(LoadSettings.builder().build()) - .loadFromReader(scala.io.Source.fromFile(".github/workflows/ci.yml").bufferedReader()) - val yaml = doc.asInstanceOf[JMap[String, JMap[String, JMap[String, JMap[String, JMap[String, JList[String]]]]]]] - val list = yaml.get("jobs").get("test").get("strategy").get("matrix").get("scala").asScala - list.map(v => (v.split('.').take(2).mkString("."), v)).toMap - } - val Scala212: String = versions("2.12") - val Scala213: String = versions("2.13") - val ScalaDotty: String = "3.3.4" - - val SilencerVersion = "1.7.19" - - private val stdOptions = Seq( - "-deprecation", - "-encoding", - "UTF-8", - "-feature", - "-unchecked" - ) ++ { - if (sys.env.contains("CI")) { - // Seq("-Xfatal-warnings") // enable this when we are ready to enforce this - Nil - } else { - Nil // to enable Scalafix locally - } - } - - private val std2xOptions = Seq( - "-language:higherKinds", - "-language:existentials", - "-explaintypes", - "-Yrangepos", - "-Xlint:_,-missing-interpolator,-type-parameter-shadow", - "-Ywarn-numeric-widen", - "-Ywarn-value-discard" - ) - - private def optimizerOptions(optimize: Boolean) = - if (optimize) - Seq( - "-opt:l:inline", - "-opt-inline-from:zio.internal.**" - ) - else Nil - - def buildInfoSettings(packageName: String) = - Seq( - buildInfoKeys := Seq[BuildInfoKey](organization, moduleName, name, version, scalaVersion, sbtVersion, isSnapshot), - buildInfoPackage := packageName - ) - - val dottySettings = Seq( - crossScalaVersions += ScalaDotty, - scalacOptions ++= { - if (scalaVersion.value == ScalaDotty) - Seq("-noindent") - else - Seq() - }, - scalacOptions --= { - if (scalaVersion.value == ScalaDotty) - Seq("-Xfatal-warnings") - else - Seq() - }, - Compile / doc / sources := { - val old = (Compile / doc / sources).value - if (scalaVersion.value == ScalaDotty) { - Nil - } else { - old - } - }, - Test / parallelExecution := { - val old = (Test / parallelExecution).value - if (scalaVersion.value == ScalaDotty) { - false - } else { - old - } - } - ) - - val scalaReflectSettings = Seq( - libraryDependencies ++= Seq("dev.zio" %%% "izumi-reflect" % "1.0.0-M10") - ) // Keep this consistent with the version in .core-tests/shared/src/test/scala/REPLSpec.scala val replSettings = makeReplSettings { @@ -138,184 +46,9 @@ object BuildHelper { Compile / console / initialCommands := initialCommandsStr ) - def extraOptions(scalaVersion: String, optimize: Boolean) = - CrossVersion.partialVersion(scalaVersion) match { - case Some((3, 1)) => - Seq( - "-language:implicitConversions", - "-Xignore-scala2-macros" - ) - case Some((2, 13)) => - Seq( - "-Ywarn-unused:params,-implicits", - "-Wconf:msg=Boolean literals should be passed:s" - ) ++ std2xOptions ++ optimizerOptions(optimize) - case Some((2, 12)) => - Seq( - "-opt-warnings", - "-Ywarn-extra-implicit", - "-Ywarn-unused:_,imports", - "-Ywarn-unused:imports", - "-Ypartial-unification", - "-Yno-adapted-args", - "-Ywarn-inaccessible", - "-Ywarn-infer-any", - "-Ywarn-nullary-override", - "-Ywarn-nullary-unit", - "-Ywarn-unused:params,-implicits", - "-Xfuture", - "-Xsource:2.13", - "-Xmax-classfile-name", - "242" - ) ++ std2xOptions ++ optimizerOptions(optimize) - case _ => Seq.empty - } - - def platformSpecificSources(platform: String, conf: String, baseDirectory: File)(versions: String*) = for { - platform <- List("shared", platform) - version <- "scala" :: versions.toList.map("scala-" + _) - result = baseDirectory.getParentFile / platform.toLowerCase / "src" / conf / version - if result.exists - } yield result - - def crossPlatformSources(scalaVer: String, platform: String, conf: String, baseDir: File) = { - val versions = CrossVersion.partialVersion(scalaVer) match { - case Some((2, 12)) => - List("2.12", "2.12+", "2.12-2.13", "2.x") - case Some((2, 13)) => - List("2.13", "2.12+", "2.13+", "2.12-2.13", "2.x") - case Some((3, _)) => - List("dotty", "2.12+", "2.13+", "3.x") - case _ => - List.empty - } - platformSpecificSources(platform, conf, baseDir)(versions: _*) - } - - lazy val crossProjectSettings = Seq( - Compile / unmanagedSourceDirectories ++= { - crossPlatformSources( - scalaVersion.value, - crossProjectPlatform.value.identifier, - "main", - baseDirectory.value - ) - }, - Test / unmanagedSourceDirectories ++= { - crossPlatformSources( - scalaVersion.value, - crossProjectPlatform.value.identifier, - "test", - baseDirectory.value - ) - } - ) - - def stdSettings(prjName: String) = Seq( - name := s"$prjName", - crossScalaVersions := Seq(Scala212, Scala213, ScalaDotty), - ThisBuild / scalaVersion := Scala213, - scalacOptions ++= stdOptions ++ extraOptions(scalaVersion.value, optimize = !isSnapshot.value), - libraryDependencies ++= { - if (scalaVersion.value == ScalaDotty) - Seq( - "com.github.ghik" % s"silencer-lib_$Scala213" % SilencerVersion % Provided - ) - else - Seq( - "com.github.ghik" % "silencer-lib" % SilencerVersion % Provided cross CrossVersion.full, - compilerPlugin("com.github.ghik" % "silencer-plugin" % SilencerVersion cross CrossVersion.full), - compilerPlugin("org.typelevel" %% "kind-projector" % "0.13.3" cross CrossVersion.full) - ) - }, - semanticdbEnabled := scalaVersion.value != ScalaDotty, // enable SemanticDB - semanticdbOptions += "-P:semanticdb:synthetics:on", - semanticdbVersion := "4.10.2", - Test / parallelExecution := true, - incOptions ~= (_.withLogRecompileOnMacro(false)), - autoAPIMappings := true, - unusedCompileDependenciesFilter -= moduleFilter("org.scala-js", "scalajs-library") - ) - - def macroExpansionSettings = Seq( - scalacOptions ++= { - CrossVersion.partialVersion(scalaVersion.value) match { - case Some((2, 13)) => Seq("-Ymacro-annotations") - case _ => Seq.empty - } - }, - libraryDependencies ++= { - CrossVersion.partialVersion(scalaVersion.value) match { - case Some((2, x)) if x <= 12 => - Seq(compilerPlugin(("org.scalamacros" % "paradise" % "2.1.1").cross(CrossVersion.full))) - case _ => Seq.empty - } - } - ) - - def macroDefinitionSettings = Seq( - scalacOptions += "-language:experimental.macros", - libraryDependencies ++= { - if (scalaVersion.value == ScalaDotty) Seq() - else - Seq( - "org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided", - "org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided" - ) - } - ) - - val scalaJavaTimeVersion = "2.6.0" - - def jsSettings = + def usefulTasksAndSettings: Def.Initialize[Seq[(String, String)]] = Def.setting { Seq( - libraryDependencies += "io.github.cquiroz" %%% "scala-java-time" % scalaJavaTimeVersion, - libraryDependencies += "io.github.cquiroz" %%% "scala-java-time-tzdb" % scalaJavaTimeVersion + "docs/docusaurusCreateSite" -> "Generates the ZIO microsite." ) - - def nativeSettings = Seq( - Test / skip := true, - doc / skip := true, - Compile / doc / sources := Seq.empty - ) - - val scalaReflectTestSettings: List[Setting[_]] = List( - libraryDependencies ++= { - if (scalaVersion.value == ScalaDotty) - Seq("org.scala-lang" % "scala-reflect" % Scala213 % Test) - else - Seq("org.scala-lang" % "scala-reflect" % scalaVersion.value % Test) - } - ) - - def welcomeMessage = onLoadMessage := { - import scala.Console - - def header(text: String): String = s"${Console.RED}$text${Console.RESET}" - - def item(text: String): String = s"${Console.GREEN}> ${Console.CYAN}$text${Console.RESET}" - def subItem(text: String): String = s" ${Console.YELLOW}> ${Console.CYAN}$text${Console.RESET}" - - s"""|${header(" ________ ___")} - |${header("|__ /_ _/ _ \\")} - |${header(" / / | | | | |")} - |${header(" / /_ | | |_| |")} - |${header(s"/____|___\\___/ ${version.value}")} - | - |Useful sbt tasks: - |${item("build")} - Prepares sources, compiles and runs tests. - |${item("prepare")} - Prepares sources by applying scalafmt - |${item("fmt")} - Formats source files using scalafmt - |${item("~compileJVM")} - Compiles all JVM modules (file-watch enabled) - |${item("testJVM")} - Runs all JVM tests - |${item("testJS")} - Runs all ScalaJS tests - |${item("testOnly *.YourSpec -- -t \"YourLabel\"")} - Only runs tests with matching term e.g. - |${subItem("coreTestsJVM/testOnly *.ZIOSpec -- -t \"happy-path\"")} - |${item("docs/docusaurusCreateSite")} - Generates the ZIO microsite - """.stripMargin - } - - implicit class ModuleHelper(p: Project) { - def module: Project = p.in(file(p.id)).settings(stdSettings(p.id)) } } diff --git a/project/Version.scala b/project/Version.scala new file mode 100644 index 00000000..a6ad6600 --- /dev/null +++ b/project/Version.scala @@ -0,0 +1,16 @@ +object Version { + + val catsEffect = "3.4.9" + val circe = "0.14.10" + val http4s = "0.23.29" + val izumi = "1.0.0-M10" + val magnolia1_2 = "1.1.10" + val magnolia1_3 = "1.3.7" + val refined = "0.11.2" + val scalaz = "7.3.8" + val silencer = "1.7.19" + val snakeyaml = "2.3" + val scalaJavaTime = "2.6.0" + val zio = "2.1.11" + val zioInteropCats = "23.1.0.3" +} diff --git a/project/plugins.sbt b/project/plugins.sbt index 20f44992..d18d567d 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,3 +1,5 @@ +val zioSbtVersion = "0.0.0+524-5fdf568b-SNAPSHOT" + addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.13.0") addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.6.1") addSbtPlugin("com.github.cb372" % "sbt-explicit-dependencies" % "0.3.1") @@ -7,10 +9,10 @@ addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.3.2") addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.3.2") addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.17.0") addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.5.5") -addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0") addSbtPlugin("pl.project13.scala" % "sbt-jcstress" % "0.2.0") addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.11") -addSbtPlugin("dev.zio" % "zio-sbt-website" % "0.4.0-alpha.28") -addSbtPlugin("dev.zio" % "zio-sbt-website" % "0.4.0-alpha.27") +addSbtPlugin("nl.thijsbroersen" % "zio-sbt-ci" % zioSbtVersion) +addSbtPlugin("nl.thijsbroersen" % "zio-sbt-ecosystem" % zioSbtVersion) +addSbtPlugin("nl.thijsbroersen" % "zio-sbt-website" % zioSbtVersion) -libraryDependencies += "org.snakeyaml" % "snakeyaml-engine" % "2.8" +resolvers ++= Resolver.sonatypeOssRepos("snapshots") diff --git a/zio-json/jvm/src/test/scala-2/zio/json/DecoderPlatformSpecificSpec.scala b/zio-json/jvm/src/test/scala-2/zio/json/DecoderPlatformSpecificSpec.scala index eab496ca..4654e418 100644 --- a/zio-json/jvm/src/test/scala-2/zio/json/DecoderPlatformSpecificSpec.scala +++ b/zio-json/jvm/src/test/scala-2/zio/json/DecoderPlatformSpecificSpec.scala @@ -236,7 +236,7 @@ object DecoderPlatformSpecificSpec extends ZIOSpecDefault { import logEvent._ for { - lines <- readJsonLinesAs[Event](Paths.get("zio-json/jvm/src/test/resources/log.jsonlines")).runCollect + lines <- readJsonLinesAs[Event](Paths.get("src/test/resources/log.jsonlines")).runCollect } yield { assert(lines(0))(equalTo(Event(1603669875, "hello"))) && assert(lines(1))(equalTo(Event(1603669876, "world")))