From e7475d82b718f81195ca8d670428279f540470fc Mon Sep 17 00:00:00 2001 From: Frank Thomas Date: Thu, 9 Mar 2023 20:38:58 +0100 Subject: [PATCH] Build core and calev modules for Scala.js (#415) --- .github/workflows/ci.yml | 42 +++++++++++++++++-- .mergify.yml | 3 ++ build.sbt | 32 ++++++++++---- .../fs2cron/ZonedDateTimeScheduler.scala | 4 +- project/Dependencies.scala | 9 ---- 5 files changed, 66 insertions(+), 24 deletions(-) delete mode 100644 project/Dependencies.scala diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 84344c0..2d874e3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,7 +30,7 @@ jobs: os: [ubuntu-latest] scala: [2.12.17, 2.13.10, 3.2.2] java: [temurin@8] - project: [rootJVM] + project: [rootJS, rootJVM] runs-on: ${{ matrix.os }} steps: - name: Checkout current branch (full) @@ -73,6 +73,10 @@ jobs: if: matrix.java == 'temurin@8' && matrix.os == 'ubuntu-latest' run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' headerCheckAll scalafmtCheckAll 'project /' scalafmtSbtCheck + - name: scalaJSLink + if: matrix.project == 'rootJS' + run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' Test/scalaJSLinkerResult + - name: Test run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' test @@ -85,7 +89,7 @@ jobs: run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' doc - name: Check README - if: matrix.scala != '3.2.2' + if: matrix.scala != '3.2.2' && matrix.project == 'rootJVM' run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' readme/mdoc - name: Generate coverage report @@ -97,11 +101,11 @@ jobs: - name: Make target directories if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/master') - run: mkdir -p target .js/target modules/cron4s/.jvm/target .jvm/target .native/target modules/cron-utils/.jvm/target modules/readme/target modules/core/.jvm/target modules/calev/.jvm/target project/target + run: mkdir -p target .js/target modules/core/.js/target modules/cron4s/.jvm/target .jvm/target .native/target modules/cron-utils/.jvm/target modules/readme/target modules/calev/.js/target modules/core/.jvm/target modules/calev/.jvm/target project/target - name: Compress target directories if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/master') - run: tar cf targets.tar target .js/target modules/cron4s/.jvm/target .jvm/target .native/target modules/cron-utils/.jvm/target modules/readme/target modules/core/.jvm/target modules/calev/.jvm/target project/target + run: tar cf targets.tar target .js/target modules/core/.js/target modules/cron4s/.jvm/target .jvm/target .native/target modules/cron-utils/.jvm/target modules/readme/target modules/calev/.js/target modules/core/.jvm/target modules/calev/.jvm/target project/target - name: Upload target directories if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/master') @@ -154,6 +158,16 @@ jobs: ~/Library/Caches/Coursier/v1 key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }} + - name: Download target directories (2.12.17, rootJS) + uses: actions/download-artifact@v3 + with: + name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.17-rootJS + + - name: Inflate target directories (2.12.17, rootJS) + run: | + tar xf targets.tar + rm targets.tar + - name: Download target directories (2.12.17, rootJVM) uses: actions/download-artifact@v3 with: @@ -164,6 +178,16 @@ jobs: tar xf targets.tar rm targets.tar + - name: Download target directories (2.13.10, rootJS) + uses: actions/download-artifact@v3 + with: + name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.10-rootJS + + - name: Inflate target directories (2.13.10, rootJS) + run: | + tar xf targets.tar + rm targets.tar + - name: Download target directories (2.13.10, rootJVM) uses: actions/download-artifact@v3 with: @@ -174,6 +198,16 @@ jobs: tar xf targets.tar rm targets.tar + - name: Download target directories (3.2.2, rootJS) + uses: actions/download-artifact@v3 + with: + name: target-${{ matrix.os }}-${{ matrix.java }}-3.2.2-rootJS + + - name: Inflate target directories (3.2.2, rootJS) + run: | + tar xf targets.tar + rm targets.tar + - name: Download target directories (3.2.2, rootJVM) uses: actions/download-artifact@v3 with: diff --git a/.mergify.yml b/.mergify.yml index edebdb2..73d803e 100644 --- a/.mergify.yml +++ b/.mergify.yml @@ -17,8 +17,11 @@ pull_request_rules: - name: merge scala-steward's PRs conditions: - author=scala-steward + - status-success=Build and Test (ubuntu-latest, 2.12.17, temurin@8, rootJS) - status-success=Build and Test (ubuntu-latest, 2.12.17, temurin@8, rootJVM) + - status-success=Build and Test (ubuntu-latest, 2.13.10, temurin@8, rootJS) - status-success=Build and Test (ubuntu-latest, 2.13.10, temurin@8, rootJVM) + - status-success=Build and Test (ubuntu-latest, 3.2.2, temurin@8, rootJS) - status-success=Build and Test (ubuntu-latest, 3.2.2, temurin@8, rootJVM) actions: merge: diff --git a/build.sbt b/build.sbt index 2ccf0b6..2e62348 100644 --- a/build.sbt +++ b/build.sbt @@ -5,15 +5,14 @@ import sbtcrossproject.{CrossProject, CrossType, Platform} val groupId = "eu.timepit" val projectName = "fs2-cron" val rootPkg = s"$groupId.${projectName.replace("-", "")}" -val gitHubOwner = "fthomas" val Scala_2_12 = "2.12.17" val Scala_2_13 = "2.13.10" val Scala_3 = "3.2.2" val moduleCrossPlatformMatrix: Map[String, List[Platform]] = Map( - "calev" -> List(JVMPlatform), - "core" -> List(JVMPlatform), + "calev" -> List(JVMPlatform, JSPlatform), + "core" -> List(JVMPlatform, JSPlatform), "cron4s" -> List(JVMPlatform), "cron-utils" -> List(JVMPlatform) ) @@ -35,7 +34,7 @@ ThisBuild / githubWorkflowBuild ++= Seq( WorkflowStep.Sbt( commands = List("readme/mdoc"), name = Some("Check README"), - cond = Some(s"matrix.scala != '$Scala_3'") + cond = Some(s"matrix.scala != '$Scala_3' && matrix.project == 'rootJVM'") ), WorkflowStep.Sbt( commands = List("coverage", "test", "coverageReport"), @@ -71,26 +70,41 @@ lazy val root = tlCrossRootProject lazy val core = myCrossProject("core") .settings( libraryDependencies ++= Seq( - Dependencies.fs2Core, - Dependencies.munitCatsEffect % Test + "co.fs2" %%% "fs2-core" % "3.6.1", + "org.typelevel" %%% "munit-cats-effect-3" % "1.0.7" % Test + ) + ) + .jsSettings( + tlVersionIntroduced := Map( + "2.12" -> "0.8.3", + "2.13" -> "0.8.3", + "3" -> "0.8.3" ) ) lazy val calev = myCrossProject("calev") .dependsOn(core % "compile->compile;test->test") .settings( - libraryDependencies += Dependencies.calevCore, + libraryDependencies += "com.github.eikek" %%% "calev-core" % "0.6.4", initialCommands += s""" import $rootPkg.calev._ import com.github.eikek.calev._ """ ) + .jsSettings( + libraryDependencies += "io.github.cquiroz" %%% "scala-java-time-tzdb" % "2.5.0" % Test, + tlVersionIntroduced := Map( + "2.12" -> "0.8.3", + "2.13" -> "0.8.3", + "3" -> "0.8.3" + ) + ) lazy val cron4s = myCrossProject("cron4s") .dependsOn(core % "compile->compile;test->test") .settings( crossScalaVersions := List(Scala_2_12, Scala_2_13), - libraryDependencies += Dependencies.cron4s, + libraryDependencies += "com.github.alonsodomin.cron4s" %% "cron4s-core" % "0.6.1", initialCommands += s""" import $rootPkg.cron4s._ import _root_.cron4s.Cron @@ -101,7 +115,7 @@ lazy val cron4s = myCrossProject("cron4s") lazy val cronUtils = myCrossProject("cron-utils") .dependsOn(core % "compile->compile;test->test") .settings( - libraryDependencies += Dependencies.cronUtils, + libraryDependencies += "com.cronutils" % "cron-utils" % "9.2.0", initialCommands += s""" import $rootPkg.cronutils._ import com.cronutils.model.CronType diff --git a/modules/core/src/main/scala/eu/timepit/fs2cron/ZonedDateTimeScheduler.scala b/modules/core/src/main/scala/eu/timepit/fs2cron/ZonedDateTimeScheduler.scala index 71b725d..6102dc9 100644 --- a/modules/core/src/main/scala/eu/timepit/fs2cron/ZonedDateTimeScheduler.scala +++ b/modules/core/src/main/scala/eu/timepit/fs2cron/ZonedDateTimeScheduler.scala @@ -20,7 +20,7 @@ import cats.effect.{Sync, Temporal} import cats.syntax.all._ import java.time.temporal.ChronoUnit -import java.time.{ZoneId, ZoneOffset, ZonedDateTime} +import java.time.{Instant, ZoneId, ZoneOffset, ZonedDateTime} import java.util.concurrent.TimeUnit import scala.concurrent.duration.FiniteDuration @@ -38,7 +38,7 @@ abstract class ZonedDateTimeScheduler[F[_], Schedule](zoneId: F[ZoneId])(implici } private val now: F[ZonedDateTime] = - (temporal.realTimeInstant, zoneId).mapN(_.atZone(_)) + (temporal.realTime, zoneId).mapN((d, z) => Instant.EPOCH.plusNanos(d.toNanos).atZone(z)) } object ZonedDateTimeScheduler { diff --git a/project/Dependencies.scala b/project/Dependencies.scala deleted file mode 100644 index 22436fe..0000000 --- a/project/Dependencies.scala +++ /dev/null @@ -1,9 +0,0 @@ -import sbt._ - -object Dependencies { - val calevCore = "com.github.eikek" %% "calev-core" % "0.6.4" - val cron4s = "com.github.alonsodomin.cron4s" %% "cron4s-core" % "0.6.1" - val cronUtils = "com.cronutils" % "cron-utils" % "9.2.0" - val fs2Core = "co.fs2" %% "fs2-core" % "3.6.1" - val munitCatsEffect = "org.typelevel" %% "munit-cats-effect-3" % "1.0.7" -}